initializeCallsEventStream method

void initializeCallsEventStream()

Implementation

void initializeCallsEventStream() {
  nativeStream = callsEventsStreamChannel.receiveBroadcastStream(1).map((e) {
    CometChatCallsUtils.showLog("CometChatCall",
        "eventStream: methodNameReceived: ${e["methodName"]}");
    CometChatCallsUtils.showLog("CometChatCall",
        "eventStream: globalCallListener: $globalCallListener");
    if (globalCallListener != null) {
      switch (e["methodName"]) {
        case "onCallEnded":
          CometChatCallsUtils.showLog(
              "CometChatCall", "eventStream => onCallEnded");
          globalCallListener?.onCallEnded();
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onCallEnded();
          }
          break;
        case "onCallEndButtonPressed":
          CometChatCallsUtils.showLog(
              "CometChatCall", "eventStream => onCallEndButtonPressed");
          globalCallListener?.onCallEndButtonPressed();
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onCallEndButtonPressed();
          }
          break;
        case "onUserJoined":
          RTCUser user = RTCUser.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onUserJoined: value: ${user.toString()}");
          globalCallListener?.onUserJoined(user);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onUserJoined(user);
          }
          break;
        case "onUserLeft":
          RTCUser user = RTCUser.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onUserLeft: value: ${user.toString()}");
          globalCallListener?.onUserLeft(user);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onUserLeft(user);
          }
          break;
        case "onUserListChanged":
          List<RTCUser> userList = e["userList"]
              .map<RTCUser>((entry) => RTCUser.fromMap(e))
              .toList();
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onUserListChanged: value: ${userList.toString()}");
          globalCallListener?.onUserListChanged(userList);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onUserListChanged(userList);
          }
          break;
        case "onAudioModeChanged":
          List<AudioMode> audioModeList = e["audioModeList"]
              .map<AudioMode>((entry) => AudioMode.fromMap(e))
              .toList();
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onAudioModeChanged: value: ${audioModeList.toString()}");
          globalCallListener?.onAudioModeChanged(audioModeList);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onAudioModeChanged(audioModeList);
          }
          break;
        case "onCallSwitchedToVideo":
          CallSwitchRequestInfo info = CallSwitchRequestInfo.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onCallSwitchedToVideo: value: ${info..toString()}");
          globalCallListener?.onCallSwitchedToVideo(info);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onCallSwitchedToVideo(info);
          }
          break;
        case "onUserMuted":
          RTCMutedUser muteObj = RTCMutedUser.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onUserMuted: value: ${muteObj.toString()}");
          globalCallListener?.onUserMuted(muteObj);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onUserMuted(muteObj);
          }
          break;
        case "onRecordingToggled":
          RTCRecordingInfo info = RTCRecordingInfo.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onRecordingToggled: value: ${info.toString()}");
          globalCallListener?.onRecordingToggled(info);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onRecordingToggled(info);
          }
          break;
        case "onError":
          CometChatCallsException ce = CometChatCallsException.fromMap(e);
          CometChatCallsUtils.showLog("CometChatCall",
              "eventStream => onError: value: ${ce.toString()}");
          globalCallListener?.onError(ce);
          for (var element in CometChatCalls.callsEventsListener.values) {
            element.onError(ce);
          }
          break;
      }
    }
  });
}