@cutos/core 3.0.1 → 3.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.
- package/dist/cutos.cjs.js +22 -24
- package/dist/cutos.esm.js +22 -24
- 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.0.
|
|
401
|
+
var version = "3.0.2";
|
|
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";
|
|
@@ -448,7 +448,8 @@ const mqtt = require$$1;
|
|
|
448
448
|
|
|
449
449
|
const cutosAPI$1 = cutosApi;
|
|
450
450
|
const callbackMap = new Map();
|
|
451
|
-
const callbackInterval =
|
|
451
|
+
const callbackInterval = 500; // 500ms
|
|
452
|
+
const callbackTimeout = 5000; // 5s超时
|
|
452
453
|
const listenerMap = new Map();
|
|
453
454
|
const packageJson = require$$3;
|
|
454
455
|
|
|
@@ -456,6 +457,7 @@ const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|
|
|
|
456
457
|
|
|
457
458
|
let client = null;
|
|
458
459
|
let callbackTimer = null;
|
|
460
|
+
let coreApiInitialized = false;
|
|
459
461
|
|
|
460
462
|
function publishRequest(topic, callback, body, destAddress) {
|
|
461
463
|
let request = {};
|
|
@@ -466,7 +468,7 @@ function publishRequest(topic, callback, body, destAddress) {
|
|
|
466
468
|
if (typeof callback === "function") {
|
|
467
469
|
let callbackItem = {};
|
|
468
470
|
callbackItem.callback = callback;
|
|
469
|
-
callbackItem.
|
|
471
|
+
callbackItem.timestamp = Date.now();
|
|
470
472
|
saveCallback(request.context.id, callbackItem);
|
|
471
473
|
}
|
|
472
474
|
client.publish(topic, JSON.stringify(request));
|
|
@@ -495,13 +497,10 @@ function saveCallback(id, item) {
|
|
|
495
497
|
callbackTimer = setInterval(() => {
|
|
496
498
|
let currentTimestamp = new Date().getTime();
|
|
497
499
|
callbackMap.forEach((callbackItem, id) => {
|
|
498
|
-
if (currentTimestamp - callbackItem.timestamp >
|
|
500
|
+
if (currentTimestamp - callbackItem.timestamp > callbackTimeout) {
|
|
499
501
|
callbackItem.callback({
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
result: "failure",
|
|
503
|
-
reason: "callback is timeout!"
|
|
504
|
-
}
|
|
502
|
+
status: false,
|
|
503
|
+
msg: "callback is timeout!"
|
|
505
504
|
});
|
|
506
505
|
callbackMap.delete(id);
|
|
507
506
|
}
|
|
@@ -859,7 +858,7 @@ class Device {
|
|
|
859
858
|
}
|
|
860
859
|
|
|
861
860
|
onData(listener) {
|
|
862
|
-
if(!listenerMap.has(this.topicData)) {
|
|
861
|
+
if (!listenerMap.has(this.topicData)) {
|
|
863
862
|
client.subscribe(this.topicData); // receive data from device
|
|
864
863
|
}
|
|
865
864
|
let _this = this;
|
|
@@ -939,6 +938,9 @@ const CoreAPI$2 = {
|
|
|
939
938
|
if (!host) {
|
|
940
939
|
host = 'ws://localhost:1883';
|
|
941
940
|
}
|
|
941
|
+
if (callback && typeof (callback) !== 'function') {
|
|
942
|
+
throw new Error("callback must be a function");
|
|
943
|
+
}
|
|
942
944
|
client = mqtt.connect(host);
|
|
943
945
|
|
|
944
946
|
client.on('connect', function () {
|
|
@@ -952,12 +954,9 @@ const CoreAPI$2 = {
|
|
|
952
954
|
for (let api in cutosAPI$1.CORE_APP) {
|
|
953
955
|
client.subscribe(cutosAPI$1.CORE_APP[api]);
|
|
954
956
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
msg: 'CUTOS CORE connected.'
|
|
959
|
-
});
|
|
960
|
-
}
|
|
957
|
+
|
|
958
|
+
!coreApiInitialized && callback && callback({status: true, msg: 'CUTOS CORE connected.'});
|
|
959
|
+
coreApiInitialized = true;
|
|
961
960
|
});
|
|
962
961
|
|
|
963
962
|
client.on('message', function (topic, message, context) {
|
|
@@ -984,14 +983,13 @@ const CoreAPI$2 = {
|
|
|
984
983
|
console.log("CUTOS CORE closed.");
|
|
985
984
|
});
|
|
986
985
|
|
|
987
|
-
client.on("error", (
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
console.error("CUTOS CORE error: ", e.message);
|
|
986
|
+
client.on("error", (err) => {
|
|
987
|
+
callback && callback({status: false, msg: err.message});
|
|
988
|
+
console.error("CUTOS CORE error:", err.message);
|
|
989
|
+
});
|
|
990
|
+
client.stream.on("error", (err) => {
|
|
991
|
+
callback && callback({status: false, msg: err.message});
|
|
992
|
+
console.error("CUTOS CORE error:", err.message);
|
|
995
993
|
});
|
|
996
994
|
},
|
|
997
995
|
connected() {
|
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.0.
|
|
693
|
+
var version = "3.0.2";
|
|
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";
|
|
@@ -740,7 +740,8 @@ const mqtt = require$$1;
|
|
|
740
740
|
|
|
741
741
|
const cutosAPI$1 = cutosApi;
|
|
742
742
|
const callbackMap = new Map();
|
|
743
|
-
const callbackInterval =
|
|
743
|
+
const callbackInterval = 500; // 500ms
|
|
744
|
+
const callbackTimeout = 5000; // 5s超时
|
|
744
745
|
const listenerMap = new Map();
|
|
745
746
|
const packageJson = require$$3;
|
|
746
747
|
|
|
@@ -748,6 +749,7 @@ const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|
|
|
|
748
749
|
|
|
749
750
|
let client = null;
|
|
750
751
|
let callbackTimer = null;
|
|
752
|
+
let coreApiInitialized = false;
|
|
751
753
|
|
|
752
754
|
function publishRequest(topic, callback, body, destAddress) {
|
|
753
755
|
let request = {};
|
|
@@ -758,7 +760,7 @@ function publishRequest(topic, callback, body, destAddress) {
|
|
|
758
760
|
if (typeof callback === "function") {
|
|
759
761
|
let callbackItem = {};
|
|
760
762
|
callbackItem.callback = callback;
|
|
761
|
-
callbackItem.
|
|
763
|
+
callbackItem.timestamp = Date.now();
|
|
762
764
|
saveCallback(request.context.id, callbackItem);
|
|
763
765
|
}
|
|
764
766
|
client.publish(topic, JSON.stringify(request));
|
|
@@ -787,13 +789,10 @@ function saveCallback(id, item) {
|
|
|
787
789
|
callbackTimer = setInterval(() => {
|
|
788
790
|
let currentTimestamp = new Date().getTime();
|
|
789
791
|
callbackMap.forEach((callbackItem, id) => {
|
|
790
|
-
if (currentTimestamp - callbackItem.timestamp >
|
|
792
|
+
if (currentTimestamp - callbackItem.timestamp > callbackTimeout) {
|
|
791
793
|
callbackItem.callback({
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
result: "failure",
|
|
795
|
-
reason: "callback is timeout!"
|
|
796
|
-
}
|
|
794
|
+
status: false,
|
|
795
|
+
msg: "callback is timeout!"
|
|
797
796
|
});
|
|
798
797
|
callbackMap.delete(id);
|
|
799
798
|
}
|
|
@@ -1151,7 +1150,7 @@ class Device {
|
|
|
1151
1150
|
}
|
|
1152
1151
|
|
|
1153
1152
|
onData(listener) {
|
|
1154
|
-
if(!listenerMap.has(this.topicData)) {
|
|
1153
|
+
if (!listenerMap.has(this.topicData)) {
|
|
1155
1154
|
client.subscribe(this.topicData); // receive data from device
|
|
1156
1155
|
}
|
|
1157
1156
|
let _this = this;
|
|
@@ -1231,6 +1230,9 @@ const CoreAPI$2 = {
|
|
|
1231
1230
|
if (!host) {
|
|
1232
1231
|
host = 'ws://localhost:1883';
|
|
1233
1232
|
}
|
|
1233
|
+
if (callback && typeof (callback) !== 'function') {
|
|
1234
|
+
throw new Error("callback must be a function");
|
|
1235
|
+
}
|
|
1234
1236
|
client = mqtt.connect(host);
|
|
1235
1237
|
|
|
1236
1238
|
client.on('connect', function () {
|
|
@@ -1244,12 +1246,9 @@ const CoreAPI$2 = {
|
|
|
1244
1246
|
for (let api in cutosAPI$1.CORE_APP) {
|
|
1245
1247
|
client.subscribe(cutosAPI$1.CORE_APP[api]);
|
|
1246
1248
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
msg: 'CUTOS CORE connected.'
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1249
|
+
|
|
1250
|
+
!coreApiInitialized && callback && callback({status: true, msg: 'CUTOS CORE connected.'});
|
|
1251
|
+
coreApiInitialized = true;
|
|
1253
1252
|
});
|
|
1254
1253
|
|
|
1255
1254
|
client.on('message', function (topic, message, context) {
|
|
@@ -1276,14 +1275,13 @@ const CoreAPI$2 = {
|
|
|
1276
1275
|
console.log("CUTOS CORE closed.");
|
|
1277
1276
|
});
|
|
1278
1277
|
|
|
1279
|
-
client.on("error", (
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
console.error("CUTOS CORE error: ", e.message);
|
|
1278
|
+
client.on("error", (err) => {
|
|
1279
|
+
callback && callback({status: false, msg: err.message});
|
|
1280
|
+
console.error("CUTOS CORE error:", err.message);
|
|
1281
|
+
});
|
|
1282
|
+
client.stream.on("error", (err) => {
|
|
1283
|
+
callback && callback({status: false, msg: err.message});
|
|
1284
|
+
console.error("CUTOS CORE error:", err.message);
|
|
1287
1285
|
});
|
|
1288
1286
|
},
|
|
1289
1287
|
connected() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|