...
|
...
|
@@ -23,6 +23,7 @@ import { |
23
|
23
|
TsSubCmdsItemType,
|
24
|
24
|
} from './useSocket.type';
|
25
|
25
|
import { ComponentPropsConfigType } from '../../index.type';
|
|
26
|
+import { isNullOrUnDef } from '/@/utils/is';
|
26
|
27
|
|
27
|
28
|
interface DeviceGroupMapType {
|
28
|
29
|
subscriptionId: number;
|
...
|
...
|
@@ -70,11 +71,14 @@ class Subscriber { |
70
|
71
|
clearSubscriber = () => {
|
71
|
72
|
this.deviceGroupMap.clear();
|
72
|
73
|
this.subscriptionMap.clear();
|
73
|
|
- this.componentUpdateFnMap.clear();
|
74
|
|
- this.componentGroupUpdateFnMap.clear();
|
75
|
74
|
this.customSubscribeMap.clear();
|
76
|
75
|
};
|
77
|
76
|
|
|
77
|
+ clearUpdateFn() {
|
|
78
|
+ this.componentUpdateFnMap.clear();
|
|
79
|
+ this.componentGroupUpdateFnMap.clear();
|
|
80
|
+ }
|
|
81
|
+
|
78
|
82
|
addSubscriber = (info: Record<'deviceId' | 'slaveDeviceId' | 'attribute' | 'uuid', string>) => {
|
79
|
83
|
const { deviceId, attribute, uuid } = info;
|
80
|
84
|
if (!this.deviceGroupMap.has(deviceId)) {
|
...
|
...
|
@@ -188,7 +192,7 @@ class Subscriber { |
188
|
192
|
return;
|
189
|
193
|
}
|
190
|
194
|
|
191
|
|
- if (message.subscriptionId) {
|
|
195
|
+ if (!isNullOrUnDef(message.subscriptionId)) {
|
192
|
196
|
this.triggerTsSubCmdsMessage(message);
|
193
|
197
|
}
|
194
|
198
|
}
|
...
|
...
|
@@ -204,29 +208,30 @@ class Subscriber { |
204
|
208
|
const updateGroups = this.componentGroupUpdateFnMap.get(deviceId);
|
205
|
209
|
|
206
|
210
|
if (updateGroups) {
|
207
|
|
- (updateGroups || []).forEach((item) => {
|
|
211
|
+ for (const item of updateGroups || []) {
|
208
|
212
|
const { attributes, fn } = item;
|
209
|
213
|
try {
|
210
|
|
- if (!fn) return;
|
|
214
|
+ if (!fn) continue;
|
211
|
215
|
fn?.(this.getGroupScopeMessage(message, attributes, deviceId), deviceId, attributes);
|
212
|
216
|
} catch (error) {
|
213
|
217
|
console.error(`deviceId: ${deviceId}`);
|
214
|
218
|
throw error;
|
215
|
219
|
}
|
216
|
|
- });
|
|
220
|
+ }
|
|
221
|
+ return;
|
217
|
222
|
}
|
218
|
223
|
|
219
|
|
- subscriptionGroup.forEach((item) => {
|
|
224
|
+ for (const item of subscriptionGroup) {
|
220
|
225
|
const { attribute, uuid } = item;
|
221
|
226
|
const updateFn = this.componentUpdateFnMap.get(uuid);
|
222
|
227
|
try {
|
223
|
|
- if (!updateFn) return;
|
|
228
|
+ if (!updateFn) continue;
|
224
|
229
|
updateFn?.(this.getScopeMessage(message, [attribute]), attribute);
|
225
|
230
|
} catch (error) {
|
226
|
231
|
console.error(`uuid: ${uuid}`);
|
227
|
232
|
throw error;
|
228
|
233
|
}
|
229
|
|
- });
|
|
234
|
+ }
|
230
|
235
|
}
|
231
|
236
|
|
232
|
237
|
triggerAlarmDataMesssage(message: ReceiveAlarmDataCmdsMessageType) {
|
...
|
...
|
@@ -299,6 +304,8 @@ export const useSocket = (dataSourceRef: Ref<WidgetDataType[]>) => { |
299
|
304
|
|
300
|
305
|
onUnmounted(() => {
|
301
|
306
|
close();
|
|
307
|
+ subscriber.clearSubscriber();
|
|
308
|
+ subscriber.clearUpdateFn();
|
302
|
309
|
});
|
303
|
310
|
|
304
|
311
|
return {
|
...
|
...
|
|