setEventHandler method

最近更新时间:2022-09-20 05:17:40

void setEventHandler (
    RtcChannelEventHandler handler
)

设置频道事件句柄。

设置后,你可以通过 RtcChannel 回调监听对应频道内的事件、获取频道数据。

Parameter handler 事件句柄。

Implementation

void setEventHandler(RtcChannelEventHandler handler) {
  _handler = handler;
  _subscription ??= _eventChannel.receiveBroadcastStream().listen((event) {
    final eventMap = Map<dynamic, dynamic>.from(event);
    final channelId = eventMap['channelId'];
    final methodName = eventMap['methodName'] as String;
    final data = List<dynamic>.from(eventMap['data']);
    _channels[channelId]?._handler?.process(methodName, data);
  });
}