login method

  1. @override
Future<Map<String, dynamic>> login({
  1. required String userID,
  2. required String userSig,
})
override

Implementation

@override
Future<Map<String, dynamic>> login({required String userID, required String userSig}) async {
  try {
    V2TimValueCallback<int> getLoginStatusRes = await TencentImSDKPlugin.v2TIMManager.getLoginStatus();
    if (getLoginStatusRes.code == 0) {
      int? status = getLoginStatusRes.data;
      if (status == 3) {
        V2TimCallback result = await TencentImSDKPlugin.v2TIMManager.login(userID: userID, userSig: userSig);
        if (result.code == 0) {
          ImState.setChatLoginInfo(ImLoginInfoEntity.fromJson({
            'userId': userID,
            'userSig': userSig,
          }));

          try {
            return await _loginCall(userID: userID, userSig: userSig);
          } catch(e) {
            rethrow;
          }
        } else {
          ImState.setChatLoginInfo(null);
          developerLog('登录 chat 失败, code: ${result.code}, message: ${result.desc}');
          throw Exception('登录失败: $result');
        }
      } else {
        developerLog('当前 im 登录状态为:$status | ${ { 1: '已登录', 2: '登录中', 3: '未登录' }[status] },跳过本次登录逻辑的执行,仅进行call的登录逻辑判断');
        ImState.chatInstance.value = {};
        ImState.setChatLoginInfo(ImLoginInfoEntity.fromJson({
          'userId': userID,
          'userSig': userSig,
        }));

        // 把 call 登录一下
        try {
          return await _loginCall(userID: userID, userSig: userSig);
        } catch(e) {
          rethrow;
        }
      }
    } else {
      developerLog('获取当前 im 登录状态异常,错误码:${getLoginStatusRes.code}');
      throw Exception('登录失败: 获取当前 im 登录状态异常');
    }
  } catch (e) {
    throw Exception('登录失败: $e');
  }
}