onInit method

  1. @override
Future<void> onInit()
override

Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.

Implementation

@override
Future<void> onInit() async {
  if (!Get.isRegistered<RoomStore>() || !RoomStore.to.isEnteredRoom) {
    if (conferenceId == null || isCreateConference == null) {
      _showNotEnteredRoomDialog();
      return;
    }
    await _enterConference(
        conferenceId!, isCreateConference!, conferenceParams);
  } else if (conferenceId != null &&
      conferenceId != RoomStore.to.roomInfo.roomId) {
    _showDifferentRoomIdDialog();
  }
  isEnteredRoom.value = RoomStore.to.isEnteredRoom;
  observer = TUIRoomObserver(
    onRequestReceived: (request) {
      switch (request.requestAction) {
        case TUIRequestAction.requestToOpenRemoteCamera:
        case TUIRequestAction.requestToOpenRemoteMicrophone:
        case TUIRequestAction.requestRemoteUserOnSeat:
          showRequestDialog(request);
          break;
        default:
          break;
      }
    },
    onRequestCancelled: (requestId, userId) {
      if (isCameraInviteDialogShow) {
        Get.back();
        isCameraInviteDialogShow = false;
      }
      if (isMicrophoneInviteDialogShow) {
        Get.back();
        isMicrophoneInviteDialogShow = false;
      }
    },
    onRoomDismissed: (roomId, reason) {
      conferenceObserver?.onConferenceFinished
          ?.call(RoomStore.to.roomInfo.roomId);
      RoomStore.to.clearStore();
      showExitRoomDialog('roomDestroyed'.roomTr);
    },
    onKickedOutOfRoom: (roomId, reason, message) {
      conferenceObserver?.onConferenceExited
          ?.call(RoomStore.to.roomInfo.roomId);
      RoomStore.to.clearStore();
      showExitRoomDialog('kickedOutOfRoom'.roomTr);
    },
    onUserInfoChanged: (userInfo, modifyFlagList) {
      if (!modifyFlagList.contains(TUIUserInfoModifyFlag.userRole)) {
        return;
      }
      if (userInfo.userId == RoomStore.to.currentUser.userId.value) {
        switch (userInfo.userRole) {
          case TUIRole.roomOwner:
            if (RoomStore.to.currentUser.userRole.value ==
                TUIRole.generalUser) {
              RoomEngineManager().getSeatApplicationList();
            }
            makeToast(msg: 'haveBecomeOwner'.roomTr);
            break;
          case TUIRole.administrator:
            if (RoomStore.to.currentUser.userRole.value ==
                TUIRole.generalUser) {
              RoomEngineManager().getSeatApplicationList();
            }
            makeToast(msg: 'haveBecomeAdministrator'.roomTr);
            break;
          case TUIRole.generalUser:
            if (RoomStore.to.currentUser.userRole.value ==
                TUIRole.administrator) {
              makeToast(msg: 'revokedYourAdministrator'.roomTr);
            }
            RoomStore.to.inviteSeatList.clear();
            RoomStore.to.inviteSeatMap.clear();
            break;
          default:
            break;
        }
        RoomStore.to.currentUser.userRole.value = userInfo.userRole;
        RoomStore.to.updateItemTouchableState();
      }
    },
  );
  RoomEngineManager().addObserver(observer!);
  super.onInit();
}