Skip to content

Commit

Permalink
修复同步服务无法启动问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyaocz committed Mar 13, 2024
1 parent 6eda8b6 commit f5741af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion simple_live_app/lib/modules/sync/sync_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SyncController extends BaseController {
version: QrVersions.auto,
backgroundColor: Colors.white,
padding: AppStyle.edgeInsetsA12,
size: 240,
size: 200,
),
),
),
Expand Down
39 changes: 24 additions & 15 deletions simple_live_app/lib/services/sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SyncService extends GetxService {
return;
}
//处理Hello的广播
if (data["type"] == "Hello SimpleLive") {
if (data["type"] == "hello") {
//如果http服务已经启动,就回复自己的信息
if (httpRunning.value) {
sendInfo();
Expand Down Expand Up @@ -156,24 +156,33 @@ class SyncService extends GetxService {
/// - 如果是wifi,直接获取wifi的IP
/// - 如果是有线,获取所有的IP,找到全部的IP
Future<String> getLocalIP() async {
var ip = await networkInfo.getWifiIP();
if (ip == null || ip.isEmpty) {
var interfaces = await NetworkInterface.list();
var ipList = <String>[];
for (var interface in interfaces) {
for (var addr in interface.addresses) {
if (addr.type.name == 'IPv4' &&
!addr.address.startsWith('127') &&
!addr.isMulticast &&
!addr.isLoopback) {
ipList.add(addr.address);
break;
String? ip = "";
try {
ip = await networkInfo.getWifiIP();
} catch (e) {
Log.logPrint(e);
}
try {
if (ip == null || ip.isEmpty) {
var interfaces = await NetworkInterface.list();
var ipList = <String>[];
for (var interface in interfaces) {
for (var addr in interface.addresses) {
if (addr.type.name == 'IPv4' &&
!addr.address.startsWith('127') &&
!addr.isMulticast &&
!addr.isLoopback) {
ipList.add(addr.address);
break;
}
}
}
ip = ipList.join(';');
}
ip = ipList.join(';');
} catch (e) {
Log.logPrint(e);
}
return ip;
return ip ?? "";
}

/// 初始化HTTP服务
Expand Down

0 comments on commit f5741af

Please sign in to comment.