Browse Source

发消息修改

wr_202303
zsw 4 months ago
parent
commit
32bba1b888
  1. 19
      lib/im/SocketClient.dart

19
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<Function> callbacks = [];
Map<String, Function> callbacks = <String, Function>{};
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() {

Loading…
Cancel
Save