Closed CMLCNL closed 3 years ago
@CMLCNL See this answer.
https://developers.connectycube.com/reactnative/videocalling?id=continue-calling-in-background
I use the code below to enable/disable call activity in background:
...
backgroundModeOptions = {
taskName: 'AppName',
taskTitle: 'You have an active call',
taskDesc: 'Press to return',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
linkingURI: 'appname://foreground', // see the guide to configure deep linking
};
startBackgroundMode = () => {
this.stopBackgroundMode();
BackgroundService.start(async (params) => {
await new Promise(async () => {});
}, this.backgroundModeOptions);
};
stopBackgroundMode = () => {
if (BackgroundService.isRunning()) {
return BackgroundService.stop();
}
};
...
To receive call if your app is closed:
You will receive a call to onCallListener after chat will be connected and videochat listeners will be inited
I guess you didn't understand me. Now you open the app for example and then throw the app to the background in iOS. 10-15 minutes passed. Then if you call this phone. no way listeners work.
I just tried to answer more explained)
Try the code below (need to setup push notification):
import {AppState, ...} from 'react-native';
...
componentDidMount = () => {
this.setupAppStateListener();
}
componentWillUnmount = () => {
this.removeAppStateListener();
}
setupAppStateListener = () => {
AppState.addEventListener('change', this.handleAppStateChange);
};
removeAppStateListener = () => {
AppState.removeEventListener('change', this.handleAppStateChange);
};
handleAppStateChange = (state) => {
if (state === 'inactive') {
// Ignore, handle only 'active' and 'background'
// https://facebook.github.io/react-native/docs/appstate
return;
}
if (state === 'background') { // app goes to background/inactive
if (ConnectyCube.chat.isConnected) { // checks is we are able to send request via chat
ConnectyCube.chat.markInactive(); // status inactive (offline) to an ability to receives push notification for app in tray.
// you are able to receive push to show CallKit (or open your app by tap on push notification about incoming call).
}
} else { // app returns from background (active)
if (ConnectyCube.chat.isConnected) {
ConnectyCube.chat.markActive(); // status active (online)
} else {
ConnectyCube.chat.connect(params); // reconnect if chat connection was closed
}
// onCallListener, onRemoteStreamListener etc. will works after...
}
};
...
i will try this. thank you for interest.
Hello is facing a problem that I do not understand. We have functions related to calls. onCallListener etc. For example, if the application remains open on the frontend or in the background, it will not be triggered when a call is received after 10 or 15 minutes. I think he's dying. What can I do to keep it active all the time? or what can i do to revive it with notification?
For example, I talked to someone for 20 minutes. Then I closed the call. If someone else calls me after this call, they cannot connect to me because the listeners are not working. @ccvlad What do you think about this problem?