使用Agora的Flutter传入视频/音频呼叫通知

bkhjykvo  于 2023-02-09  发布在  Flutter
关注(0)|答案(1)|浏览(126)

我一直在做一个应用程序,我需要在我的应用程序中实现音频和视频通话,我已经使用www.example.com,但问题是我必须显示来电通知不要紧,如果应用程序是在前台或后台。我已经尝试了很多事情,但我仍然无法配置出来。我正在使用agora_rtc_engine包拨打电话。Agora.io but the issue is I have to display incoming call notification does not matter if app is in foreground or in background. I have tried many things but still I am unable to configure that out. I am using agora_rtc_engine package for making calls.
任何帮助都将不胜感激。
谢谢
我目前使用的代码:

    • 调用方法**
class CallMethods {
  final callRef = FirebaseFirestore.instance.collection('Calls');

  Stream<DocumentSnapshot> callstream({@required String id}) =>
      callRef.doc(id).snapshots();

  Future<bool> makeCall({@required Call call}) async {
    try {
      log('Making call');
      call.hasdialed = true;
      Map<String, dynamic> hasDialedMap = call.toMap(call);

      call.hasdialed = false;
      Map<String, dynamic> hasNotDialedMap = call.toMap(call);

      await callRef.doc(call.senderid).set(hasDialedMap);
      await callRef.doc(call.receiverid).set(hasNotDialedMap);

      return true;
    } catch (e) {
      print(e);
      return false;
    }
  }

  Future<bool> endCall({@required Call call}) async {
    try {
      log('ending call');
      await callRef.doc(call.senderid).delete();
      await callRef.doc(call.receiverid).delete();

      return true;
    } catch (e) {
      print(e);
      return false;
    }
  }
}
    • 呼叫实用程序:**用于拨打电话
class CallUtils {
  static final CallMethods callmethods = CallMethods();

  static dial(
    BuildContext context, {
    @required User from,
    @required var to,
  }) async {
    Call call = Call(
      senderid: from.id,
      // senderpic: from.avatar.url,
      callername: from.name,
      receiverid: to.id,
      // receiverpic: to.avatar.url,
      receivername: to.name,
      channelid: Random().nextInt(999999).toString(),
    );

    bool callmade = await callmethods.makeCall(call: call);
    call.hasdialed = true;

    if (callmade) {
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => VideoCallScreen(call: call),
        ),
      );
    }
  }
}

之后,我有一个皮卡布局,这是用来 Package 所有的屏幕显示来电通知。

    • 代答呼叫布局:**
(user.value.id != null)
          ? StreamBuilder<DocumentSnapshot>(
              stream: callmethods.callstream(id: user.value.id),
              builder: (context, snapshot) {
                if (snapshot.hasData && snapshot.data.data() != null) {
                    Call call = Call.fromMap(snapshot.data.data());
                  if (!call.hasdialed) {
                    return PickupScreen(call: call);
                  } else {
                    return widget.scaffold;
                  }

                } else {
                  return widget.scaffold;
                }
              },
            )
          : widget.scaffold,
gcuhipw9

gcuhipw91#

它可以通过firebase推送通知和后端API服务来完成。

  • 发送方:*

一旦发出调用,您就可以发布包含调用者和接收者id的后端API服务,并且您的后端服务还负责向接收者发送包含有效负载的推送通知。

  • 接收端:*

当接收器收到推送通知时,您可以将其配置为自动打开您的应用并显示包含所有有效载荷信息的屏幕。也许您可以向他显示包含接受和拒绝按钮的屏幕,如果他接受,您可以将他连接到Agora。
检查this的有效负载配置。

相关问题