closeMic method

Future<void> closeMic(
  1. String from, {
  2. bool needUIDisabled = true,
  3. bool needToast = true,
})

Implementation

Future<void> closeMic(
  String from, {
  bool needUIDisabled = true,
  bool needToast = true,
}) async {
  if (needUIDisabled) {
    _trtcStreamInfoObs.updateSelfMicDeviceDisabled(true);
  }
  await TRTC.closeMic(from);
  // await TRTC.stopLocalAudio(from);
  final isMicAvailable = _trtcStreamInfoObs.isMicAvailable.value;
  var res = await networkService.selfStatusReport(
    StateReportBody(
      classId: _config.classId,
      state:
          isMicAvailable
              ? StateStatusValueEnum.off
              : StateStatusValueEnum.fail,
      type: StateTypeEnum.mic,
    ),
  );
  if (res?.errorCode == 0) {
    _membersInfoObs.updateSelfMemberInfoByAction(
      MemberActionType.micClose,
      isMicAvailable ? StateStatusValueEnum.off : StateStatusValueEnum.fail,
    );
    _trtcStreamInfoObs.updateTRTCStreamInfo(
      TRTCRoomInfo.fromJson({
        "userId": _config.userId,
        "userAudioAvailable": false,
      }),
      TRTCStreamInfoUpdateType.userAudioAvailableChanged,
    );
    TCICLog.info(
      "关闭麦克风成功",
      actionModule: ActionModule.tcicController.name,
      actionName: ActionName.closeMic.name,
    );
    if (needToast) {
      TCICToast.show(StringEnum.closeMicSuccess);
    }
  } else {
    TCICLog.error(
      "关闭麦克风失败",
      actionModule: ActionModule.tcicController.name,
      actionName: ActionName.closeMic.name,
    );
    if (needToast) {
      TCICToast.show(StringEnum.closeMicFailed);
    }
  }
  if (needUIDisabled) {
    _trtcStreamInfoObs.updateSelfMicDeviceDisabled(false);
  }
}