getClassInfoFromServer method

Future<ClassInfo?> getClassInfoFromServer(
  1. String from
)

Implementation

Future<ClassInfo?> getClassInfoFromServer(String from) async {
  // 如果已经失败过,不再重复请求
  if (_classInfoFetchFailed) {
    return null;
  }
  var classId = _config.classId;
  var body = GetClassInfoBody(classId: classId, allTask: 0);
  var data = await networkService.getClassInfo(body);
  if (data != null) {
    // 即使 errorCode == 0,也要检查 classInfo 是否有效
    if (data.errorCode == 0 && data.classInfo.classId != 0) {
      _classInfoObs.updateClassInfo(data.classInfo);
      _taskController.initTasks(
        lastTaskSeq: data.classInfo.roomInfo.lastTaskSeq,
        tasks: data.classInfo.roomInfo.tasks,
      );
      _eventbus.fire(
        MainEvent(
          type: EventTypeEnum.getClassInfoSuccess,
          data: data.classInfo,
        ),
      );
      final maxRtcMember = data.classInfo.roomInfo.maxRtcMember;
      if (maxRtcMember > 1) {
        _loopStageObs.updateLoopStateEnabled(true);
        _loopStageObs.updateMaxMemberNumber(maxRtcMember);
        _loopStageObs.updateMemberNumber(maxRtcMember, needEvent: false);
      } else {
        _loopStageObs.updateLoopStateEnabled(false);
      }
      TCICLog.info(
        'getClassInfoFromServer success from $from',
        actionModule: ActionModule.tcicController.name,
        actionName: ActionName.getClassInfoFromServer.name,
      );
      return data.classInfo;
    } else {
      // errorCode != 0 或 classId == 0(无效数据),设置失败标志并触发阻断弹窗
      _classInfoFetchFailed = true;
      final errorCode = data.errorCode != 0 ? data.errorCode : -1;
      final errorMsg =
          data.errorCode != 0
              ? data.errorMsg
              : 'classInfo is invalid (classId is 0)';
      TCICLog.error(
        'getClassInfoFromServer failed from $from, errorCode: $errorCode, errorMsg: $errorMsg',
        actionModule: ActionModule.tcicController.name,
        actionName: ActionName.getClassInfoFromServer.name,
      );
      fireMainBreakEvent(
        MainProcessBreakenEventEnum.joinClassFailed,
        errorCode,
        requestId: data.requestId,
      );
      return null;
    }
  }
  // 网络错误等情况,也标记失败
  _classInfoFetchFailed = true;
  TCICLog.error(
    'getClassInfoFromServer failed from $from, data is null',
    actionModule: ActionModule.tcicController.name,
    actionName: ActionName.getClassInfoFromServer.name,
  );
  return null;
}