@cutos/core 3.2.8 → 3.3.0
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/cutos.cjs.js +38 -25
- package/dist/cutos.esm.js +38 -25
- package/package.json +1 -1
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.
|
|
401
|
+
var version = "3.3.0";
|
|
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";
|
|
@@ -506,7 +506,7 @@ function saveCallback(id, item) {
|
|
|
506
506
|
let currentTimestamp = new Date().getTime();
|
|
507
507
|
callbackMap.forEach((callbackItem, id) => {
|
|
508
508
|
if (currentTimestamp - callbackItem.timestamp > callbackTimeout) {
|
|
509
|
-
|
|
509
|
+
console.warn("callback is timeout");
|
|
510
510
|
callbackMap.delete(id);
|
|
511
511
|
}
|
|
512
512
|
});
|
|
@@ -517,11 +517,14 @@ function doCallback(id, body, err) {
|
|
|
517
517
|
if (!callbackMap.has(id)) {
|
|
518
518
|
return false;
|
|
519
519
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
try {
|
|
521
|
+
if (err) {
|
|
522
|
+
callbackMap.get(id).callback(null, new CutosError('CUTOS CORE error', err));
|
|
523
|
+
} else {
|
|
524
|
+
callbackMap.get(id).callback(body);
|
|
525
|
+
}
|
|
526
|
+
} catch (e) {
|
|
527
|
+
console.warn(e.message);
|
|
525
528
|
}
|
|
526
529
|
|
|
527
530
|
callbackMap.delete(id);
|
|
@@ -886,7 +889,7 @@ class IPC {
|
|
|
886
889
|
* send message to channel
|
|
887
890
|
* @param channel
|
|
888
891
|
* @param args
|
|
889
|
-
* @param callback (result
|
|
892
|
+
* @param callback (result) response from receiver
|
|
890
893
|
* @returns {boolean}
|
|
891
894
|
*/
|
|
892
895
|
sendTo(channel, args, callback = null) {
|
|
@@ -898,34 +901,46 @@ class IPC {
|
|
|
898
901
|
}
|
|
899
902
|
|
|
900
903
|
/**
|
|
901
|
-
*
|
|
902
|
-
* @param context
|
|
904
|
+
* internal function, used to response sender with the result
|
|
905
|
+
* @param context contain sender information
|
|
903
906
|
* @param result
|
|
904
|
-
* @param error
|
|
905
907
|
*/
|
|
906
|
-
|
|
908
|
+
_sendResponse(context, result) {
|
|
907
909
|
let response = {};
|
|
908
910
|
response.context = {};
|
|
909
911
|
response.context.destAddress = context.sourceAddress;
|
|
910
912
|
response.id = context.id;
|
|
911
913
|
response.result = result;
|
|
912
|
-
response.err = error;
|
|
913
914
|
let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
|
|
914
915
|
client.publish(topic, JSON.stringify(response));
|
|
915
916
|
}
|
|
916
917
|
|
|
917
918
|
/**
|
|
918
|
-
*
|
|
919
|
+
* listening channel
|
|
919
920
|
* @param channel
|
|
920
|
-
* @param listener (args,
|
|
921
|
+
* @param listener (args, callback(result)) args is the data from sender, callback is used to response sender with the result
|
|
921
922
|
*/
|
|
922
923
|
on(channel, listener) {
|
|
923
|
-
if (
|
|
924
|
-
ipcListenerMap.
|
|
924
|
+
if (listener) {
|
|
925
|
+
if (!ipcListenerMap.has(channel)) {
|
|
926
|
+
ipcListenerMap.set(channel, new Map());
|
|
927
|
+
}
|
|
928
|
+
if (!ipcListenerMap.get(channel).has(listener)) {
|
|
929
|
+
let innerListener = (args, context) => {
|
|
930
|
+
listener(args, (result) => {
|
|
931
|
+
this._sendResponse(context, result);
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
ipcListenerMap.get(channel).set(listener, innerListener);
|
|
935
|
+
}
|
|
925
936
|
}
|
|
926
|
-
ipcListenerMap.get(channel).push(listener);
|
|
927
937
|
}
|
|
928
938
|
|
|
939
|
+
/**
|
|
940
|
+
* unsubscribe from channel, if listener is null, all listeners will remove
|
|
941
|
+
* @param channel
|
|
942
|
+
* @param listener
|
|
943
|
+
*/
|
|
929
944
|
removeListener(channel, listener = null) {
|
|
930
945
|
if (!ipcListenerMap.has(channel)) {
|
|
931
946
|
return;
|
|
@@ -933,7 +948,7 @@ class IPC {
|
|
|
933
948
|
if (!listener) {
|
|
934
949
|
ipcListenerMap.delete(channel);
|
|
935
950
|
} else {
|
|
936
|
-
ipcListenerMap.
|
|
951
|
+
ipcListenerMap.get(channel).delete(listener);
|
|
937
952
|
}
|
|
938
953
|
}
|
|
939
954
|
}
|
|
@@ -1250,14 +1265,12 @@ const CoreAPI$2 = {
|
|
|
1250
1265
|
if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
1251
1266
|
// process response message
|
|
1252
1267
|
if (_message.id) {
|
|
1253
|
-
doCallback(_message.id, _message.result
|
|
1268
|
+
doCallback(_message.id, _message.result);
|
|
1254
1269
|
return
|
|
1255
1270
|
}
|
|
1256
|
-
let
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1259
|
-
listener(_message.body.args, _message.context);
|
|
1260
|
-
}
|
|
1271
|
+
let listenerMap = ipcListenerMap.get(_message.body.channel);
|
|
1272
|
+
if (listenerMap) {
|
|
1273
|
+
listenerMap.forEach(listener => listener(_message.body.args, _message.context));
|
|
1261
1274
|
}
|
|
1262
1275
|
} else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
|
|
1263
1276
|
|| 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.
|
|
693
|
+
var version = "3.3.0";
|
|
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";
|
|
@@ -798,7 +798,7 @@ function saveCallback(id, item) {
|
|
|
798
798
|
let currentTimestamp = new Date().getTime();
|
|
799
799
|
callbackMap.forEach((callbackItem, id) => {
|
|
800
800
|
if (currentTimestamp - callbackItem.timestamp > callbackTimeout) {
|
|
801
|
-
|
|
801
|
+
console.warn("callback is timeout");
|
|
802
802
|
callbackMap.delete(id);
|
|
803
803
|
}
|
|
804
804
|
});
|
|
@@ -809,11 +809,14 @@ function doCallback(id, body, err) {
|
|
|
809
809
|
if (!callbackMap.has(id)) {
|
|
810
810
|
return false;
|
|
811
811
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
812
|
+
try {
|
|
813
|
+
if (err) {
|
|
814
|
+
callbackMap.get(id).callback(null, new CutosError('CUTOS CORE error', err));
|
|
815
|
+
} else {
|
|
816
|
+
callbackMap.get(id).callback(body);
|
|
817
|
+
}
|
|
818
|
+
} catch (e) {
|
|
819
|
+
console.warn(e.message);
|
|
817
820
|
}
|
|
818
821
|
|
|
819
822
|
callbackMap.delete(id);
|
|
@@ -1178,7 +1181,7 @@ class IPC {
|
|
|
1178
1181
|
* send message to channel
|
|
1179
1182
|
* @param channel
|
|
1180
1183
|
* @param args
|
|
1181
|
-
* @param callback (result
|
|
1184
|
+
* @param callback (result) response from receiver
|
|
1182
1185
|
* @returns {boolean}
|
|
1183
1186
|
*/
|
|
1184
1187
|
sendTo(channel, args, callback = null) {
|
|
@@ -1190,34 +1193,46 @@ class IPC {
|
|
|
1190
1193
|
}
|
|
1191
1194
|
|
|
1192
1195
|
/**
|
|
1193
|
-
*
|
|
1194
|
-
* @param context
|
|
1196
|
+
* internal function, used to response sender with the result
|
|
1197
|
+
* @param context contain sender information
|
|
1195
1198
|
* @param result
|
|
1196
|
-
* @param error
|
|
1197
1199
|
*/
|
|
1198
|
-
|
|
1200
|
+
_sendResponse(context, result) {
|
|
1199
1201
|
let response = {};
|
|
1200
1202
|
response.context = {};
|
|
1201
1203
|
response.context.destAddress = context.sourceAddress;
|
|
1202
1204
|
response.id = context.id;
|
|
1203
1205
|
response.result = result;
|
|
1204
|
-
response.err = error;
|
|
1205
1206
|
let topic = cutosAPI$1.CORE_NORESP.IPC + (this.destAddress ? "" : "-endpoint");
|
|
1206
1207
|
client.publish(topic, JSON.stringify(response));
|
|
1207
1208
|
}
|
|
1208
1209
|
|
|
1209
1210
|
/**
|
|
1210
|
-
*
|
|
1211
|
+
* listening channel
|
|
1211
1212
|
* @param channel
|
|
1212
|
-
* @param listener (args,
|
|
1213
|
+
* @param listener (args, callback(result)) args is the data from sender, callback is used to response sender with the result
|
|
1213
1214
|
*/
|
|
1214
1215
|
on(channel, listener) {
|
|
1215
|
-
if (
|
|
1216
|
-
ipcListenerMap.
|
|
1216
|
+
if (listener) {
|
|
1217
|
+
if (!ipcListenerMap.has(channel)) {
|
|
1218
|
+
ipcListenerMap.set(channel, new Map());
|
|
1219
|
+
}
|
|
1220
|
+
if (!ipcListenerMap.get(channel).has(listener)) {
|
|
1221
|
+
let innerListener = (args, context) => {
|
|
1222
|
+
listener(args, (result) => {
|
|
1223
|
+
this._sendResponse(context, result);
|
|
1224
|
+
});
|
|
1225
|
+
};
|
|
1226
|
+
ipcListenerMap.get(channel).set(listener, innerListener);
|
|
1227
|
+
}
|
|
1217
1228
|
}
|
|
1218
|
-
ipcListenerMap.get(channel).push(listener);
|
|
1219
1229
|
}
|
|
1220
1230
|
|
|
1231
|
+
/**
|
|
1232
|
+
* unsubscribe from channel, if listener is null, all listeners will remove
|
|
1233
|
+
* @param channel
|
|
1234
|
+
* @param listener
|
|
1235
|
+
*/
|
|
1221
1236
|
removeListener(channel, listener = null) {
|
|
1222
1237
|
if (!ipcListenerMap.has(channel)) {
|
|
1223
1238
|
return;
|
|
@@ -1225,7 +1240,7 @@ class IPC {
|
|
|
1225
1240
|
if (!listener) {
|
|
1226
1241
|
ipcListenerMap.delete(channel);
|
|
1227
1242
|
} else {
|
|
1228
|
-
ipcListenerMap.
|
|
1243
|
+
ipcListenerMap.get(channel).delete(listener);
|
|
1229
1244
|
}
|
|
1230
1245
|
}
|
|
1231
1246
|
}
|
|
@@ -1542,14 +1557,12 @@ const CoreAPI$2 = {
|
|
|
1542
1557
|
if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
1543
1558
|
// process response message
|
|
1544
1559
|
if (_message.id) {
|
|
1545
|
-
doCallback(_message.id, _message.result
|
|
1560
|
+
doCallback(_message.id, _message.result);
|
|
1546
1561
|
return
|
|
1547
1562
|
}
|
|
1548
|
-
let
|
|
1549
|
-
if (
|
|
1550
|
-
|
|
1551
|
-
listener(_message.body.args, _message.context);
|
|
1552
|
-
}
|
|
1563
|
+
let listenerMap = ipcListenerMap.get(_message.body.channel);
|
|
1564
|
+
if (listenerMap) {
|
|
1565
|
+
listenerMap.forEach(listener => listener(_message.body.args, _message.context));
|
|
1553
1566
|
}
|
|
1554
1567
|
} else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
|
|
1555
1568
|
|| 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.
|
|
3
|
+
"version": "3.3.0",
|
|
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",
|