fix: 登录失败自动自检三个服务端口并展示 SDK 原始错误(B-58)
- IMService 记录 onConnectFailed 的 code/error(lastConnectError) - SDK 未初始化成功时 login 直接抛错,不再无限等待 - 登录页失败提示下附自检结果:账号服务/消息接口/消息长连接 通不通 - 版本号 1.0.2+3
This commit is contained in:
@@ -36,6 +36,9 @@ class IMService extends ChangeNotifier {
|
||||
/// 与服务器的连接状态(断网横幅用)
|
||||
ConnectStatus connectStatus = ConnectStatus.idle;
|
||||
|
||||
/// 最近一次连接失败的原始错误(诊断展示用)
|
||||
String? lastConnectError;
|
||||
|
||||
/// 是否已登录
|
||||
bool loggedIn = false;
|
||||
|
||||
@@ -108,12 +111,14 @@ class IMService extends ChangeNotifier {
|
||||
connectStatus = ConnectStatus.connecting;
|
||||
notifyListeners();
|
||||
},
|
||||
onConnectSuccess: () {
|
||||
connectStatus = ConnectStatus.success;
|
||||
notifyListeners();
|
||||
},
|
||||
onConnectFailed: (code, error) {
|
||||
connectStatus = ConnectStatus.failed;
|
||||
lastConnectError = '$code $error';
|
||||
notifyListeners();
|
||||
},
|
||||
onConnectSuccess: () {
|
||||
connectStatus = ConnectStatus.success;
|
||||
lastConnectError = null;
|
||||
notifyListeners();
|
||||
},
|
||||
onKickedOffline: _forceLogout,
|
||||
@@ -191,6 +196,10 @@ class IMService extends ChangeNotifier {
|
||||
/// 登录(init 之后调用)。userID/token 来自公司账号登录接口。
|
||||
Future<void> login({required String userID, required String token}) async {
|
||||
await init();
|
||||
if (!sdkReady) {
|
||||
// initSDK 返回 false:SDK 没初始化成功,直接登录会无限等待
|
||||
throw StateError('消息组件初始化失败');
|
||||
}
|
||||
final user = await OpenIM.iMManager.login(
|
||||
userID: userID,
|
||||
token: token,
|
||||
|
||||
Reference in New Issue
Block a user