messageReceived function

void messageReceived({
  1. required String messageType,
  2. required Map<String, dynamic> message,
  3. required SessionController sessionController,
})

Implementation

void messageReceived({
  required String messageType,
  required Map<String, dynamic> message,
  required SessionController sessionController,
}) {
  switch (messageType) {
    case "UserData":
      message.forEach((key, val) {
        if (key == "text") {
          var userData = UserData.fromJson(jsonDecode(val.toString()));
          String rtmId = userData.rtmId;
          int rtcId = userData.rtcId;
          _addToUidUserMap(
            rtcId: rtcId,
            rtmId: rtmId,
            sessionController: sessionController,
          );
          _addToUserRtmMap(
            rtmId: rtmId,
            message: message,
            sessionController: sessionController,
          );
        }
      });
      break;
    case "MuteRequest":
      bool? muted;
      int? deviceId;
      message.forEach((key, val) {
        if (key == "text") {
          var muteRequest = MuteRequest.fromJson(jsonDecode(val.toString()));
          muted = muteRequest.mute;
          deviceId = muteRequest.device;
        }
      });
      if (deviceId == 0) {
        sessionController.value = sessionController.value.copyWith(
          displaySnackbar: true,
          cameraRequest: muted! ? CameraState.enabled : CameraState.disabled,
          showMicMessage: false,
          showCameraMessage: true,
        );
      } else if (deviceId == 1) {
        sessionController.value = sessionController.value.copyWith(
          displaySnackbar: true,
          muteRequest: muted! ? MicState.unmuted : MicState.muted,
          showCameraMessage: false,
          showMicMessage: true,
        );
      }

      Future.delayed(Duration(seconds: 10), () {
        sessionController.value = sessionController.value.copyWith(
          displaySnackbar: false,
          showCameraMessage: false,
        );
      });
      break;
    default:
  }
}