我已经在我的flutter应用中实现了voip呼叫。如果用户同时打开应用程序并手动加入(agora频道),它就可以正常工作。但是,如果用户A呼叫用户B,我在用户B的手机中收到使用callkeep & fcm数据消息的呼叫。例如,在FCM onBackground消息中,我已经编写了启用音频和加入通道的代码。执行这两行(通道连接,音频启用)。但是,没有一个用户可以说或听其他用户的话。
这是我的代码。
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有问题。你能帮我解决这个问题吗?任何帮助都是值得感谢的。
发布于 2021-11-11 23:33:27
我以前没有用过Agora,但我不认为muted应该是真的。_callKeep.setMutedCall(callUUID, true);
发布于 2021-11-18 15:27:00
从你的代码看,它看起来是有意阻止每个用户彼此说话或听到对方的声音。
以块为单位
Timer(const Duration(seconds: 1), () {
_callKeep.setCurrentCallActive(callUUID);
_callKeep.setMutedCall(callUUID, true);
});变化
_callKeep.setMutedCall(callUUID, true);至
_callKeep.setMutedCall(callUUID, false);或者将其完全删除。
https://stackoverflow.com/questions/69821363
复制相似问题