更新多个用户连接同一个设备的通知
This commit is contained in:
@@ -177,6 +177,10 @@ void initEasyDartModule() {
|
||||
WebSocketConfig(ServiceConstant.webSocketService, (data) {
|
||||
// 接收到服务消息
|
||||
var json = jsonDecode(data);
|
||||
ef.log("[websokcet]:${json}");
|
||||
if (json['wsId'] != null) {
|
||||
ef.kvRoot.websocketId = json['wsId'];
|
||||
}
|
||||
if (json['code'] != null && json['code'] != 200) {
|
||||
EasyDartModule.logger.error("websocket连接失败--》" + json);
|
||||
}
|
||||
@@ -184,7 +188,11 @@ void initEasyDartModule() {
|
||||
var call = CommonVariables.callMap[json["path"]];
|
||||
if (call != null) {
|
||||
try {
|
||||
call(json["data"]);
|
||||
if (json['path'] != "/smartbed/connect") {
|
||||
call(json["data"]);
|
||||
} else {
|
||||
call(json);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ class WebSocketMessage {
|
||||
String path;
|
||||
int? type;
|
||||
dynamic data;
|
||||
String? to;
|
||||
|
||||
WebSocketMessage({required this.path, this.type, this.data});
|
||||
WebSocketMessage({required this.path, this.type, this.data, this.to});
|
||||
|
||||
static WebSocketMessage fromJson(Map<String, dynamic> json) =>
|
||||
_$WebSocketMessageFromJson(json);
|
||||
|
||||
@@ -11,6 +11,7 @@ WebSocketMessage _$WebSocketMessageFromJson(Map<String, dynamic> json) =>
|
||||
path: json['path'] as String,
|
||||
type: (json['type'] as num?)?.toInt(),
|
||||
data: json['data'],
|
||||
to: json['to'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$WebSocketMessageToJson(WebSocketMessage instance) =>
|
||||
@@ -18,4 +19,5 @@ Map<String, dynamic> _$WebSocketMessageToJson(WebSocketMessage instance) =>
|
||||
'path': instance.path,
|
||||
'type': instance.type,
|
||||
'data': instance.data,
|
||||
'to': instance.to,
|
||||
};
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -188,8 +188,7 @@ class _RoomPickerPageState extends State<RoomPickerPage> {
|
||||
"id": editedData["_id"],
|
||||
"roomId": rooms[selectedIndex]['_id'],
|
||||
},
|
||||
onSuccess: (res) {
|
||||
|
||||
onSuccess: (res) {
|
||||
TopSlideNotification.show(context,
|
||||
text: "更新成功".tr,
|
||||
textColor: Color(0XFF00C1AA));
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/WebSocketMessage.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||
|
||||
class WebviewTestModel {
|
||||
@@ -69,13 +70,15 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
(selectDevice['mac'] != args[0]['mac'])) {
|
||||
lastSelectDevice = selectDevice;
|
||||
}
|
||||
edm.EasyDartModule.websocket.sendData(jsonEncode(
|
||||
WebSocketMessage(path: "/smartbed/connect", type: 5, data: {
|
||||
'mac': selectDevice['mac'],
|
||||
})));
|
||||
dealInstantData(selectDevice);
|
||||
} catch (e) {
|
||||
ef.log("[aaaa]$e");
|
||||
ef.log("[切换设备失败]$e");
|
||||
}
|
||||
|
||||
//查询人员信息
|
||||
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.updateBlueToothStatus((args) async {
|
||||
|
||||
Reference in New Issue
Block a user