@cutos/core 0.0.20 → 0.0.21
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 +1 -1
- package/dist/cutos.cjs.js +118 -78
- package/dist/cutos.esm.js +118 -74
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cutos.cjs.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var require$$1 = require('mqtt');
|
|
7
7
|
|
|
8
|
+
function getDefaultExportFromCjs (x) {
|
|
9
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
function getAugmentedNamespace(n) {
|
|
9
13
|
if (n.__esModule) return n;
|
|
10
14
|
var f = n.default;
|
|
@@ -389,13 +393,13 @@ const HEARTBEAT_STATUS = Object.freeze({
|
|
|
389
393
|
REGISTER: "register", ALIVE: "alive", ERROR: 'error', NOT_FOUND: 'not-found', SUCCESS: 'success'
|
|
390
394
|
});
|
|
391
395
|
|
|
392
|
-
const cutosAPI$
|
|
396
|
+
const cutosAPI$2 = {
|
|
393
397
|
version: '2.0.1', CORE, CORE_NORESP, CORE_APP, DEVICE, HEARTBEAT_STATUS
|
|
394
398
|
};
|
|
395
|
-
var cutosApi = cutosAPI$
|
|
399
|
+
var cutosApi = cutosAPI$2;
|
|
396
400
|
|
|
397
401
|
var name = "@cutos/core";
|
|
398
|
-
var version = "0.0.
|
|
402
|
+
var version = "0.0.21";
|
|
399
403
|
var description = "";
|
|
400
404
|
var main = "dist/cutos.cjs.js";
|
|
401
405
|
var module$1 = "dist/cutos.esm.js";
|
|
@@ -443,7 +447,7 @@ var require$$3 = {
|
|
|
443
447
|
const {v4: uuidv4} = require$$0;
|
|
444
448
|
const mqtt = require$$1;
|
|
445
449
|
|
|
446
|
-
const cutosAPI = cutosApi;
|
|
450
|
+
const cutosAPI$1 = cutosApi;
|
|
447
451
|
const callbackMap = new Map();
|
|
448
452
|
const callbackInterval = 5000; // 5s超时
|
|
449
453
|
const listenerMap = new Map();
|
|
@@ -545,91 +549,91 @@ class Database {
|
|
|
545
549
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
546
550
|
|
|
547
551
|
}
|
|
548
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
552
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
549
553
|
}
|
|
550
554
|
|
|
551
555
|
insert(value, callback, tid) {
|
|
552
556
|
let body = {
|
|
553
557
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
554
558
|
};
|
|
555
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
559
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
556
560
|
}
|
|
557
561
|
|
|
558
562
|
insertById(id, value, callback, tid) {
|
|
559
563
|
let body = {
|
|
560
564
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
561
565
|
};
|
|
562
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
566
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
563
567
|
}
|
|
564
568
|
|
|
565
569
|
insertByKey(key, value, callback, tid) {
|
|
566
570
|
let body = {
|
|
567
571
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
568
572
|
};
|
|
569
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
573
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
570
574
|
}
|
|
571
575
|
|
|
572
576
|
update(id, value, callback) {
|
|
573
577
|
let body = {
|
|
574
578
|
db: this.db, cmd: "db.table.update", name: this.name, id: id, value: value
|
|
575
579
|
};
|
|
576
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
580
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
577
581
|
}
|
|
578
582
|
|
|
579
583
|
updateByKey(key, value, callback) {
|
|
580
584
|
let body = {
|
|
581
585
|
db: this.db, cmd: "db.table.updateByKey", name: this.name, key: key, value: value
|
|
582
586
|
};
|
|
583
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
587
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
584
588
|
}
|
|
585
589
|
|
|
586
590
|
delete(id, callback) {
|
|
587
591
|
let body = {
|
|
588
592
|
db: this.db, cmd: "db.table.delete", name: this.name, id: id
|
|
589
593
|
};
|
|
590
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
594
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
591
595
|
}
|
|
592
596
|
|
|
593
597
|
query(id, callback, count = 100) {
|
|
594
598
|
let body = {
|
|
595
599
|
db: this.db, cmd: "db.table.query", name: this.name, id: id
|
|
596
600
|
};
|
|
597
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
601
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
598
602
|
}
|
|
599
603
|
|
|
600
604
|
queryByKey(key, callback, count = 100) {
|
|
601
605
|
let body = {
|
|
602
606
|
db: this.db, cmd: "db.table.queryByKey", name: this.name, key: key
|
|
603
607
|
};
|
|
604
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
608
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
605
609
|
}
|
|
606
610
|
|
|
607
611
|
queryByTid(tid, callback, limit = 100) {
|
|
608
612
|
let body = {
|
|
609
613
|
db: this.db, cmd: "db.table.queryByTid", name: this.name, limit: limit, tid: tid
|
|
610
614
|
};
|
|
611
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
615
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
612
616
|
}
|
|
613
617
|
|
|
614
618
|
queryUnsynced(callback, limit = 100) {
|
|
615
619
|
let body = {
|
|
616
620
|
db: this.db, cmd: "db.table.queryUnsynced", name: this.name, limit: limit
|
|
617
621
|
};
|
|
618
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
622
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
619
623
|
}
|
|
620
624
|
|
|
621
625
|
queryAll(callback) {
|
|
622
626
|
let body = {
|
|
623
627
|
db: this.db, cmd: "db.table.queryAll", name: this.name
|
|
624
628
|
};
|
|
625
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
629
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
626
630
|
}
|
|
627
631
|
|
|
628
632
|
sync(id, callback) {
|
|
629
633
|
let body = {
|
|
630
634
|
db: this.db, cmd: "db.table.sync", name: this.name, id: id
|
|
631
635
|
};
|
|
632
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
636
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
633
637
|
}
|
|
634
638
|
|
|
635
639
|
publishRequestMirror(topic, callback, body) {
|
|
@@ -667,14 +671,14 @@ class Database {
|
|
|
667
671
|
let body = {
|
|
668
672
|
cmd: "db.connect", db: this.db
|
|
669
673
|
};
|
|
670
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
674
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
671
675
|
}
|
|
672
676
|
|
|
673
677
|
run(sql, callback) {
|
|
674
678
|
let body = {
|
|
675
679
|
db: this.db, cmd: "db.run", sql: sql
|
|
676
680
|
};
|
|
677
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
681
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
678
682
|
}
|
|
679
683
|
|
|
680
684
|
createTable(name, callback, retentionTime, keyType = 'INTEGER', keyName = 'id') {
|
|
@@ -694,28 +698,28 @@ class Logger {
|
|
|
694
698
|
let body = {
|
|
695
699
|
type: type, level: "info", remark: remark, content: content
|
|
696
700
|
};
|
|
697
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
701
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
698
702
|
}
|
|
699
703
|
|
|
700
704
|
warning(remark, content, type = "LWA") {
|
|
701
705
|
let body = {
|
|
702
706
|
type: type, level: "warning", remark: remark, content: content
|
|
703
707
|
};
|
|
704
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
708
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
705
709
|
}
|
|
706
710
|
|
|
707
711
|
error(remark, content, type = "LWA") {
|
|
708
712
|
let body = {
|
|
709
713
|
type: type, level: "error", remark: remark, content: content
|
|
710
714
|
};
|
|
711
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
715
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
712
716
|
}
|
|
713
717
|
|
|
714
718
|
debug(remark, content, type = "LWA") {
|
|
715
719
|
let body = {
|
|
716
720
|
type: type, level: "debug", remark: remark, content: content
|
|
717
721
|
};
|
|
718
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
722
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
719
723
|
}
|
|
720
724
|
}
|
|
721
725
|
|
|
@@ -734,7 +738,7 @@ class IPC {
|
|
|
734
738
|
let body = {};
|
|
735
739
|
body.channel = channel;
|
|
736
740
|
body.args = args;
|
|
737
|
-
return publishRequest(cutosAPI.CORE_NORESP.IPC, null, body, this.destAddress);
|
|
741
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.IPC, null, body, this.destAddress);
|
|
738
742
|
}
|
|
739
743
|
|
|
740
744
|
on(channel, listener) {
|
|
@@ -751,28 +755,28 @@ class Notification {
|
|
|
751
755
|
}
|
|
752
756
|
|
|
753
757
|
register(listener) {
|
|
754
|
-
listenerMap.set(cutosAPI.CORE_APP.NOTIFICATION, listener);
|
|
758
|
+
listenerMap.set(cutosAPI$1.CORE_APP.NOTIFICATION, listener);
|
|
755
759
|
}
|
|
756
760
|
|
|
757
761
|
unregister() {
|
|
758
|
-
listenerMap.delete(cutosAPI.CORE_APP.NOTIFICATION);
|
|
762
|
+
listenerMap.delete(cutosAPI$1.CORE_APP.NOTIFICATION);
|
|
759
763
|
}
|
|
760
764
|
|
|
761
765
|
emit(event, msg) {
|
|
762
|
-
client.publish(cutosAPI.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
|
|
766
|
+
client.publish(cutosAPI$1.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
|
|
763
767
|
return true;
|
|
764
768
|
}
|
|
765
769
|
}
|
|
766
770
|
|
|
767
771
|
class Heartbeat {
|
|
768
|
-
STATUS = cutosAPI.HEARTBEAT_STATUS;
|
|
772
|
+
STATUS = cutosAPI$1.HEARTBEAT_STATUS;
|
|
769
773
|
|
|
770
774
|
constructor(pinger, counter) {
|
|
771
775
|
this.registered = false;
|
|
772
776
|
this.request = {};
|
|
773
777
|
this.request.counter = counter;
|
|
774
778
|
this.request.pinger = pinger;
|
|
775
|
-
this.request.subscriber = cutosAPI.CORE_NORESP.HEARTBEAT_PING + '-' + pinger;
|
|
779
|
+
this.request.subscriber = cutosAPI$1.CORE_NORESP.HEARTBEAT_PING + '-' + pinger;
|
|
776
780
|
|
|
777
781
|
}
|
|
778
782
|
|
|
@@ -781,7 +785,7 @@ class Heartbeat {
|
|
|
781
785
|
this.request.msg.status = this.STATUS.REGISTER;
|
|
782
786
|
this.request.msg.info = `Start to monitor ${this.request.pinger}.`;
|
|
783
787
|
|
|
784
|
-
client.publish(cutosAPI.CORE_NORESP.HEARTBEAT_REGISTER, JSON.stringify(this.request));
|
|
788
|
+
client.publish(cutosAPI$1.CORE_NORESP.HEARTBEAT_REGISTER, JSON.stringify(this.request));
|
|
785
789
|
this.registered = true;
|
|
786
790
|
}
|
|
787
791
|
|
|
@@ -792,17 +796,17 @@ class Heartbeat {
|
|
|
792
796
|
this.request.msg = {};
|
|
793
797
|
this.request.msg.status = status;
|
|
794
798
|
this.request.msg.info = info;
|
|
795
|
-
client.publish(cutosAPI.CORE_NORESP.HEARTBEAT_PING, JSON.stringify(this.request));
|
|
799
|
+
client.publish(cutosAPI$1.CORE_NORESP.HEARTBEAT_PING, JSON.stringify(this.request));
|
|
796
800
|
}
|
|
797
801
|
}
|
|
798
802
|
|
|
799
803
|
class Device {
|
|
800
|
-
constructor(name = 'default-device-name', type = cutosAPI.DEVICE.DEFAULT, callback) {
|
|
804
|
+
constructor(name = 'default-device-name', type = cutosAPI$1.DEVICE.DEFAULT, callback, development = false) {
|
|
801
805
|
this.name = name;
|
|
802
806
|
this.type = type;
|
|
803
|
-
this.topicData = cutosAPI.DEVICE.CHANNEL + '-' + type + '-data';
|
|
804
|
-
this.topicResponse = cutosAPI.DEVICE.CHANNEL + '-' + type + '-response';
|
|
805
|
-
this.topicCommand = cutosAPI.DEVICE.CHANNEL + '-' + type + '-command';
|
|
807
|
+
this.topicData = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-data';
|
|
808
|
+
this.topicResponse = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-response';
|
|
809
|
+
this.topicCommand = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-command';
|
|
806
810
|
this.data = {};
|
|
807
811
|
|
|
808
812
|
if (Device.objectMap === undefined) {
|
|
@@ -822,19 +826,19 @@ class Device {
|
|
|
822
826
|
}
|
|
823
827
|
//console.debug(JSON.stringify(msg));
|
|
824
828
|
};
|
|
825
|
-
listenerMap.set(cutosAPI.CORE_APP.HEARTBEAT_LISTENER, Device.heartbeatListener);
|
|
829
|
+
listenerMap.set(cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER, Device.heartbeatListener);
|
|
826
830
|
}
|
|
827
831
|
// subscribe callback
|
|
828
832
|
client.subscribe(this.topicCommand + '-callback');
|
|
829
|
-
this.init(name, type, callback);
|
|
833
|
+
this.init(name, type, callback, development);
|
|
830
834
|
}
|
|
831
835
|
|
|
832
|
-
init(name, type, callback) {
|
|
836
|
+
init(name, type, callback, development) {
|
|
833
837
|
let command = {};
|
|
834
838
|
command.cmd = "init";
|
|
835
|
-
command.args = {name
|
|
839
|
+
command.args = {name, type, development};
|
|
836
840
|
command.topicResponse = this.topicResponse;
|
|
837
|
-
let defaultTopic = cutosAPI.DEVICE.CHANNEL + '-' + cutosAPI.DEVICE.DEFAULT + '-command';
|
|
841
|
+
let defaultTopic = cutosAPI$1.DEVICE.CHANNEL + '-' + cutosAPI$1.DEVICE.DEFAULT + '-command';
|
|
838
842
|
publishRequest(defaultTopic, null, command);
|
|
839
843
|
|
|
840
844
|
// response callback
|
|
@@ -877,15 +881,15 @@ class Device {
|
|
|
877
881
|
}
|
|
878
882
|
|
|
879
883
|
class Driver {
|
|
880
|
-
constructor(name = 'default-driver-name', type = cutosAPI.DEVICE.DEFAULT, counter = 10) {
|
|
884
|
+
constructor(name = 'default-driver-name', type = cutosAPI$1.DEVICE.DEFAULT, counter = 10) {
|
|
881
885
|
this.name = name;
|
|
882
886
|
this.type = type;
|
|
883
887
|
this.heartbeat = new Heartbeat(type, counter);
|
|
884
888
|
this.statusInfo = {};
|
|
885
889
|
this.beatInterval = 3000;
|
|
886
|
-
this.topicData = cutosAPI.DEVICE.CHANNEL + '-' + type + '-data';
|
|
887
|
-
this.topicResponse = cutosAPI.DEVICE.CHANNEL + '-' + type + '-response';
|
|
888
|
-
this.topicCommand = cutosAPI.DEVICE.CHANNEL + '-' + type + '-command';
|
|
890
|
+
this.topicData = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-data';
|
|
891
|
+
this.topicResponse = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-response';
|
|
892
|
+
this.topicCommand = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-command';
|
|
889
893
|
}
|
|
890
894
|
|
|
891
895
|
startBeat() {
|
|
@@ -929,23 +933,23 @@ class Driver {
|
|
|
929
933
|
}
|
|
930
934
|
}
|
|
931
935
|
|
|
932
|
-
const CoreAPI = {
|
|
933
|
-
init(
|
|
934
|
-
if (!
|
|
935
|
-
|
|
936
|
+
const CoreAPI$2 = {
|
|
937
|
+
init(host = 'ws://localhost:1883', callback) {
|
|
938
|
+
if (!host) {
|
|
939
|
+
host = 'ws://localhost:1883';
|
|
936
940
|
}
|
|
937
|
-
client = mqtt.connect(
|
|
941
|
+
client = mqtt.connect(host);
|
|
938
942
|
|
|
939
943
|
client.on('connect', function () {
|
|
940
944
|
console.log("CUTOS CORE connected.");
|
|
941
|
-
for (let api in cutosAPI.CORE) {
|
|
942
|
-
client.subscribe(cutosAPI.CORE[api] + '-callback');
|
|
945
|
+
for (let api in cutosAPI$1.CORE) {
|
|
946
|
+
client.subscribe(cutosAPI$1.CORE[api] + '-callback');
|
|
943
947
|
}
|
|
944
|
-
for (let api in cutosAPI.CORE_NORESP) {
|
|
945
|
-
client.subscribe(cutosAPI.CORE_NORESP[api] + '-endpoint');
|
|
948
|
+
for (let api in cutosAPI$1.CORE_NORESP) {
|
|
949
|
+
client.subscribe(cutosAPI$1.CORE_NORESP[api] + '-endpoint');
|
|
946
950
|
}
|
|
947
|
-
for (let api in cutosAPI.CORE_APP) {
|
|
948
|
-
client.subscribe(cutosAPI.CORE_APP[api]);
|
|
951
|
+
for (let api in cutosAPI$1.CORE_APP) {
|
|
952
|
+
client.subscribe(cutosAPI$1.CORE_APP[api]);
|
|
949
953
|
}
|
|
950
954
|
if (typeof (callback) === 'function') {
|
|
951
955
|
callback({
|
|
@@ -959,13 +963,13 @@ const CoreAPI = {
|
|
|
959
963
|
// message is Buffer
|
|
960
964
|
// console.debug(topic.toString() + message.toString());
|
|
961
965
|
let _message = JSON.parse(message);
|
|
962
|
-
if (topic === cutosAPI.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
966
|
+
if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
963
967
|
let listener = listenerMap.get(_message.body.channel);
|
|
964
968
|
if (listener !== undefined) {
|
|
965
969
|
listener(_message.body.args, _message.context);
|
|
966
970
|
}
|
|
967
|
-
} else if (topic === cutosAPI.CORE_APP.NOTIFICATION || topic === cutosAPI.CORE_APP.HEARTBEAT_LISTENER
|
|
968
|
-
|| topic.startsWith(cutosAPI.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
|
|
971
|
+
} else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
|
|
972
|
+
|| topic.startsWith(cutosAPI$1.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
|
|
969
973
|
let listener = listenerMap.get(topic);
|
|
970
974
|
if (listener !== undefined) {
|
|
971
975
|
listener(_message);
|
|
@@ -990,7 +994,7 @@ const CoreAPI = {
|
|
|
990
994
|
});
|
|
991
995
|
},
|
|
992
996
|
connected() {
|
|
993
|
-
return client.connected;
|
|
997
|
+
return !!client && client.connected;
|
|
994
998
|
},
|
|
995
999
|
|
|
996
1000
|
getVersion() {
|
|
@@ -998,27 +1002,27 @@ const CoreAPI = {
|
|
|
998
1002
|
},
|
|
999
1003
|
|
|
1000
1004
|
getPlatform(callback) {
|
|
1001
|
-
return publishRequest(cutosAPI.CORE.PLATFORM, callback);
|
|
1005
|
+
return publishRequest(cutosAPI$1.CORE.PLATFORM, callback);
|
|
1002
1006
|
},
|
|
1003
1007
|
|
|
1004
1008
|
getConfig(callback) {
|
|
1005
|
-
return publishRequest(cutosAPI.CORE.CONFIG, callback);
|
|
1009
|
+
return publishRequest(cutosAPI$1.CORE.CONFIG, callback);
|
|
1006
1010
|
},
|
|
1007
1011
|
|
|
1008
1012
|
getBoxInfo(callback) {
|
|
1009
|
-
return publishRequest(cutosAPI.CORE.BOX_INFO, callback);
|
|
1013
|
+
return publishRequest(cutosAPI$1.CORE.BOX_INFO, callback);
|
|
1010
1014
|
},
|
|
1011
1015
|
|
|
1012
1016
|
getSignInfo(callback) {
|
|
1013
|
-
return publishRequest(cutosAPI.CORE.SIGN_INFO, callback);
|
|
1017
|
+
return publishRequest(cutosAPI$1.CORE.SIGN_INFO, callback);
|
|
1014
1018
|
},
|
|
1015
1019
|
|
|
1016
1020
|
getDeviceInfo(callback) {
|
|
1017
|
-
return publishRequest(cutosAPI.CORE.DEVICE_INFO, callback);
|
|
1021
|
+
return publishRequest(cutosAPI$1.CORE.DEVICE_INFO, callback);
|
|
1018
1022
|
},
|
|
1019
1023
|
|
|
1020
1024
|
getSignGroupInfo(callback) {
|
|
1021
|
-
return publishRequest(cutosAPI.CORE.SIGN_GROUP_INFO, callback);
|
|
1025
|
+
return publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, callback);
|
|
1022
1026
|
},
|
|
1023
1027
|
|
|
1024
1028
|
getIPC(destAddress) {
|
|
@@ -1034,7 +1038,7 @@ const CoreAPI = {
|
|
|
1034
1038
|
},
|
|
1035
1039
|
|
|
1036
1040
|
shell(command, callback) {
|
|
1037
|
-
return publishRequest(cutosAPI.CORE.SHELL, callback, command);
|
|
1041
|
+
return publishRequest(cutosAPI$1.CORE.SHELL, callback, command);
|
|
1038
1042
|
},
|
|
1039
1043
|
|
|
1040
1044
|
getDatabase(db, callback) {
|
|
@@ -1042,25 +1046,61 @@ const CoreAPI = {
|
|
|
1042
1046
|
},
|
|
1043
1047
|
|
|
1044
1048
|
getVolume(callback) {
|
|
1045
|
-
return publishRequest(cutosAPI.CORE.GET_VOLUME, callback);
|
|
1049
|
+
return publishRequest(cutosAPI$1.CORE.GET_VOLUME, callback);
|
|
1046
1050
|
},
|
|
1047
1051
|
|
|
1048
1052
|
setVolume(vol, callback) {
|
|
1049
|
-
return publishRequest(cutosAPI.CORE.SET_VOLUME, callback, vol);
|
|
1053
|
+
return publishRequest(cutosAPI$1.CORE.SET_VOLUME, callback, vol);
|
|
1050
1054
|
}
|
|
1051
1055
|
};
|
|
1052
1056
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
DEVICE: cutosAPI.DEVICE, HEARTBEAT_STATUS: cutosAPI.HEARTBEAT_STATUS
|
|
1057
|
+
cutos.CoreAPI = CoreAPI$2;
|
|
1058
|
+
cutos.CoreDefine = {
|
|
1059
|
+
DEVICE: cutosAPI$1.DEVICE, HEARTBEAT_STATUS: cutosAPI$1.HEARTBEAT_STATUS
|
|
1056
1060
|
};
|
|
1057
|
-
|
|
1061
|
+
cutos.CoreClass = {
|
|
1058
1062
|
Device, Driver
|
|
1059
1063
|
};
|
|
1060
|
-
var cutosAPI_1 = cutos.cutosAPI = cutosAPI;
|
|
1061
1064
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1065
|
+
cutos.cutosAPI = cutosAPI$1;
|
|
1066
|
+
|
|
1067
|
+
// simulate cutos core for development
|
|
1068
|
+
const {CoreAPI: CoreAPI$1, CoreClass: CoreClass$1} = cutos;
|
|
1069
|
+
|
|
1070
|
+
const CoreSimulator$1 = {
|
|
1071
|
+
start: function (driver, port = 1883) {
|
|
1072
|
+
CoreAPI$1.init(`ws://localhost:${port}`, result => {
|
|
1073
|
+
console.log('CUTOS Simulator started and listening on port ', port);
|
|
1074
|
+
|
|
1075
|
+
let drvDefault = new CoreClass$1.Driver();
|
|
1076
|
+
drvDefault.onCommand((command) => {
|
|
1077
|
+
console.log('drvDefault onCommand', JSON.stringify(command));
|
|
1078
|
+
if (command.cmd === "init") {
|
|
1079
|
+
let rsp = {result: true};
|
|
1080
|
+
try {
|
|
1081
|
+
driver.init(command.args);
|
|
1082
|
+
} catch (e) {
|
|
1083
|
+
rsp.msg = e.message;
|
|
1084
|
+
rsp.result = false;
|
|
1085
|
+
}
|
|
1086
|
+
drvDefault.sendResponse(rsp, command.topicResponse);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
var coreSimulator = {CoreSimulator: CoreSimulator$1};
|
|
1094
|
+
|
|
1095
|
+
const {CoreAPI, CoreDefine, CoreClass, cutosAPI} = cutos;
|
|
1096
|
+
const {CoreSimulator} = coreSimulator;
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
var src = {
|
|
1100
|
+
CoreAPI, CoreDefine, CoreClass, cutosAPI,
|
|
1101
|
+
CoreSimulator
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(src);
|
|
1105
|
+
|
|
1106
|
+
exports.default = index;
|
package/dist/cutos.esm.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import require$$1 from 'mqtt';
|
|
2
2
|
|
|
3
|
+
function getDefaultExportFromCjs (x) {
|
|
4
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
function getAugmentedNamespace(n) {
|
|
4
8
|
if (n.__esModule) return n;
|
|
5
9
|
var f = n.default;
|
|
@@ -681,13 +685,13 @@ const HEARTBEAT_STATUS = Object.freeze({
|
|
|
681
685
|
REGISTER: "register", ALIVE: "alive", ERROR: 'error', NOT_FOUND: 'not-found', SUCCESS: 'success'
|
|
682
686
|
});
|
|
683
687
|
|
|
684
|
-
const cutosAPI$
|
|
688
|
+
const cutosAPI$2 = {
|
|
685
689
|
version: '2.0.1', CORE, CORE_NORESP, CORE_APP, DEVICE, HEARTBEAT_STATUS
|
|
686
690
|
};
|
|
687
|
-
var cutosApi = cutosAPI$
|
|
691
|
+
var cutosApi = cutosAPI$2;
|
|
688
692
|
|
|
689
693
|
var name = "@cutos/core";
|
|
690
|
-
var version = "0.0.
|
|
694
|
+
var version = "0.0.21";
|
|
691
695
|
var description = "";
|
|
692
696
|
var main = "dist/cutos.cjs.js";
|
|
693
697
|
var module = "dist/cutos.esm.js";
|
|
@@ -735,7 +739,7 @@ var require$$3 = {
|
|
|
735
739
|
const {v4: uuidv4} = require$$0;
|
|
736
740
|
const mqtt = require$$1;
|
|
737
741
|
|
|
738
|
-
const cutosAPI = cutosApi;
|
|
742
|
+
const cutosAPI$1 = cutosApi;
|
|
739
743
|
const callbackMap = new Map();
|
|
740
744
|
const callbackInterval = 5000; // 5s超时
|
|
741
745
|
const listenerMap = new Map();
|
|
@@ -837,91 +841,91 @@ class Database {
|
|
|
837
841
|
throw new Error("keyType MUST be INTEGER or TEXT");
|
|
838
842
|
|
|
839
843
|
}
|
|
840
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
844
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
841
845
|
}
|
|
842
846
|
|
|
843
847
|
insert(value, callback, tid) {
|
|
844
848
|
let body = {
|
|
845
849
|
db: this.db, cmd: "db.table.insert", name: this.name, value: value, tid: tid
|
|
846
850
|
};
|
|
847
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
851
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
848
852
|
}
|
|
849
853
|
|
|
850
854
|
insertById(id, value, callback, tid) {
|
|
851
855
|
let body = {
|
|
852
856
|
db: this.db, cmd: "db.table.insertById", name: this.name, id: id, value: value, tid: tid
|
|
853
857
|
};
|
|
854
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
858
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
855
859
|
}
|
|
856
860
|
|
|
857
861
|
insertByKey(key, value, callback, tid) {
|
|
858
862
|
let body = {
|
|
859
863
|
db: this.db, cmd: "db.table.insertByKey", name: this.name, key: key, value: value, tid: tid
|
|
860
864
|
};
|
|
861
|
-
return this.publishRequestMirror(cutosAPI.CORE.DATABASE, callback, body);
|
|
865
|
+
return this.publishRequestMirror(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
862
866
|
}
|
|
863
867
|
|
|
864
868
|
update(id, value, callback) {
|
|
865
869
|
let body = {
|
|
866
870
|
db: this.db, cmd: "db.table.update", name: this.name, id: id, value: value
|
|
867
871
|
};
|
|
868
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
872
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
869
873
|
}
|
|
870
874
|
|
|
871
875
|
updateByKey(key, value, callback) {
|
|
872
876
|
let body = {
|
|
873
877
|
db: this.db, cmd: "db.table.updateByKey", name: this.name, key: key, value: value
|
|
874
878
|
};
|
|
875
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
879
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
876
880
|
}
|
|
877
881
|
|
|
878
882
|
delete(id, callback) {
|
|
879
883
|
let body = {
|
|
880
884
|
db: this.db, cmd: "db.table.delete", name: this.name, id: id
|
|
881
885
|
};
|
|
882
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
886
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
883
887
|
}
|
|
884
888
|
|
|
885
889
|
query(id, callback, count = 100) {
|
|
886
890
|
let body = {
|
|
887
891
|
db: this.db, cmd: "db.table.query", name: this.name, id: id
|
|
888
892
|
};
|
|
889
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
893
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
890
894
|
}
|
|
891
895
|
|
|
892
896
|
queryByKey(key, callback, count = 100) {
|
|
893
897
|
let body = {
|
|
894
898
|
db: this.db, cmd: "db.table.queryByKey", name: this.name, key: key
|
|
895
899
|
};
|
|
896
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
900
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
897
901
|
}
|
|
898
902
|
|
|
899
903
|
queryByTid(tid, callback, limit = 100) {
|
|
900
904
|
let body = {
|
|
901
905
|
db: this.db, cmd: "db.table.queryByTid", name: this.name, limit: limit, tid: tid
|
|
902
906
|
};
|
|
903
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
907
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
904
908
|
}
|
|
905
909
|
|
|
906
910
|
queryUnsynced(callback, limit = 100) {
|
|
907
911
|
let body = {
|
|
908
912
|
db: this.db, cmd: "db.table.queryUnsynced", name: this.name, limit: limit
|
|
909
913
|
};
|
|
910
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
914
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
911
915
|
}
|
|
912
916
|
|
|
913
917
|
queryAll(callback) {
|
|
914
918
|
let body = {
|
|
915
919
|
db: this.db, cmd: "db.table.queryAll", name: this.name
|
|
916
920
|
};
|
|
917
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
921
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
918
922
|
}
|
|
919
923
|
|
|
920
924
|
sync(id, callback) {
|
|
921
925
|
let body = {
|
|
922
926
|
db: this.db, cmd: "db.table.sync", name: this.name, id: id
|
|
923
927
|
};
|
|
924
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
928
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
925
929
|
}
|
|
926
930
|
|
|
927
931
|
publishRequestMirror(topic, callback, body) {
|
|
@@ -959,14 +963,14 @@ class Database {
|
|
|
959
963
|
let body = {
|
|
960
964
|
cmd: "db.connect", db: this.db
|
|
961
965
|
};
|
|
962
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
966
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
963
967
|
}
|
|
964
968
|
|
|
965
969
|
run(sql, callback) {
|
|
966
970
|
let body = {
|
|
967
971
|
db: this.db, cmd: "db.run", sql: sql
|
|
968
972
|
};
|
|
969
|
-
return publishRequest(cutosAPI.CORE.DATABASE, callback, body);
|
|
973
|
+
return publishRequest(cutosAPI$1.CORE.DATABASE, callback, body);
|
|
970
974
|
}
|
|
971
975
|
|
|
972
976
|
createTable(name, callback, retentionTime, keyType = 'INTEGER', keyName = 'id') {
|
|
@@ -986,28 +990,28 @@ class Logger {
|
|
|
986
990
|
let body = {
|
|
987
991
|
type: type, level: "info", remark: remark, content: content
|
|
988
992
|
};
|
|
989
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
993
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
990
994
|
}
|
|
991
995
|
|
|
992
996
|
warning(remark, content, type = "LWA") {
|
|
993
997
|
let body = {
|
|
994
998
|
type: type, level: "warning", remark: remark, content: content
|
|
995
999
|
};
|
|
996
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
1000
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
997
1001
|
}
|
|
998
1002
|
|
|
999
1003
|
error(remark, content, type = "LWA") {
|
|
1000
1004
|
let body = {
|
|
1001
1005
|
type: type, level: "error", remark: remark, content: content
|
|
1002
1006
|
};
|
|
1003
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
1007
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
1004
1008
|
}
|
|
1005
1009
|
|
|
1006
1010
|
debug(remark, content, type = "LWA") {
|
|
1007
1011
|
let body = {
|
|
1008
1012
|
type: type, level: "debug", remark: remark, content: content
|
|
1009
1013
|
};
|
|
1010
|
-
return publishRequest(cutosAPI.CORE_NORESP.LOGGER, null, body);
|
|
1014
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.LOGGER, null, body);
|
|
1011
1015
|
}
|
|
1012
1016
|
}
|
|
1013
1017
|
|
|
@@ -1026,7 +1030,7 @@ class IPC {
|
|
|
1026
1030
|
let body = {};
|
|
1027
1031
|
body.channel = channel;
|
|
1028
1032
|
body.args = args;
|
|
1029
|
-
return publishRequest(cutosAPI.CORE_NORESP.IPC, null, body, this.destAddress);
|
|
1033
|
+
return publishRequest(cutosAPI$1.CORE_NORESP.IPC, null, body, this.destAddress);
|
|
1030
1034
|
}
|
|
1031
1035
|
|
|
1032
1036
|
on(channel, listener) {
|
|
@@ -1043,28 +1047,28 @@ class Notification {
|
|
|
1043
1047
|
}
|
|
1044
1048
|
|
|
1045
1049
|
register(listener) {
|
|
1046
|
-
listenerMap.set(cutosAPI.CORE_APP.NOTIFICATION, listener);
|
|
1050
|
+
listenerMap.set(cutosAPI$1.CORE_APP.NOTIFICATION, listener);
|
|
1047
1051
|
}
|
|
1048
1052
|
|
|
1049
1053
|
unregister() {
|
|
1050
|
-
listenerMap.delete(cutosAPI.CORE_APP.NOTIFICATION);
|
|
1054
|
+
listenerMap.delete(cutosAPI$1.CORE_APP.NOTIFICATION);
|
|
1051
1055
|
}
|
|
1052
1056
|
|
|
1053
1057
|
emit(event, msg) {
|
|
1054
|
-
client.publish(cutosAPI.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
|
|
1058
|
+
client.publish(cutosAPI$1.CORE_APP.NOTIFICATION, JSON.stringify({event: event, msg: msg}));
|
|
1055
1059
|
return true;
|
|
1056
1060
|
}
|
|
1057
1061
|
}
|
|
1058
1062
|
|
|
1059
1063
|
class Heartbeat {
|
|
1060
|
-
STATUS = cutosAPI.HEARTBEAT_STATUS;
|
|
1064
|
+
STATUS = cutosAPI$1.HEARTBEAT_STATUS;
|
|
1061
1065
|
|
|
1062
1066
|
constructor(pinger, counter) {
|
|
1063
1067
|
this.registered = false;
|
|
1064
1068
|
this.request = {};
|
|
1065
1069
|
this.request.counter = counter;
|
|
1066
1070
|
this.request.pinger = pinger;
|
|
1067
|
-
this.request.subscriber = cutosAPI.CORE_NORESP.HEARTBEAT_PING + '-' + pinger;
|
|
1071
|
+
this.request.subscriber = cutosAPI$1.CORE_NORESP.HEARTBEAT_PING + '-' + pinger;
|
|
1068
1072
|
|
|
1069
1073
|
}
|
|
1070
1074
|
|
|
@@ -1073,7 +1077,7 @@ class Heartbeat {
|
|
|
1073
1077
|
this.request.msg.status = this.STATUS.REGISTER;
|
|
1074
1078
|
this.request.msg.info = `Start to monitor ${this.request.pinger}.`;
|
|
1075
1079
|
|
|
1076
|
-
client.publish(cutosAPI.CORE_NORESP.HEARTBEAT_REGISTER, JSON.stringify(this.request));
|
|
1080
|
+
client.publish(cutosAPI$1.CORE_NORESP.HEARTBEAT_REGISTER, JSON.stringify(this.request));
|
|
1077
1081
|
this.registered = true;
|
|
1078
1082
|
}
|
|
1079
1083
|
|
|
@@ -1084,17 +1088,17 @@ class Heartbeat {
|
|
|
1084
1088
|
this.request.msg = {};
|
|
1085
1089
|
this.request.msg.status = status;
|
|
1086
1090
|
this.request.msg.info = info;
|
|
1087
|
-
client.publish(cutosAPI.CORE_NORESP.HEARTBEAT_PING, JSON.stringify(this.request));
|
|
1091
|
+
client.publish(cutosAPI$1.CORE_NORESP.HEARTBEAT_PING, JSON.stringify(this.request));
|
|
1088
1092
|
}
|
|
1089
1093
|
}
|
|
1090
1094
|
|
|
1091
1095
|
class Device {
|
|
1092
|
-
constructor(name = 'default-device-name', type = cutosAPI.DEVICE.DEFAULT, callback) {
|
|
1096
|
+
constructor(name = 'default-device-name', type = cutosAPI$1.DEVICE.DEFAULT, callback, development = false) {
|
|
1093
1097
|
this.name = name;
|
|
1094
1098
|
this.type = type;
|
|
1095
|
-
this.topicData = cutosAPI.DEVICE.CHANNEL + '-' + type + '-data';
|
|
1096
|
-
this.topicResponse = cutosAPI.DEVICE.CHANNEL + '-' + type + '-response';
|
|
1097
|
-
this.topicCommand = cutosAPI.DEVICE.CHANNEL + '-' + type + '-command';
|
|
1099
|
+
this.topicData = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-data';
|
|
1100
|
+
this.topicResponse = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-response';
|
|
1101
|
+
this.topicCommand = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-command';
|
|
1098
1102
|
this.data = {};
|
|
1099
1103
|
|
|
1100
1104
|
if (Device.objectMap === undefined) {
|
|
@@ -1114,19 +1118,19 @@ class Device {
|
|
|
1114
1118
|
}
|
|
1115
1119
|
//console.debug(JSON.stringify(msg));
|
|
1116
1120
|
};
|
|
1117
|
-
listenerMap.set(cutosAPI.CORE_APP.HEARTBEAT_LISTENER, Device.heartbeatListener);
|
|
1121
|
+
listenerMap.set(cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER, Device.heartbeatListener);
|
|
1118
1122
|
}
|
|
1119
1123
|
// subscribe callback
|
|
1120
1124
|
client.subscribe(this.topicCommand + '-callback');
|
|
1121
|
-
this.init(name, type, callback);
|
|
1125
|
+
this.init(name, type, callback, development);
|
|
1122
1126
|
}
|
|
1123
1127
|
|
|
1124
|
-
init(name, type, callback) {
|
|
1128
|
+
init(name, type, callback, development) {
|
|
1125
1129
|
let command = {};
|
|
1126
1130
|
command.cmd = "init";
|
|
1127
|
-
command.args = {name
|
|
1131
|
+
command.args = {name, type, development};
|
|
1128
1132
|
command.topicResponse = this.topicResponse;
|
|
1129
|
-
let defaultTopic = cutosAPI.DEVICE.CHANNEL + '-' + cutosAPI.DEVICE.DEFAULT + '-command';
|
|
1133
|
+
let defaultTopic = cutosAPI$1.DEVICE.CHANNEL + '-' + cutosAPI$1.DEVICE.DEFAULT + '-command';
|
|
1130
1134
|
publishRequest(defaultTopic, null, command);
|
|
1131
1135
|
|
|
1132
1136
|
// response callback
|
|
@@ -1169,15 +1173,15 @@ class Device {
|
|
|
1169
1173
|
}
|
|
1170
1174
|
|
|
1171
1175
|
class Driver {
|
|
1172
|
-
constructor(name = 'default-driver-name', type = cutosAPI.DEVICE.DEFAULT, counter = 10) {
|
|
1176
|
+
constructor(name = 'default-driver-name', type = cutosAPI$1.DEVICE.DEFAULT, counter = 10) {
|
|
1173
1177
|
this.name = name;
|
|
1174
1178
|
this.type = type;
|
|
1175
1179
|
this.heartbeat = new Heartbeat(type, counter);
|
|
1176
1180
|
this.statusInfo = {};
|
|
1177
1181
|
this.beatInterval = 3000;
|
|
1178
|
-
this.topicData = cutosAPI.DEVICE.CHANNEL + '-' + type + '-data';
|
|
1179
|
-
this.topicResponse = cutosAPI.DEVICE.CHANNEL + '-' + type + '-response';
|
|
1180
|
-
this.topicCommand = cutosAPI.DEVICE.CHANNEL + '-' + type + '-command';
|
|
1182
|
+
this.topicData = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-data';
|
|
1183
|
+
this.topicResponse = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-response';
|
|
1184
|
+
this.topicCommand = cutosAPI$1.DEVICE.CHANNEL + '-' + type + '-command';
|
|
1181
1185
|
}
|
|
1182
1186
|
|
|
1183
1187
|
startBeat() {
|
|
@@ -1221,23 +1225,23 @@ class Driver {
|
|
|
1221
1225
|
}
|
|
1222
1226
|
}
|
|
1223
1227
|
|
|
1224
|
-
const CoreAPI = {
|
|
1225
|
-
init(
|
|
1226
|
-
if (!
|
|
1227
|
-
|
|
1228
|
+
const CoreAPI$2 = {
|
|
1229
|
+
init(host = 'ws://localhost:1883', callback) {
|
|
1230
|
+
if (!host) {
|
|
1231
|
+
host = 'ws://localhost:1883';
|
|
1228
1232
|
}
|
|
1229
|
-
client = mqtt.connect(
|
|
1233
|
+
client = mqtt.connect(host);
|
|
1230
1234
|
|
|
1231
1235
|
client.on('connect', function () {
|
|
1232
1236
|
console.log("CUTOS CORE connected.");
|
|
1233
|
-
for (let api in cutosAPI.CORE) {
|
|
1234
|
-
client.subscribe(cutosAPI.CORE[api] + '-callback');
|
|
1237
|
+
for (let api in cutosAPI$1.CORE) {
|
|
1238
|
+
client.subscribe(cutosAPI$1.CORE[api] + '-callback');
|
|
1235
1239
|
}
|
|
1236
|
-
for (let api in cutosAPI.CORE_NORESP) {
|
|
1237
|
-
client.subscribe(cutosAPI.CORE_NORESP[api] + '-endpoint');
|
|
1240
|
+
for (let api in cutosAPI$1.CORE_NORESP) {
|
|
1241
|
+
client.subscribe(cutosAPI$1.CORE_NORESP[api] + '-endpoint');
|
|
1238
1242
|
}
|
|
1239
|
-
for (let api in cutosAPI.CORE_APP) {
|
|
1240
|
-
client.subscribe(cutosAPI.CORE_APP[api]);
|
|
1243
|
+
for (let api in cutosAPI$1.CORE_APP) {
|
|
1244
|
+
client.subscribe(cutosAPI$1.CORE_APP[api]);
|
|
1241
1245
|
}
|
|
1242
1246
|
if (typeof (callback) === 'function') {
|
|
1243
1247
|
callback({
|
|
@@ -1251,13 +1255,13 @@ const CoreAPI = {
|
|
|
1251
1255
|
// message is Buffer
|
|
1252
1256
|
// console.debug(topic.toString() + message.toString());
|
|
1253
1257
|
let _message = JSON.parse(message);
|
|
1254
|
-
if (topic === cutosAPI.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
1258
|
+
if (topic === cutosAPI$1.CORE_NORESP.IPC + '-endpoint') { // ipc
|
|
1255
1259
|
let listener = listenerMap.get(_message.body.channel);
|
|
1256
1260
|
if (listener !== undefined) {
|
|
1257
1261
|
listener(_message.body.args, _message.context);
|
|
1258
1262
|
}
|
|
1259
|
-
} else if (topic === cutosAPI.CORE_APP.NOTIFICATION || topic === cutosAPI.CORE_APP.HEARTBEAT_LISTENER
|
|
1260
|
-
|| topic.startsWith(cutosAPI.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
|
|
1263
|
+
} else if (topic === cutosAPI$1.CORE_APP.NOTIFICATION || topic === cutosAPI$1.CORE_APP.HEARTBEAT_LISTENER
|
|
1264
|
+
|| topic.startsWith(cutosAPI$1.DEVICE.CHANNEL) && !topic.endsWith('-callback')) {
|
|
1261
1265
|
let listener = listenerMap.get(topic);
|
|
1262
1266
|
if (listener !== undefined) {
|
|
1263
1267
|
listener(_message);
|
|
@@ -1282,7 +1286,7 @@ const CoreAPI = {
|
|
|
1282
1286
|
});
|
|
1283
1287
|
},
|
|
1284
1288
|
connected() {
|
|
1285
|
-
return client.connected;
|
|
1289
|
+
return !!client && client.connected;
|
|
1286
1290
|
},
|
|
1287
1291
|
|
|
1288
1292
|
getVersion() {
|
|
@@ -1290,27 +1294,27 @@ const CoreAPI = {
|
|
|
1290
1294
|
},
|
|
1291
1295
|
|
|
1292
1296
|
getPlatform(callback) {
|
|
1293
|
-
return publishRequest(cutosAPI.CORE.PLATFORM, callback);
|
|
1297
|
+
return publishRequest(cutosAPI$1.CORE.PLATFORM, callback);
|
|
1294
1298
|
},
|
|
1295
1299
|
|
|
1296
1300
|
getConfig(callback) {
|
|
1297
|
-
return publishRequest(cutosAPI.CORE.CONFIG, callback);
|
|
1301
|
+
return publishRequest(cutosAPI$1.CORE.CONFIG, callback);
|
|
1298
1302
|
},
|
|
1299
1303
|
|
|
1300
1304
|
getBoxInfo(callback) {
|
|
1301
|
-
return publishRequest(cutosAPI.CORE.BOX_INFO, callback);
|
|
1305
|
+
return publishRequest(cutosAPI$1.CORE.BOX_INFO, callback);
|
|
1302
1306
|
},
|
|
1303
1307
|
|
|
1304
1308
|
getSignInfo(callback) {
|
|
1305
|
-
return publishRequest(cutosAPI.CORE.SIGN_INFO, callback);
|
|
1309
|
+
return publishRequest(cutosAPI$1.CORE.SIGN_INFO, callback);
|
|
1306
1310
|
},
|
|
1307
1311
|
|
|
1308
1312
|
getDeviceInfo(callback) {
|
|
1309
|
-
return publishRequest(cutosAPI.CORE.DEVICE_INFO, callback);
|
|
1313
|
+
return publishRequest(cutosAPI$1.CORE.DEVICE_INFO, callback);
|
|
1310
1314
|
},
|
|
1311
1315
|
|
|
1312
1316
|
getSignGroupInfo(callback) {
|
|
1313
|
-
return publishRequest(cutosAPI.CORE.SIGN_GROUP_INFO, callback);
|
|
1317
|
+
return publishRequest(cutosAPI$1.CORE.SIGN_GROUP_INFO, callback);
|
|
1314
1318
|
},
|
|
1315
1319
|
|
|
1316
1320
|
getIPC(destAddress) {
|
|
@@ -1326,7 +1330,7 @@ const CoreAPI = {
|
|
|
1326
1330
|
},
|
|
1327
1331
|
|
|
1328
1332
|
shell(command, callback) {
|
|
1329
|
-
return publishRequest(cutosAPI.CORE.SHELL, callback, command);
|
|
1333
|
+
return publishRequest(cutosAPI$1.CORE.SHELL, callback, command);
|
|
1330
1334
|
},
|
|
1331
1335
|
|
|
1332
1336
|
getDatabase(db, callback) {
|
|
@@ -1334,21 +1338,61 @@ const CoreAPI = {
|
|
|
1334
1338
|
},
|
|
1335
1339
|
|
|
1336
1340
|
getVolume(callback) {
|
|
1337
|
-
return publishRequest(cutosAPI.CORE.GET_VOLUME, callback);
|
|
1341
|
+
return publishRequest(cutosAPI$1.CORE.GET_VOLUME, callback);
|
|
1338
1342
|
},
|
|
1339
1343
|
|
|
1340
1344
|
setVolume(vol, callback) {
|
|
1341
|
-
return publishRequest(cutosAPI.CORE.SET_VOLUME, callback, vol);
|
|
1345
|
+
return publishRequest(cutosAPI$1.CORE.SET_VOLUME, callback, vol);
|
|
1342
1346
|
}
|
|
1343
1347
|
};
|
|
1344
1348
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
DEVICE: cutosAPI.DEVICE, HEARTBEAT_STATUS: cutosAPI.HEARTBEAT_STATUS
|
|
1349
|
+
cutos.CoreAPI = CoreAPI$2;
|
|
1350
|
+
cutos.CoreDefine = {
|
|
1351
|
+
DEVICE: cutosAPI$1.DEVICE, HEARTBEAT_STATUS: cutosAPI$1.HEARTBEAT_STATUS
|
|
1348
1352
|
};
|
|
1349
|
-
|
|
1353
|
+
cutos.CoreClass = {
|
|
1350
1354
|
Device, Driver
|
|
1351
1355
|
};
|
|
1352
|
-
var cutosAPI_1 = cutos.cutosAPI = cutosAPI;
|
|
1353
1356
|
|
|
1354
|
-
|
|
1357
|
+
cutos.cutosAPI = cutosAPI$1;
|
|
1358
|
+
|
|
1359
|
+
// simulate cutos core for development
|
|
1360
|
+
const {CoreAPI: CoreAPI$1, CoreClass: CoreClass$1} = cutos;
|
|
1361
|
+
|
|
1362
|
+
const CoreSimulator$1 = {
|
|
1363
|
+
start: function (driver, port = 1883) {
|
|
1364
|
+
CoreAPI$1.init(`ws://localhost:${port}`, result => {
|
|
1365
|
+
console.log('CUTOS Simulator started and listening on port ', port);
|
|
1366
|
+
|
|
1367
|
+
let drvDefault = new CoreClass$1.Driver();
|
|
1368
|
+
drvDefault.onCommand((command) => {
|
|
1369
|
+
console.log('drvDefault onCommand', JSON.stringify(command));
|
|
1370
|
+
if (command.cmd === "init") {
|
|
1371
|
+
let rsp = {result: true};
|
|
1372
|
+
try {
|
|
1373
|
+
driver.init(command.args);
|
|
1374
|
+
} catch (e) {
|
|
1375
|
+
rsp.msg = e.message;
|
|
1376
|
+
rsp.result = false;
|
|
1377
|
+
}
|
|
1378
|
+
drvDefault.sendResponse(rsp, command.topicResponse);
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
var coreSimulator = {CoreSimulator: CoreSimulator$1};
|
|
1386
|
+
|
|
1387
|
+
const {CoreAPI, CoreDefine, CoreClass, cutosAPI} = cutos;
|
|
1388
|
+
const {CoreSimulator} = coreSimulator;
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
var src = {
|
|
1392
|
+
CoreAPI, CoreDefine, CoreClass, cutosAPI,
|
|
1393
|
+
CoreSimulator
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(src);
|
|
1397
|
+
|
|
1398
|
+
export { index as default };
|