@cutos/core 3.2.7 → 3.2.8

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/README.md CHANGED
@@ -112,7 +112,7 @@ CoreAPI.getVersion();
112
112
  - Return result example:
113
113
 
114
114
  ```
115
- "3.2.7"
115
+ "3.2.8"
116
116
  ```
117
117
 
118
118
  ### CoreAPI.getPlatform
package/dist/cutos.cjs.js CHANGED
@@ -398,7 +398,7 @@ const cutosAPI$2 = {
398
398
  var cutosApi = cutosAPI$2;
399
399
 
400
400
  var name = "@cutos/core";
401
- var version = "3.2.7";
401
+ var version = "3.2.8";
402
402
  var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
403
403
  var main = "dist/cutos.cjs.js";
404
404
  var module$1 = "dist/cutos.esm.js";
@@ -456,6 +456,7 @@ const callbackMap = new Map();
456
456
  const callbackInterval = 500; // 500ms
457
457
  const callbackTimeout = 5000; // 5s
458
458
  const listenerMap = new Map();
459
+ const ipcListenerMap = new Map();
459
460
  const packageJson = require$$3;
460
461
 
461
462
  const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
@@ -892,7 +893,8 @@ class IPC {
892
893
  let body = {};
893
894
  body.channel = channel;
894
895
  body.args = args;
895
- return publishRequest(cutosAPI$1.CORE_NORESP.IPC, callback, body, this.destAddress);
896
+ let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
897
+ return publishRequest(topic, callback, body, this.destAddress);
896
898
  }
897
899
 
898
900
  /**
@@ -908,7 +910,8 @@ class IPC {
908
910
  response.id = context.id;
909
911
  response.result = result;
910
912
  response.err = error;
911
- client.publish(cutosAPI$1.CORE_NORESP.IPC, JSON.stringify(response));
913
+ let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
914
+ client.publish(topic, JSON.stringify(response));
912
915
  }
913
916
 
914
917
  /**
@@ -917,11 +920,21 @@ class IPC {
917
920
  * @param listener (args, context) the context use when sendResponse
918
921
  */
919
922
  on(channel, listener) {
920
- listenerMap.set(channel, listener);
923
+ if (!ipcListenerMap.has(channel)) {
924
+ ipcListenerMap.set(channel, []);
925
+ }
926
+ ipcListenerMap.get(channel).push(listener);
921
927
  }
922
928
 
923
- removeListener(channel) {
924
- listenerMap.delete(channel);
929
+ removeListener(channel, listener = null) {
930
+ if (!ipcListenerMap.has(channel)) {
931
+ return;
932
+ }
933
+ if (!listener) {
934
+ ipcListenerMap.delete(channel);
935
+ } else {
936
+ ipcListenerMap.has(channel).indexOf(listener) > -1 && ipcListenerMap.get(channel).splice(ipcListenerMap.get(channel).indexOf(listener), 1);
937
+ }
925
938
  }
926
939
  }
927
940
 
@@ -1240,9 +1253,11 @@ const CoreAPI$2 = {
1240
1253
  doCallback(_message.id, _message.result, _message.err);
1241
1254
  return
1242
1255
  }
1243
- let listener = listenerMap.get(_message.body.channel);
1244
- if (listener !== undefined) {
1245
- listener(_message.body.args, _message.context);
1256
+ let listenerArray = ipcListenerMap.get(_message.body.channel);
1257
+ if (listenerArray) {
1258
+ for (const listener of listenerArray) {
1259
+ listener(_message.body.args, _message.context);
1260
+ }
1246
1261
  }
1247
1262
  } else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
1248
1263
  || topic.startsWith(cutosAPI$1.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
package/dist/cutos.esm.js CHANGED
@@ -690,7 +690,7 @@ const cutosAPI$2 = {
690
690
  var cutosApi = cutosAPI$2;
691
691
 
692
692
  var name = "@cutos/core";
693
- var version = "3.2.7";
693
+ var version = "3.2.8";
694
694
  var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
695
695
  var main = "dist/cutos.cjs.js";
696
696
  var module = "dist/cutos.esm.js";
@@ -748,6 +748,7 @@ const callbackMap = new Map();
748
748
  const callbackInterval = 500; // 500ms
749
749
  const callbackTimeout = 5000; // 5s
750
750
  const listenerMap = new Map();
751
+ const ipcListenerMap = new Map();
751
752
  const packageJson = require$$3;
752
753
 
753
754
  const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
@@ -1184,7 +1185,8 @@ class IPC {
1184
1185
  let body = {};
1185
1186
  body.channel = channel;
1186
1187
  body.args = args;
1187
- return publishRequest(cutosAPI$1.CORE_NORESP.IPC, callback, body, this.destAddress);
1188
+ let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
1189
+ return publishRequest(topic, callback, body, this.destAddress);
1188
1190
  }
1189
1191
 
1190
1192
  /**
@@ -1200,7 +1202,8 @@ class IPC {
1200
1202
  response.id = context.id;
1201
1203
  response.result = result;
1202
1204
  response.err = error;
1203
- client.publish(cutosAPI$1.CORE_NORESP.IPC, JSON.stringify(response));
1205
+ let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
1206
+ client.publish(topic, JSON.stringify(response));
1204
1207
  }
1205
1208
 
1206
1209
  /**
@@ -1209,11 +1212,21 @@ class IPC {
1209
1212
  * @param listener (args, context) the context use when sendResponse
1210
1213
  */
1211
1214
  on(channel, listener) {
1212
- listenerMap.set(channel, listener);
1215
+ if (!ipcListenerMap.has(channel)) {
1216
+ ipcListenerMap.set(channel, []);
1217
+ }
1218
+ ipcListenerMap.get(channel).push(listener);
1213
1219
  }
1214
1220
 
1215
- removeListener(channel) {
1216
- listenerMap.delete(channel);
1221
+ removeListener(channel, listener = null) {
1222
+ if (!ipcListenerMap.has(channel)) {
1223
+ return;
1224
+ }
1225
+ if (!listener) {
1226
+ ipcListenerMap.delete(channel);
1227
+ } else {
1228
+ ipcListenerMap.has(channel).indexOf(listener) > -1 && ipcListenerMap.get(channel).splice(ipcListenerMap.get(channel).indexOf(listener), 1);
1229
+ }
1217
1230
  }
1218
1231
  }
1219
1232
 
@@ -1532,9 +1545,11 @@ const CoreAPI$2 = {
1532
1545
  doCallback(_message.id, _message.result, _message.err);
1533
1546
  return
1534
1547
  }
1535
- let listener = listenerMap.get(_message.body.channel);
1536
- if (listener !== undefined) {
1537
- listener(_message.body.args, _message.context);
1548
+ let listenerArray = ipcListenerMap.get(_message.body.channel);
1549
+ if (listenerArray) {
1550
+ for (const listener of listenerArray) {
1551
+ listener(_message.body.args, _message.context);
1552
+ }
1538
1553
  }
1539
1554
  } else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
1540
1555
  || topic.startsWith(cutosAPI$1.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "3.2.7",
3
+ "version": "3.2.8",
4
4
  "description": "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ",
5
5
  "main": "dist/cutos.cjs.js",
6
6
  "module": "dist/cutos.esm.js",