【发布时间】:2021-12-17 15:02:39
【问题描述】:
我已经在我的 Flutter 应用中实现了 voip 通话。如果用户都打开应用程序并手动加入(agora 频道),它工作正常。但是,如果用户 A 呼叫用户 B,我将使用 callkeep 和 fcm 数据消息在用户 B 的手机中接听电话。即,在 FCM onBackground Message 中,我编写了启用音频和加入频道的代码。两条线都被执行(加入频道,启用音频)。但是,没有一个用户可以说话或听其他用户说话。
这是我的代码。
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();
}
}
在调试控制台中,我收到本地和远程用户加入的消息。但是,无法传输和接收音频。
这是我的 init agora 函数
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");
}
}
我不知道是 agora 还是 callKeep 的问题。 你能帮我解决这个问题吗?任何帮助都是值得赞赏的。
【问题讨论】:
-
嘿,如果您可以共享相同的日志,那就太好了。您也可以在 Agora Developer slack 频道上跟进 Agora 团队:agoraiodev.slack.com
标签: flutter firebase-cloud-messaging phone-call agora.io