如何使用 Agora 在 Flutter 中检测对等方是否离开视频通话

How to detect if peer leaves video call in Flutter using Agora

我有两个内置应用 FlutterDoctor 应用Patient 应用,一个 医生 使用Agora RTC Engine(点对点)..

患者 建立视频通话

我想知道是否有一种方法(从前端)检测对方何时离开通话(由于连接不良、断开连接甚至挂断。

这是我正在使用的库: agora_rtc_engine

如果有人感兴趣,我找到了答案。

所以首先导入库:

import 'package:agora_rtc_engine/rtc_engine.dart';

然后声明这个变量:

late RtcEngine _engine;

然后添加此函数并添加您自己的代码:

Future <void> setHandler() async {
    _engine = await RtcEngine.createWithConfig(RtcEngineConfig("$REMOTE_VIDEO_UID"));

    await _engine.enableVideo();

    _engine.setEventHandler(
      RtcEngineEventHandler(
        joinChannelSuccess: (String channel, int uid, int elapsed) {
          print("Local user has joined the call!");
          // Your code goes here
        },

        userJoined: (int uid, int elapsed) {
          print("Local user has joined the call!");
          // Your code goes here
        },

        userOffline: (int uid, UserOfflineReason reason) {
          print("remote user has left the call!");
          // Your code goes here
        },

      ),
    );
  }

最后在您喜欢的状态下像这样调用处理程序:

  setState(
    () {
      setHandler();
    },
  );

感谢此人 his tutorial