Ionic2 sleep mode backgroundMode and background geolocation - background

I have installed backgroundMode, backgroundGeolocation and insomnia but I'm still banging my head.
Background mode seems to work ok
after 40 secs the phone goes to sleep and backgroundGeolocation stops working
everything else seems to work fine eg: network connections, BLE button clicks, just not backgroundGeolocation.
I'm getting desperate and happy to pay someone for some help.
Please gurus, help me lol
home.ts
constructor(public navCtrl: NavController,
public navParams: NavParams,
public member:Member,
public journey: Journey,
public backgroundMode: BackgroundMode,
public insomnia: Insomnia,
platform: Platform) {
platform.ready().then(() => {
this.backgroundMode.enable();
this.insomnia.keepAwake()
.then(
() => console.log('success'),
() => console.log('error')
);
});
this.member.onLoggedIn.subscribe(
(data) => {
this.memberLoggedIn();
}
);
this.member.onLoggedOut.subscribe(
(data) => {
this.memberLoggedOut();
}
);
}

The only way I managed to fix this is by turning off power saving mode on my phone :(

Related

React Native - Cannot use Speech To Text and Text To Speech together

I am using both react-native-voice and expo-speech libraries to transcript my voice and to convert a text to a speech. The problem is, when i end registering my voice and start a speech with expo-voice, there is no sound. It seems like react-native-voice completly mutes the audio when the voice recording is ended. The speech starts, but i must press on the mic button (activating the voice recognition) to hear it.
The only way i found to make everything work together is by stopping the voice recording after the text to speech has ended. Here is a part of the code :
const startRecognizing = async () => {
setButtonColor('#38b000');
// Starts listening for speech for a specific locale
try {
await Voice.start('en-EN');
} catch (e) {
console.error(e);
}
};
const destroyRecognizer = async () => {
//Destroys the current SpeechRecognizer instance
try {
await Voice.destroy();
} catch (e) {
console.error(e);
}
};
const stopRecognizing = async () => {
setButtonColor('#344E41');
setTimeout(() => {
Speech.speak("I did not understand, can you repeat please ?", {
language: 'en-EN',
onDone: () => {
setTimeout(
async() => {
await destroyRecognizer();
}, 1000);
},
});
}, 1000);
};
return (
<View style={styles.microphoneButtonContainer}>
<TouchableOpacity
onPressIn={startRecognizing}
onPressOut={stopRecognizing}>
<Image
style={styles.microphoneButton}
source={require('../img/microphone-icon.png')}
/>
</TouchableOpacity>
</View>
);
This solution brings a lot of edgecases so i can't work with it. None of the methods given to stop the recording solve the issue. And i did not found any help in the libraries docs. Is there a solution to this ? Thank you for your help !
Because there was no way to solve the issue with react-native-voice methods, i had the idea to go search directly in the library if i can modify the native code. For ios the code is in ios/voice/Voice.m. I found this :
- (void) teardown {
self.isTearingDown = YES;
[self.recognitionTask cancel];
self.recognitionTask = nil;
// Set back audio session category
[self resetAudioSession];
So i tried to comment out [self resetAudioSession];, i then rebuilt the packages with npx-pod-install (i use cocoapod), and it worked!
Doing this may cause edgecases, i did not fully test the methods yet, and i did not try for android.

Ionic program dont work in backgraund. How to fix that?

I need the app to run fully in the background and when I use other apps on my phone. The program transmits video from the camera. When I turn off the screen, I managed to get the program to transmit video, but when I turn on other programs on the phone, the program stops transmitting. Part of the code as I managed to omit in off mode.
i use library #ionic-native/background-mode
componentDidMount() {
document.addEventListener('deviceready', () => {
BackgroundMode.setEnabled(true);
BackgroundMode.disableBatteryOptimizations();
BatteryStatus.onChange().subscribe(status => {
this.batteryStatus = status;
this.signalCurrentStatus();
});
},false);
Use plugin Background Mode
ionic cordova plugin add cordova-plugin-background-mode
npm install #ionic-native/background-mode
Then use it like this:
import { BackgroundMode } from '#ionic-native/background-mode/ngx';
export class AppComponent {
constructor(private backgroundMode: BackgroundMode) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.backgroundMode.enable();
});
}
}

Detect All Beacons in the region and get its data ( REACT NATIVE )

Hope you are doing well.
i want to detect the beacons which are in my range. i got the react-native-beacons-manager but its not working.
i have the beacon device. i tested it but not luck.
As per this code its showing only those UUID which i am passing in the region object.
Can anyone help me out how to detect the nearby beacons. the code i got from the library is :
the source link is
https://github.com/MacKentoch/react-native-beacons-manager
i just did nothing just console the data using in example in above link.
my code is
componentWillMount() {
Beacons.requestAlwaysAuthorization();
const region = {
identifier: 'pBeacon_n',
uuid: '7BA5D5CE-C416-5FD6-8AAA-919D534E0DC3'
};
Beacons.startMonitoringForRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.warn('Beacons monitoring started succesfully'))
.catch(error => console.warn(`Beacons monitoring not started, error: ${error}`));
// Range for beacons inside the region
Beacons.startRangingBeaconsInRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.warn('Beacons ranging started succesfully'))
.catch(error => console.warn(`Beacons ranging not started, error: ${error}`));
// update location to ba able to monitor:
Beacons.startUpdatingLocation();
}
componentDidMount() {
this.beaconsDidRangeEvent = DeviceEventEmitter.addListener(
'beaconsDidRange',
(data) => {
console.warn('beaconsDidRange data: ', data);
}
);
}
The UUID i am passing to the region is my real Beacon UUID.
Thanks.
Unfortunately iOS simply does not let you search for iBeacon transmissions without specifying the ProximityUUID. The lowest level native APIs which this ReactNative Module uses have this restriction. Apple implements it this way as a security restriction to prevent you from scanning for beacons belonging to others.
use like this you can detect all beacons with out giving uuid and etc, but its not working in ios.
startBeacon = () => {
Reactotron.log('else');
Beacons.detectIBeacons();
Beacons.detectAltBeacons();
Beacons.detectEstimotes();
Beacons.detectEddystoneUID();
Beacons.detectEddystoneTLM();
Beacons.detectEddystoneURL();
Beacons.startRangingBeaconsInRegion('REGION1')
.then((data) => {
Alert.alert('', `Beacons monitoring started!`);
})
.catch((error) => {
Alert.alert('', `Beacons start error!`);
});
DeviceEventEmitter.addListener('beaconsDidRange', (data) => {
if (data.beacons.length) {
this.setState({ detectedBeacons: data.beacons });
Alert.alert(`Found beacons!`, JSON.stringify(data.beacons));
}
});
}

Laravel echo listen for whisper function not working

I'm building a live chat app, but I found that listenforwhisper function is not working, but .whisper() function works fine, pusher also received client typing event.
Here is my code:
For listen whisper:
Echo.private(`messages.${this.user.id}`)
.listen("NewMessage", (e) => {
this.handleIncoming(e.message);
})
.listenForWhisper("typing", (e) => {
if(e.name !='') {
this.typeStatus = 'typing .........'
}
else {
this.typeStatus = ''
}
console.log(this.typeStatus);
});
For whisper:
watch: {
message() {
Echo.private(`messages.${this.user.id}`)
.whisper("typing", {
name: this.message
});
}
}
For channel:
Broadcast::channel('messages.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Theoretically, my console will return the typeStatus, but I got nothing in my console.
Whisper works like broadcastToOthers. You're now trying to listen for the current users whispers. You should have a room where the whisper goes to and there should be multiple clients there to recieve. Now your channel is tied to the user and no-one else can see the messages that go through that channel.
Ok, I step in same issue. I got 2 channels and 2 users. I set a interval with wisper
setInterval(() => {
channel.whisper('typing', {
message: 'hola!'
});
}, 3000);
channel.listenForWhisper('typing', (e) => {
console.log('Typing');
console.log(e);
})
The thing was that I was receving events but won't be able to see the output from listenForWhisper until I connect the second user to the channel.
Once the second user is connected, it's works just fine. So I leaved her if you got same issue.

Check for internet connection returns wrong results

I am trying to check whether the user is connected to internet. I am using NetInfo like this (from the documentation):
componentDidMount() {
NetInfo.isConnected.addEventListener('change', this.handleConnectionChange);
NetInfo.isConnected.fetch().done(
(isConnected) => { this.setState({ status: isConnected }); }
);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('change', this.handleConnectionChange);
}
handleConnectionChange = (isConnected) => {
this.setState({ status: isConnected });
console.log(`is connected: ${this.state.status}`);
}
The strange is that the first time loading the screen where I am doing this is working fine. But when I start turning on/of my wifi the results are different: sometimes it detects the change sometime no. Someone having the same issue?
In my experience, the iOS simulator doesn't 'notice' when the internet connection is re-connected when using the React Native NetInfo class.
It is rather annoying. However, for me it works as intended on a real device.