model-action 2.3.5 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/SceneAsset.d.ts +104 -16
- package/dist/modules/SceneAsset.d.ts.map +1 -1
- package/dist/modules/SceneAsset.js +80 -10
- package/dist/modules/SceneAsset.js.map +1 -1
- package/dist/modules/Status.d.ts +9 -0
- package/dist/modules/Status.d.ts.map +1 -1
- package/dist/modules/Status.js +8 -0
- package/dist/modules/Status.js.map +1 -1
- package/dist/peer-stream.d.ts +3 -1
- package/dist/peer-stream.d.ts.map +1 -1
- package/dist/peer-stream.js +30 -6
- package/dist/peer-stream.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/modules/SceneAsset.ts +198 -20
- package/src/modules/Status.ts +164 -149
- package/src/peer-stream.js +32 -11
package/src/modules/Status.ts
CHANGED
|
@@ -1,150 +1,165 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 状态操作方法
|
|
3
|
-
*/
|
|
4
|
-
import { Action } from "./Action";
|
|
5
|
-
|
|
6
|
-
// 状态信息
|
|
7
|
-
export interface StatusInfo {
|
|
8
|
-
id: string; // 唯一标识
|
|
9
|
-
state: string; // 状态值:normal | alarm | color=FFFFFF
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Status命令类型(不继承SendParam,因为data中没有action字段)
|
|
13
|
-
type StatusType = {
|
|
14
|
-
cmd: "status";
|
|
15
|
-
data: {
|
|
16
|
-
isLocation?: boolean; // 是否定位到第一个ID对应的设备,默认false
|
|
17
|
-
type?: string; // 变换状态的类型,非必须,如"POI"
|
|
18
|
-
infos: StatusInfo[]; // 要切换状态的设备的数据
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class StatusAction extends Action {
|
|
23
|
-
/**
|
|
24
|
-
* 切换指定ID的模型、POI等的状态
|
|
25
|
-
* @param infos 状态信息数组,包含id和state
|
|
26
|
-
* @param options 可选参数
|
|
27
|
-
* @param options.isLocation 是否定位到第一个ID对应的设备,默认false
|
|
28
|
-
* @param options.type 变换状态的类型,如"POI"
|
|
29
|
-
*/
|
|
30
|
-
static statusChange(
|
|
31
|
-
infos: StatusInfo[],
|
|
32
|
-
options?: {
|
|
33
|
-
isLocation?: boolean;
|
|
34
|
-
type?: string;
|
|
35
|
-
}
|
|
36
|
-
) {
|
|
37
|
-
const data: {
|
|
38
|
-
isLocation?: boolean;
|
|
39
|
-
type?: string;
|
|
40
|
-
infos: StatusInfo[];
|
|
41
|
-
} = {
|
|
42
|
-
infos
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// 如果提供了 isLocation,则添加(默认false,所以只有为true时才添加)
|
|
46
|
-
if (options?.isLocation !== undefined) {
|
|
47
|
-
data.isLocation = options.isLocation;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 如果提供了 type,则添加
|
|
51
|
-
if (options?.type) {
|
|
52
|
-
data.type = options.type;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const param: StatusType = {
|
|
56
|
-
cmd: "status",
|
|
57
|
-
data
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 生成描述信息
|
|
61
|
-
let msg = '切换状态';
|
|
62
|
-
if (options?.type) {
|
|
63
|
-
msg = `切换${options.type}状态`;
|
|
64
|
-
}
|
|
65
|
-
if (infos.length === 1) {
|
|
66
|
-
msg += ` - ID: ${infos[0].id}, 状态: ${infos[0].state}`;
|
|
67
|
-
} else {
|
|
68
|
-
msg += ` - 共${infos.length}个设备`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 使用类型断言调用sendParam,因为StatusType不严格符合SendParam(缺少action字段)
|
|
72
|
-
return this.sendParam(param as any, msg);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 设置设备为正常状态
|
|
77
|
-
* @param id 设备ID
|
|
78
|
-
* @param options 可选参数
|
|
79
|
-
*/
|
|
80
|
-
static setNormal(
|
|
81
|
-
id: string,
|
|
82
|
-
options?: {
|
|
83
|
-
isLocation?: boolean;
|
|
84
|
-
type?: string;
|
|
85
|
-
}
|
|
86
|
-
) {
|
|
87
|
-
this.statusChange([{ id, state: 'normal' }], options);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @param id 设备ID
|
|
93
|
-
* @param options 可选参数
|
|
94
|
-
*/
|
|
95
|
-
static
|
|
96
|
-
id: string,
|
|
97
|
-
options?: {
|
|
98
|
-
isLocation?: boolean;
|
|
99
|
-
type?: string;
|
|
100
|
-
}
|
|
101
|
-
) {
|
|
102
|
-
this.statusChange([{ id, state: '
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
* @param id 设备ID
|
|
108
|
-
* @param
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 状态操作方法
|
|
3
|
+
*/
|
|
4
|
+
import { Action } from "./Action";
|
|
5
|
+
|
|
6
|
+
// 状态信息
|
|
7
|
+
export interface StatusInfo {
|
|
8
|
+
id: string; // 唯一标识
|
|
9
|
+
state: string; // 状态值:normal | alarm | color=FFFFFF
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Status命令类型(不继承SendParam,因为data中没有action字段)
|
|
13
|
+
type StatusType = {
|
|
14
|
+
cmd: "status";
|
|
15
|
+
data: {
|
|
16
|
+
isLocation?: boolean; // 是否定位到第一个ID对应的设备,默认false
|
|
17
|
+
type?: string; // 变换状态的类型,非必须,如"POI"
|
|
18
|
+
infos: StatusInfo[]; // 要切换状态的设备的数据
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class StatusAction extends Action {
|
|
23
|
+
/**
|
|
24
|
+
* 切换指定ID的模型、POI等的状态
|
|
25
|
+
* @param infos 状态信息数组,包含id和state
|
|
26
|
+
* @param options 可选参数
|
|
27
|
+
* @param options.isLocation 是否定位到第一个ID对应的设备,默认false
|
|
28
|
+
* @param options.type 变换状态的类型,如"POI"
|
|
29
|
+
*/
|
|
30
|
+
static statusChange(
|
|
31
|
+
infos: StatusInfo[],
|
|
32
|
+
options?: {
|
|
33
|
+
isLocation?: boolean;
|
|
34
|
+
type?: string;
|
|
35
|
+
}
|
|
36
|
+
) {
|
|
37
|
+
const data: {
|
|
38
|
+
isLocation?: boolean;
|
|
39
|
+
type?: string;
|
|
40
|
+
infos: StatusInfo[];
|
|
41
|
+
} = {
|
|
42
|
+
infos
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 如果提供了 isLocation,则添加(默认false,所以只有为true时才添加)
|
|
46
|
+
if (options?.isLocation !== undefined) {
|
|
47
|
+
data.isLocation = options.isLocation;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 如果提供了 type,则添加
|
|
51
|
+
if (options?.type) {
|
|
52
|
+
data.type = options.type;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const param: StatusType = {
|
|
56
|
+
cmd: "status",
|
|
57
|
+
data
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 生成描述信息
|
|
61
|
+
let msg = '切换状态';
|
|
62
|
+
if (options?.type) {
|
|
63
|
+
msg = `切换${options.type}状态`;
|
|
64
|
+
}
|
|
65
|
+
if (infos.length === 1) {
|
|
66
|
+
msg += ` - ID: ${infos[0].id}, 状态: ${infos[0].state}`;
|
|
67
|
+
} else {
|
|
68
|
+
msg += ` - 共${infos.length}个设备`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 使用类型断言调用sendParam,因为StatusType不严格符合SendParam(缺少action字段)
|
|
72
|
+
return this.sendParam(param as any, msg);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 设置设备为正常状态
|
|
77
|
+
* @param id 设备ID
|
|
78
|
+
* @param options 可选参数
|
|
79
|
+
*/
|
|
80
|
+
static setNormal(
|
|
81
|
+
id: string,
|
|
82
|
+
options?: {
|
|
83
|
+
isLocation?: boolean;
|
|
84
|
+
type?: string;
|
|
85
|
+
}
|
|
86
|
+
) {
|
|
87
|
+
this.statusChange([{ id, state: 'normal' }], options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 设置设备为离线状态
|
|
92
|
+
* @param id 设备ID
|
|
93
|
+
* @param options 可选参数
|
|
94
|
+
*/
|
|
95
|
+
static setOffline(
|
|
96
|
+
id: string,
|
|
97
|
+
options?: {
|
|
98
|
+
isLocation?: boolean;
|
|
99
|
+
type?: string;
|
|
100
|
+
}
|
|
101
|
+
) {
|
|
102
|
+
this.statusChange([{ id, state: 'offline' }], options);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 设置设备为报警状态
|
|
107
|
+
* @param id 设备ID
|
|
108
|
+
* @param options 可选参数
|
|
109
|
+
*/
|
|
110
|
+
static setAlarm(
|
|
111
|
+
id: string,
|
|
112
|
+
options?: {
|
|
113
|
+
isLocation?: boolean;
|
|
114
|
+
type?: string;
|
|
115
|
+
}
|
|
116
|
+
) {
|
|
117
|
+
this.statusChange([{ id, state: 'alarm' }], options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 设置设备颜色
|
|
122
|
+
* @param id 设备ID
|
|
123
|
+
* @param color 颜色值,格式如 "FFFFFF" 或 "93050C"(不需要#前缀)
|
|
124
|
+
* @param options 可选参数
|
|
125
|
+
*/
|
|
126
|
+
static setColor(
|
|
127
|
+
id: string,
|
|
128
|
+
color: string,
|
|
129
|
+
options?: {
|
|
130
|
+
isLocation?: boolean;
|
|
131
|
+
type?: string;
|
|
132
|
+
}
|
|
133
|
+
) {
|
|
134
|
+
// 移除可能的#前缀
|
|
135
|
+
const colorValue = color.startsWith('#') ? color.slice(1) : color;
|
|
136
|
+
this.statusChange([{ id, state: `color=${colorValue}` }], options);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 批量设置多个设备的状态
|
|
141
|
+
* @param statusMap 状态映射,key为设备ID,value为状态值(normal | alarm | color值)
|
|
142
|
+
* @param options 可选参数
|
|
143
|
+
*/
|
|
144
|
+
static batchSetStatus(
|
|
145
|
+
statusMap: Record<string, string>,
|
|
146
|
+
options?: {
|
|
147
|
+
isLocation?: boolean;
|
|
148
|
+
type?: string;
|
|
149
|
+
}
|
|
150
|
+
) {
|
|
151
|
+
const infos: StatusInfo[] = [];
|
|
152
|
+
for (const id in statusMap) {
|
|
153
|
+
if (statusMap.hasOwnProperty(id)) {
|
|
154
|
+
const state = statusMap[id];
|
|
155
|
+
// 如果state是颜色值(6位十六进制),自动添加color=前缀
|
|
156
|
+
let finalState = state;
|
|
157
|
+
if (/^[0-9A-Fa-f]{6}$/.test(state) && !state.startsWith('color=')) {
|
|
158
|
+
finalState = `color=${state}`;
|
|
159
|
+
}
|
|
160
|
+
infos.push({ id, state: finalState });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
this.statusChange(infos, options);
|
|
164
|
+
}
|
|
150
165
|
}
|
package/src/peer-stream.js
CHANGED
|
@@ -174,7 +174,7 @@ class PeerStream extends HTMLVideoElement {
|
|
|
174
174
|
// overlayDiv.style.borderRadius = '5px';
|
|
175
175
|
// overlayDiv.style.display = 'block'; // Initially hidden
|
|
176
176
|
// this.parentNode.appendChild(overlayDiv)
|
|
177
|
-
console.warn(
|
|
177
|
+
console.warn("你的浏览器版本过低 推荐使用谷歌100以上版本浏览器")
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// This will happen each time the node is moved, and may happen before the element"s contents have been fully parsed. may be called once your element is no longer connected
|
|
@@ -284,6 +284,8 @@ class PeerStream extends HTMLVideoElement {
|
|
|
284
284
|
if ((now - this.lastmouseTime) > this.mouseReleaseTime * 1000) {
|
|
285
285
|
msg.type = "mouseRelease"
|
|
286
286
|
this.ws.send(JSON.stringify(msg));
|
|
287
|
+
this.mouseReleaseTime = undefined
|
|
288
|
+
this.dispatchEvent(new CustomEvent("mouseRelease", { detail: "" }));
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
}
|
|
@@ -300,6 +302,10 @@ class PeerStream extends HTMLVideoElement {
|
|
|
300
302
|
console.log("↓↓ getStatus:", msg);
|
|
301
303
|
this.handleGetStatus(msg)
|
|
302
304
|
}
|
|
305
|
+
else if(msg.type === "getUeinstance"){
|
|
306
|
+
console.log("↓↓ getUeinstance:", msg);
|
|
307
|
+
this.dispatchEvent(new CustomEvent("getUeinstance", { detail: msg }));
|
|
308
|
+
}
|
|
303
309
|
else {
|
|
304
310
|
console.warn("↓↓", msg);
|
|
305
311
|
}
|
|
@@ -753,19 +759,20 @@ class PeerStream extends HTMLVideoElement {
|
|
|
753
759
|
|
|
754
760
|
this.onmousedown = (e) => {
|
|
755
761
|
this.emitMouseDown(e.button, e.offsetX, e.offsetY);
|
|
756
|
-
//
|
|
762
|
+
//e.preventDefault();
|
|
757
763
|
};
|
|
758
764
|
|
|
759
765
|
this.onmouseup = (e) => {
|
|
760
766
|
this.emitMouseUp(e.button, e.offsetX, e.offsetY);
|
|
761
|
-
//
|
|
767
|
+
//e.preventDefault();
|
|
762
768
|
};
|
|
763
769
|
|
|
764
770
|
// When the context menu is shown then it is safest to release the button which was pressed when the event happened. This will guarantee we will get at least one mouse up corresponding to a mouse down event. Otherwise the mouse can get stuck.
|
|
765
771
|
// https://github.com/facebook/react/issues/5531
|
|
766
772
|
this.oncontextmenu = (e) => {
|
|
767
|
-
this.emitMouseUp(e.button, e.offsetX, e.offsetY);
|
|
773
|
+
//this.emitMouseUp(e.button, e.offsetX, e.offsetY);
|
|
768
774
|
e.preventDefault();
|
|
775
|
+
return false;
|
|
769
776
|
};
|
|
770
777
|
|
|
771
778
|
this.onwheel = (e) => {
|
|
@@ -906,13 +913,18 @@ class PeerStream extends HTMLVideoElement {
|
|
|
906
913
|
data.setUint16(byteIdx, msg.charCodeAt(i), true);
|
|
907
914
|
byteIdx += 2;
|
|
908
915
|
}
|
|
909
|
-
|
|
916
|
+
try{
|
|
917
|
+
this.dc.send(data);
|
|
918
|
+
}catch(error){
|
|
919
|
+
console.error(error.message);
|
|
920
|
+
}
|
|
921
|
+
|
|
910
922
|
|
|
911
|
-
return new Promise(resolve => this.addEventListener(
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
));
|
|
923
|
+
// return new Promise(resolve => this.addEventListener(
|
|
924
|
+
// 'message',
|
|
925
|
+
// e => resolve(e.detail),
|
|
926
|
+
// { once: true }
|
|
927
|
+
// ));
|
|
916
928
|
}
|
|
917
929
|
|
|
918
930
|
normalize(x, y) {
|
|
@@ -934,6 +946,15 @@ class PeerStream extends HTMLVideoElement {
|
|
|
934
946
|
}
|
|
935
947
|
|
|
936
948
|
|
|
949
|
+
getUeInstance(){
|
|
950
|
+
let msg={type: "getUeinstance"}
|
|
951
|
+
this.ws.send(JSON.stringify(msg));
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
killUe(){
|
|
955
|
+
let msg={type: "killUe"}
|
|
956
|
+
this.ws.send(JSON.stringify(msg));
|
|
957
|
+
}
|
|
937
958
|
}
|
|
938
959
|
|
|
939
|
-
customElements.define("peer-stream", PeerStream, { extends: "video" });
|
|
960
|
+
customElements.define("peer-stream", PeerStream, { extends: "video" });
|