首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在flutter中使用callkeep和agora时无法通信

在flutter中使用callkeep和agora时无法通信
EN

Stack Overflow用户
提问于 2021-11-03 07:57:23
回答 2查看 432关注 0票数 1

我已经在我的flutter应用中实现了voip呼叫。如果用户同时打开应用程序并手动加入(agora频道),它就可以正常工作。但是,如果用户A呼叫用户B,我在用户B的手机中收到使用callkeep & fcm数据消息的呼叫。例如,在FCM onBackground消息中,我已经编写了启用音频和加入通道的代码。执行这两行(通道连接,音频启用)。但是,没有一个用户可以说或听其他用户的话。

这是我的代码。

代码语言:javascript
复制
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函数

代码语言:javascript
复制
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有问题。你能帮我解决这个问题吗?任何帮助都是值得感谢的。

EN

回答 2

Stack Overflow用户

发布于 2021-11-11 23:33:27

我以前没有用过Agora,但我不认为muted应该是真的。_callKeep.setMutedCall(callUUID, true);

票数 2
EN

Stack Overflow用户

发布于 2021-11-18 15:27:00

从你的代码看,它看起来是有意阻止每个用户彼此说话或听到对方的声音。

以块为单位

代码语言:javascript
复制
Timer(const Duration(seconds: 1), () {
        _callKeep.setCurrentCallActive(callUUID);
        _callKeep.setMutedCall(callUUID, true);
      });

变化

代码语言:javascript
复制
_callKeep.setMutedCall(callUUID, true);

代码语言:javascript
复制
_callKeep.setMutedCall(callUUID, false);

或者将其完全删除。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69821363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档