diff --git a/lib/im/SocketClient.dart b/lib/im/SocketClient.dart index 160108c4..f8b11346 100644 --- a/lib/im/SocketClient.dart +++ b/lib/im/SocketClient.dart @@ -20,7 +20,7 @@ class SocketClient { connect() async { shared = await SharedPreferences.getInstance(); - await Socket.connect('192.168.10.129', 9090).then((value) { + await Socket.connect('192.168.10.200', 49168).then((value) { debugPrint("socket-connect"); _socket = value; _socket.listen((data) { @@ -32,29 +32,32 @@ class SocketClient { hxDatabase.insert(createMessage(userId, utf8.decode(data1.data), msgType: data1.type.value, userId: data1.from)); - callbacks.forEach((callback) { + callbacks.values.forEach((callback) { callback.call(data1); }); }, onError: (Object error, StackTrace stackTrace) { - debugPrint("socket-error: $error, stackTrace: ${stackTrace}"); + debugPrint("socket-listen-error: $error, stackTrace: ${stackTrace}"); }); authRequest(shared.getString("token")); }).catchError((error) { debugPrint("socket-connect-error: $error"); + Future.delayed(const Duration(milliseconds: 3000), () { + connect(); + }); }); } - List callbacks = []; + Map callbacks = {}; - addCallback(Function callback) { - callbacks.add(callback); + addCallback(String userId, Function callback) { + callbacks.putIfAbsent(userId, callback); } - removeCallback(Function callback) { - callbacks.remove(callback); + removeCallback(String userId) { + callbacks.remove(userId); } dispose() {