Browse Source

socketclient add debug setting

wr_202303
zsw 4 months ago
parent
commit
a042710224
  1. 15
      lib/im/SocketClient.dart
  2. 19
      lib/setting/about_page.dart

15
lib/im/SocketClient.dart

@ -13,15 +13,17 @@ import 'package:shared_preferences/shared_preferences.dart';
class SocketClient { 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; Socket _socket;
SharedPreferences shared; SharedPreferences shared;
connect() async { connect() async {
shared = await SharedPreferences.getInstance(); shared = await SharedPreferences.getInstance();
//47.93.216.24:9090 线 192.168.10.129:9090 await Socket.connect(ip, port).then((value) {
await Socket.connect('47.93.216.24', 9090).then((value) { debugPrint("socket-connect-$ip");
debugPrint("socket-connect");
_socket = value; _socket = value;
_socket.listen((data) { _socket.listen((data) {
print(data); print(data);
@ -35,6 +37,7 @@ class SocketClient {
callbacks[userId]?.call(message); /// user self conversation callback callbacks[userId]?.call(message); /// user self conversation callback
if (callbacks[dataResult.from] != null) { if (callbacks[dataResult.from] != null) {
//
messageMap["state"] = 1; messageMap["state"] = 1;
message.state = 1; message.state = 1;
callbacks[dataResult.from].call(message); /// user conversation callback callbacks[dataResult.from].call(message); /// user conversation callback
@ -72,7 +75,7 @@ class SocketClient {
}); });
} }
int reconnectTime = 1500; int reconnectTime = 600;
reconnect() { reconnect() {
Future.delayed(Duration(milliseconds: reconnectTime *= 2), () { Future.delayed(Duration(milliseconds: reconnectTime *= 2), () {
@ -118,7 +121,7 @@ class SocketClient {
}); });
if (!checkSocket()) { if (!checkSocket()) {
hxDatabase.update({"id": id, "state": 3}).catchError((error) { hxDatabase.update({"id": id, "state": 3}).catchError((error) {
debugPrint("insertMessage: $error"); debugPrint("insertMessage: ${error.toString()}");
}); });
message["id"] = id; message["id"] = id;
message["state"] = 3; message["state"] = 3;
@ -135,7 +138,7 @@ class SocketClient {
checkSocket() { checkSocket() {
if (_socket == null) { if (_socket == null) {
reconnectTime = 1500; reconnectTime = 1000;
reconnect(); reconnect();
return false; return false;
} }

19
lib/setting/about_page.dart

@ -1,10 +1,12 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/utils/bridge.dart'; import 'package:huixiang/utils/bridge.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
@ -46,7 +48,10 @@ class _AboutPage extends State<AboutPage> {
Container( Container(
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: Border( border: Border(
bottom: BorderSide(color: Color(0xffF7F7F7), width: 0.0)), bottom: BorderSide(
color: Color(0xffF7F7F7), width: 0.0,
),
),
color: Color(0xffF7F7F7), color: Color(0xffF7F7F7),
), ),
padding: EdgeInsets.only(top: 25.h), padding: EdgeInsets.only(top: 25.h),
@ -98,6 +103,15 @@ class _AboutPage extends State<AboutPage> {
}, },
child: textItem(S.of(context).shiyongbangzhu), 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) if (!Platform.isAndroid)
GestureDetector( GestureDetector(
child: settingSingleItem(S.of(context).geiwopingfen), child: settingSingleItem(S.of(context).geiwopingfen),
@ -220,7 +234,8 @@ class _AboutPage extends State<AboutPage> {
size: 24, size: 24,
), ),
], ],
)), ),
),
], ],
), ),
); );

Loading…
Cancel
Save