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 {
//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;
}

19
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<AboutPage> {
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<AboutPage> {
},
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<AboutPage> {
size: 24,
),
],
)),
),
),
],
),
);

Loading…
Cancel
Save