From a0427102244f57f1faf5df6f6743f79ba4b50624 Mon Sep 17 00:00:00 2001 From: zsw Date: Tue, 24 Sep 2024 10:42:07 +0800 Subject: [PATCH] socketclient add debug setting --- lib/im/SocketClient.dart | 15 +++++++++------ lib/setting/about_page.dart | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/im/SocketClient.dart b/lib/im/SocketClient.dart index 8b739b0f..fc774125 100644 --- a/lib/im/SocketClient.dart +++ b/lib/im/SocketClient.dart @@ -13,15 +13,17 @@ import 'package:shared_preferences/shared_preferences.dart'; class SocketClient { + //47.93.216.24:9090 线上 192.168.10.129:9090 测试 + final String ip = kDebugMode ? '192.168.10.129' : '47.93.216.24'; + final num port = 9090; Socket _socket; SharedPreferences shared; connect() async { shared = await SharedPreferences.getInstance(); - //47.93.216.24:9090 线上 192.168.10.129:9090 测试 - await Socket.connect('47.93.216.24', 9090).then((value) { - debugPrint("socket-connect"); + await Socket.connect(ip, port).then((value) { + debugPrint("socket-connect-$ip"); _socket = value; _socket.listen((data) { print(data); @@ -35,6 +37,7 @@ class SocketClient { callbacks[userId]?.call(message); /// user self conversation callback if (callbacks[dataResult.from] != null) { + // messageMap["state"] = 1; message.state = 1; callbacks[dataResult.from].call(message); /// user conversation callback @@ -72,7 +75,7 @@ class SocketClient { }); } - int reconnectTime = 1500; + int reconnectTime = 600; reconnect() { Future.delayed(Duration(milliseconds: reconnectTime *= 2), () { @@ -118,7 +121,7 @@ class SocketClient { }); if (!checkSocket()) { hxDatabase.update({"id": id, "state": 3}).catchError((error) { - debugPrint("insertMessage: $error"); + debugPrint("insertMessage: ${error.toString()}"); }); message["id"] = id; message["state"] = 3; @@ -135,7 +138,7 @@ class SocketClient { checkSocket() { if (_socket == null) { - reconnectTime = 1500; + reconnectTime = 1000; reconnect(); return false; } diff --git a/lib/setting/about_page.dart b/lib/setting/about_page.dart index 2c385a05..e3800c7c 100644 --- a/lib/setting/about_page.dart +++ b/lib/setting/about_page.dart @@ -1,10 +1,12 @@ import 'dart:io'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:huixiang/main.dart'; import 'package:huixiang/utils/bridge.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; @@ -46,7 +48,10 @@ class _AboutPage extends State { Container( decoration: new BoxDecoration( border: Border( - bottom: BorderSide(color: Color(0xffF7F7F7), width: 0.0)), + bottom: BorderSide( + color: Color(0xffF7F7F7), width: 0.0, + ), + ), color: Color(0xffF7F7F7), ), padding: EdgeInsets.only(top: 25.h), @@ -98,6 +103,15 @@ class _AboutPage extends State { }, child: textItem(S.of(context).shiyongbangzhu), ), + if (kDebugMode) + InkWell( + onTap: () { + Navigator.of(context).pushNamed( + '/router/help_feedback_page' + ); + }, + child: textItem("ip:${socketClient.ip} port:${socketClient.port} id:${socketClient.userId}"), + ), if (!Platform.isAndroid) GestureDetector( child: settingSingleItem(S.of(context).geiwopingfen), @@ -220,7 +234,8 @@ class _AboutPage extends State { size: 24, ), ], - )), + ), + ), ], ), );