I've implemented voip call in my flutter app. If both the user open the app and join(agora channel) manually, it's working fine. But, If user A calls to user B, I'm getting call in user B's mobile using callkeep & fcm data message. i.e., in FCM onBackground Message i've written code to enable audio & join channel. Both the lines are executed(channel joined, audio enabled). But, none of the users can speak or listen to other users.
Here's my code.
Future<void> bgMsgHandler(RemoteMessage message) async {
Map msgData = message.data;
if (msgData['action'] == "Incoming call") {
final callUUID = "call_uuid_1";
// #region answer_call_action
_callKeep.on(CallKeepPerformAnswerCallAction(), (event) async {
print(
'backgroundMessage: CallKeepPerformAnswerCallAction ${event.callUUID}');
Timer(const Duration(seconds: 1), () {
_callKeep.setCurrentCallActive(callUUID);
_callKeep.setMutedCall(callUUID, true);
});
await initAgora();
});
// #endregion
// #region end_call_action
_callKeep.on(CallKeepPerformEndCallAction(),
(CallKeepPerformEndCallAction event) {
print(
'backgroundMessage: CallKeepPerformEndCallAction ${event.callUUID}');
engine.leaveChannel();
});
// #endregion
if (!callKeepInited) {
_callKeep.setup(
null,
<String, dynamic>{
'ios': {
'appName': 'CallKeepDemo',
},
'android': {
'alertTitle': 'Phone Permissions required',
'alertDescription': 'Allow access to speak to our partners',
'cancelButton': 'Cancel',
'okButton': 'Ok',
'foregroundService': {
'channelId': 'com.company.my',
'channelName': 'Foreground service for my app',
'notificationTitle': 'My app is running on background',
'notificationIcon':
'Path to the resource icon of the notification',
},
},
},
backgroundMode: true);
callKeepInited = true;
}
print('backgroundMessage: displayIncomingCall (user B)');
_callKeep.displayIncomingCall(callUUID, 'user_B');
_callKeep.backToForeground();
}
}
In debug console I am getting message the local & remote users joined. But, unable to transmit & receive audio.
Here's my init agora function
Future<void> initAgora() async {
engine = await RtcEngine.create(AGORA_APP_ID);
engine.setEventHandler(RtcEngineEventHandler(
joinChannelSuccess: (channel, uid, elapsed) {
print("local user [$uid] joined");
},
userJoined: (uid, elapsed) {
print("remote user [$uid] joined");
remoteUid = uid;
},
userOffline: (uid, reason) {
print("remote user [$uid] left channel $reason");
remoteUid = null;
engine.leaveChannel();
},
));
try {
await engine.enableAudio();
await engine.joinChannel(AGORA_TOKEN, "firstChannel", null, 0);
} catch (e) {
print("error with agora = $e");
}
}
I don't know if it's problem with agora or callKeep. Can you help me to solve this? Any help is appreciatable.