model-action 1.0.24 → 2.0.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.
Files changed (100) hide show
  1. package/dist/index.d.ts +13 -4
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +12 -4
  4. package/dist/index.js.map +1 -0
  5. package/dist/modules/Action.d.ts +5 -14
  6. package/dist/modules/Action.d.ts.map +1 -0
  7. package/dist/modules/Action.js +2 -10
  8. package/dist/modules/Action.js.map +1 -0
  9. package/dist/modules/Animation.d.ts +59 -0
  10. package/dist/modules/Animation.d.ts.map +1 -0
  11. package/dist/modules/Animation.js +117 -0
  12. package/dist/modules/Animation.js.map +1 -0
  13. package/dist/modules/Building.d.ts +28 -0
  14. package/dist/modules/Building.d.ts.map +1 -0
  15. package/dist/modules/Building.js +70 -0
  16. package/dist/modules/Building.js.map +1 -0
  17. package/dist/modules/Camera.d.ts +37 -0
  18. package/dist/modules/Camera.d.ts.map +1 -0
  19. package/dist/modules/Camera.js +110 -0
  20. package/dist/modules/Camera.js.map +1 -0
  21. package/dist/modules/CameraView.d.ts +37 -0
  22. package/dist/modules/CameraView.d.ts.map +1 -0
  23. package/dist/modules/CameraView.js +110 -0
  24. package/dist/modules/CameraView.js.map +1 -0
  25. package/dist/modules/Effect.d.ts +37 -0
  26. package/dist/modules/Effect.d.ts.map +1 -0
  27. package/dist/modules/Effect.js +72 -0
  28. package/dist/modules/Effect.js.map +1 -0
  29. package/dist/modules/Environment.d.ts +22 -0
  30. package/dist/modules/Environment.d.ts.map +1 -0
  31. package/dist/modules/Environment.js +53 -0
  32. package/dist/modules/Environment.js.map +1 -0
  33. package/dist/modules/Focus.d.ts +12 -0
  34. package/dist/modules/Focus.d.ts.map +1 -0
  35. package/dist/modules/Focus.js +22 -0
  36. package/dist/modules/Focus.js.map +1 -0
  37. package/dist/modules/GameMode.d.ts +17 -0
  38. package/dist/modules/GameMode.d.ts.map +1 -0
  39. package/dist/modules/GameMode.js +36 -0
  40. package/dist/modules/GameMode.js.map +1 -0
  41. package/dist/modules/Init.d.ts +28 -0
  42. package/dist/modules/Init.d.ts.map +1 -0
  43. package/dist/modules/Init.js +81 -0
  44. package/dist/modules/Init.js.map +1 -0
  45. package/dist/modules/Path.d.ts +76 -0
  46. package/dist/modules/Path.d.ts.map +1 -0
  47. package/dist/modules/Path.js +155 -0
  48. package/dist/modules/Path.js.map +1 -0
  49. package/dist/modules/Poi.d.ts +45 -62
  50. package/dist/modules/Poi.d.ts.map +1 -0
  51. package/dist/modules/Poi.js +117 -88
  52. package/dist/modules/Poi.js.map +1 -0
  53. package/dist/modules/Routing.d.ts +23 -31
  54. package/dist/modules/Routing.d.ts.map +1 -0
  55. package/dist/modules/Routing.js +62 -63
  56. package/dist/modules/Routing.js.map +1 -0
  57. package/dist/modules/Scene.d.ts +12 -15
  58. package/dist/modules/Scene.d.ts.map +1 -0
  59. package/dist/modules/Scene.js +26 -15
  60. package/dist/modules/Scene.js.map +1 -0
  61. package/dist/modules/Status.d.ts +59 -0
  62. package/dist/modules/Status.d.ts.map +1 -0
  63. package/dist/modules/Status.js +91 -0
  64. package/dist/modules/Status.js.map +1 -0
  65. package/dist/modules/Track.d.ts +65 -22
  66. package/dist/modules/Track.d.ts.map +1 -0
  67. package/dist/modules/Track.js +128 -20
  68. package/dist/modules/Track.js.map +1 -0
  69. package/dist/modules/VideoFusion.d.ts +1 -0
  70. package/dist/modules/VideoFusion.d.ts.map +1 -0
  71. package/dist/modules/VideoFusion.js +1 -0
  72. package/dist/modules/VideoFusion.js.map +1 -0
  73. package/dist/modules/Window.d.ts +1 -0
  74. package/dist/modules/Window.d.ts.map +1 -0
  75. package/dist/modules/Window.js +1 -0
  76. package/dist/modules/Window.js.map +1 -0
  77. package/dist/peer-stream.d.ts +123 -0
  78. package/dist/peer-stream.d.ts.map +1 -0
  79. package/dist/peer-stream.js +852 -0
  80. package/dist/peer-stream.js.map +1 -0
  81. package/package.json +1 -1
  82. package/src/index.ts +12 -4
  83. package/src/modules/Action.ts +5 -25
  84. package/src/modules/Animation.ts +171 -0
  85. package/src/modules/Building.ts +103 -0
  86. package/src/modules/CameraView.ts +175 -0
  87. package/src/modules/Effect.ts +127 -0
  88. package/src/modules/Environment.ts +81 -0
  89. package/src/modules/Focus.ts +33 -0
  90. package/src/modules/GameMode.ts +60 -0
  91. package/src/modules/Init.ts +104 -0
  92. package/src/modules/Path.ts +293 -0
  93. package/src/modules/Poi.ts +194 -117
  94. package/src/modules/Routing.ts +96 -85
  95. package/src/modules/Scene.ts +43 -21
  96. package/src/modules/Status.ts +150 -0
  97. package/src/peer-stream.js +938 -0
  98. package/src/modules/Track.ts +0 -64
  99. package/src/modules/VideoFusion.ts +0 -122
  100. package/src/modules/Window.ts +0 -40
@@ -0,0 +1,150 @@
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
+ 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 setAlarm(
96
+ id: string,
97
+ options?: {
98
+ isLocation?: boolean;
99
+ type?: string;
100
+ }
101
+ ) {
102
+ this.statusChange([{ id, state: 'alarm' }], options);
103
+ }
104
+
105
+ /**
106
+ * 设置设备颜色
107
+ * @param id 设备ID
108
+ * @param color 颜色值,格式如 "FFFFFF" 或 "93050C"(不需要#前缀)
109
+ * @param options 可选参数
110
+ */
111
+ static setColor(
112
+ id: string,
113
+ color: string,
114
+ options?: {
115
+ isLocation?: boolean;
116
+ type?: string;
117
+ }
118
+ ) {
119
+ // 移除可能的#前缀
120
+ const colorValue = color.startsWith('#') ? color.slice(1) : color;
121
+ this.statusChange([{ id, state: `color=${colorValue}` }], options);
122
+ }
123
+
124
+ /**
125
+ * 批量设置多个设备的状态
126
+ * @param statusMap 状态映射,key为设备ID,value为状态值(normal | alarm | color值)
127
+ * @param options 可选参数
128
+ */
129
+ static batchSetStatus(
130
+ statusMap: Record<string, string>,
131
+ options?: {
132
+ isLocation?: boolean;
133
+ type?: string;
134
+ }
135
+ ) {
136
+ const infos: StatusInfo[] = [];
137
+ for (const id in statusMap) {
138
+ if (statusMap.hasOwnProperty(id)) {
139
+ const state = statusMap[id];
140
+ // 如果state是颜色值(6位十六进制),自动添加color=前缀
141
+ let finalState = state;
142
+ if (/^[0-9A-Fa-f]{6}$/.test(state) && !state.startsWith('color=')) {
143
+ finalState = `color=${state}`;
144
+ }
145
+ infos.push({ id, state: finalState });
146
+ }
147
+ }
148
+ this.statusChange(infos, options);
149
+ }
150
+ }