更新多个用户连接同一个设备的通知
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vbvs_app/common/util/CommonVariables.dart';
|
||||
import 'package:vbvs_app/component/NullDataComponentWidget.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/WebSocketMessage.dart';
|
||||
import 'package:vbvs_app/pages/common/bezier_bottom_navigation_bar.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/MattressControl.dart';
|
||||
@@ -139,26 +140,90 @@ class _HomePageState extends State<MainPageBBottomChange>
|
||||
|
||||
setState(() {
|
||||
selectedIndex = index;
|
||||
dealWebSource(index);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> dealWebSource(int index) async {
|
||||
try {
|
||||
UserInfoController userInfoController = Get.find();
|
||||
WebviewTestController webviewTestController = Get.find();
|
||||
if (index == 2) {
|
||||
await webviewTestController.web.jsbridge?.dart.pageActive(true);
|
||||
//激活websocket
|
||||
CommonVariables.callMap["/smartbed/connect"] = (data) {
|
||||
//订阅连接消息
|
||||
ef.log("[设备申请连接]:$data");
|
||||
};
|
||||
edm.EasyDartModule.websocket.sendData(jsonEncode(WebSocketMessage(
|
||||
path: "/smartbed/connect",
|
||||
type: 5,
|
||||
data: {"mac": webviewTestController.selectDevice['mac']})));
|
||||
path: "/smartbed/connect",
|
||||
type: 1,
|
||||
)));
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
edm.EasyDartModule.websocket.sendData(jsonEncode(
|
||||
WebSocketMessage(path: "/smartbed/connect", type: 5, data: {
|
||||
'mac': webviewTestController.selectDevice['mac'],
|
||||
})));
|
||||
} else {
|
||||
await webviewTestController.web.jsbridge?.dart.pageInActive();
|
||||
await webviewTestController.web.jsbridge?.dart.pageInActive();
|
||||
}
|
||||
CommonVariables.callMap["/smartbed/connect"] = (data) {
|
||||
//订阅连接消息
|
||||
ef.log("[websocket]:$data");
|
||||
ef.log("[设备申请连接]:$data");
|
||||
if (data['type'] == 4) {
|
||||
if (ef.kvRoot.websocketId == data['from']) {
|
||||
return;
|
||||
}
|
||||
//接收到有人正在控制,停止连接
|
||||
if (index == 2) {
|
||||
//通知显示弹窗已被用户绑定
|
||||
try {
|
||||
webviewTestController.web.jsbridge?.dart.haveConnected(data);
|
||||
} catch (e) {
|
||||
ef.log("[websocket]调用网页异常:$e");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data['type'] == 5) {
|
||||
//接收到别人正在申请控制,判断自己是否处于控制页并且连接了该设备
|
||||
if (ef.kvRoot.websocketId == null) {
|
||||
return;
|
||||
}
|
||||
if (ef.kvRoot.websocketId == data['from']) {
|
||||
return;
|
||||
}
|
||||
if (webviewTestController.selectDevice['mac'] == null) {
|
||||
return;
|
||||
}
|
||||
if (index != 2) {
|
||||
//当前不处于控制页且没有连接该设备
|
||||
if (webviewTestController.selectDevice == null ||
|
||||
webviewTestController.selectDevice['mac'] !=
|
||||
data['data']?['mac']) {
|
||||
//如果当前没有连接该设备,则返回
|
||||
return;
|
||||
}
|
||||
//当前不处于控制页且连接了该设备-->进行断开
|
||||
//web todo 断开设备连接
|
||||
webviewTestController.web.jsbridge?.dart.disconnectByOtherUser();
|
||||
} else {
|
||||
ef.log("[websocket]:当前处于控制页,给指定用户发送xxx用户已连接");
|
||||
//当前处于控制页,给指定用户发送xxx用户已连接
|
||||
if (webviewTestController.selectDevice == null ||
|
||||
webviewTestController.selectDevice['mac'] !=
|
||||
data['data']['mac']) {
|
||||
//如果当前没有连接该设备,则返回
|
||||
return;
|
||||
}
|
||||
edm.EasyDartModule.websocket.sendData(jsonEncode(WebSocketMessage(
|
||||
to: data['from'],
|
||||
// to: ef.kvRoot.websocketId,
|
||||
path: "/smartbed/connect",
|
||||
type: 4,
|
||||
data: {
|
||||
"mac": webviewTestController.selectDevice['mac'],
|
||||
"user": userInfoController.model
|
||||
})));
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
ef.log("[激活控制页面报错]:$e");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user