sinricpro 4.0.0 → 6.0.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/README.md +43 -0
- package/dist/capabilities/EqualizerController.js +4 -3
- package/dist/capabilities/EqualizerController.js.map +1 -1
- package/dist/capabilities/ModeController.js +5 -3
- package/dist/capabilities/ModeController.js.map +1 -1
- package/dist/capabilities/RangeController.js +7 -4
- package/dist/capabilities/RangeController.js.map +1 -1
- package/dist/capabilities/SettingController.js +12 -3
- package/dist/capabilities/SettingController.js.map +1 -1
- package/dist/core/MessageQueue.js +6 -2
- package/dist/core/MessageQueue.js.map +1 -1
- package/dist/core/Signature.js +51 -18
- package/dist/core/Signature.js.map +1 -1
- package/dist/core/SinricPro.js +255 -42
- package/dist/core/SinricPro.js.map +1 -1
- package/dist/core/SinricProDevice.js +16 -10
- package/dist/core/SinricProDevice.js.map +1 -1
- package/dist/core/WebSocketClient.js +2 -1
- package/dist/core/WebSocketClient.js.map +1 -1
- package/dist/core/local/MdnsAnnouncer.js +107 -0
- package/dist/core/local/MdnsAnnouncer.js.map +1 -0
- package/dist/core/local/UdpListener.js +135 -0
- package/dist/core/local/UdpListener.js.map +1 -0
- package/dist/core/types.js +9 -1
- package/dist/core/types.js.map +1 -1
- package/dist/devices/SinricProCustomDevice.js +63 -0
- package/dist/devices/SinricProCustomDevice.js.map +1 -0
- package/dist/devices/SinricProSwitch.js +3 -1
- package/dist/devices/SinricProSwitch.js.map +1 -1
- package/dist/devices/SinricProTemperatureSensor.js +28 -0
- package/dist/devices/SinricProTemperatureSensor.js.map +1 -0
- package/dist/devices/index.js +3 -0
- package/dist/devices/index.js.map +1 -1
- package/dist/utils/network.js +58 -0
- package/dist/utils/network.js.map +1 -0
- package/package.json +14 -10
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* mDNS announcement for local (LAN) control
|
|
4
|
+
*
|
|
5
|
+
* Publishes `_sinricpro._udp.local.` so apps on the same network can find this
|
|
6
|
+
* host without going through the cloud.
|
|
7
|
+
*
|
|
8
|
+
* The responder is an optional peer dependency (`bonjour-service`). It is
|
|
9
|
+
* loaded at runtime so the SDK keeps installing with no extra dependencies -
|
|
10
|
+
* without it local control still works for a client that knows the address.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.MdnsAnnouncer = void 0;
|
|
14
|
+
const SinricProSdkLogger_1 = require("../../utils/SinricProSdkLogger");
|
|
15
|
+
const network_1 = require("../../utils/network");
|
|
16
|
+
const types_1 = require("../types");
|
|
17
|
+
const package_json_1 = require("../../../package.json");
|
|
18
|
+
const OPTIONAL_MDNS_MODULES = ['bonjour-service', 'bonjour'];
|
|
19
|
+
function loadResponder() {
|
|
20
|
+
for (const moduleName of OPTIONAL_MDNS_MODULES) {
|
|
21
|
+
try {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const loaded = require(moduleName);
|
|
24
|
+
const factory = loaded?.Bonjour ?? loaded?.default ?? loaded;
|
|
25
|
+
return new factory();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
SinricProSdkLogger_1.SinricProSdkLogger.debug(`mDNS: ${moduleName} unavailable:`, error.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
class MdnsAnnouncer {
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.responder = null;
|
|
36
|
+
this.service = null;
|
|
37
|
+
this.deviceIds = '';
|
|
38
|
+
this.port = options.port ?? types_1.UDP_MULTICAST_PORT;
|
|
39
|
+
this.hostName = options.hostName ?? (0, network_1.getMdnsHostName)();
|
|
40
|
+
}
|
|
41
|
+
start(deviceIds) {
|
|
42
|
+
if (this.responder)
|
|
43
|
+
return;
|
|
44
|
+
this.responder = loadResponder();
|
|
45
|
+
if (!this.responder) {
|
|
46
|
+
SinricProSdkLogger_1.SinricProSdkLogger.warn('mDNS: no responder installed, local control will not be discoverable. ' +
|
|
47
|
+
'Run `npm install bonjour-service` to enable discovery.');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.deviceIds = deviceIds.join(',');
|
|
51
|
+
this.announce();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Re-announce when the device list changes - not on a timer and not on every
|
|
55
|
+
* reconnect.
|
|
56
|
+
*/
|
|
57
|
+
update(deviceIds) {
|
|
58
|
+
const joined = deviceIds.join(',');
|
|
59
|
+
if (!this.responder || joined === this.deviceIds)
|
|
60
|
+
return;
|
|
61
|
+
this.deviceIds = joined;
|
|
62
|
+
if (this.service) {
|
|
63
|
+
this.service.stop();
|
|
64
|
+
this.service = null;
|
|
65
|
+
}
|
|
66
|
+
this.announce();
|
|
67
|
+
}
|
|
68
|
+
stop() {
|
|
69
|
+
if (this.service) {
|
|
70
|
+
this.service.stop();
|
|
71
|
+
this.service = null;
|
|
72
|
+
}
|
|
73
|
+
if (this.responder) {
|
|
74
|
+
this.responder.destroy();
|
|
75
|
+
this.responder = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
isAnnouncing() {
|
|
79
|
+
return this.service !== null;
|
|
80
|
+
}
|
|
81
|
+
announce() {
|
|
82
|
+
if (!this.responder)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
this.service = this.responder.publish({
|
|
86
|
+
name: this.hostName,
|
|
87
|
+
type: types_1.MDNS_SERVICE_TYPE,
|
|
88
|
+
protocol: types_1.MDNS_SERVICE_PROTOCOL,
|
|
89
|
+
port: this.port,
|
|
90
|
+
host: `${this.hostName}.local`,
|
|
91
|
+
txt: {
|
|
92
|
+
deviceIds: this.deviceIds,
|
|
93
|
+
sdk: package_json_1.version,
|
|
94
|
+
udp: '1',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
SinricProSdkLogger_1.SinricProSdkLogger.info(`mDNS: announced _${types_1.MDNS_SERVICE_TYPE}._${types_1.MDNS_SERVICE_PROTOCOL}.local. ` +
|
|
98
|
+
`host=${this.hostName}.local port=${this.port} deviceIds=${this.deviceIds}`);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error('mDNS: failed to announce service:', error.message);
|
|
102
|
+
this.service = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.MdnsAnnouncer = MdnsAnnouncer;
|
|
107
|
+
//# sourceMappingURL=MdnsAnnouncer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MdnsAnnouncer.js","sourceRoot":"","sources":["../../../src/core/local/MdnsAnnouncer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,uEAAoE;AACpE,iDAAsD;AACtD,oCAAwF;AACxF,wDAAgD;AAEhD,MAAM,qBAAqB,GAAG,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;AAoB7D,SAAS,aAAa;IACpB,KAAK,MAAM,UAAU,IAAI,qBAAqB,EAAE,CAAC;QAC/C,IAAI,CAAC;YACH,8DAA8D;YAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;YACnC,MAAM,OAAO,GAAyB,MAAM,EAAE,OAAO,IAAI,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC;YACnF,OAAO,IAAI,OAAO,EAAE,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uCAAkB,CAAC,KAAK,CAAC,SAAS,UAAU,eAAe,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAOD,MAAa,aAAa;IAOxB,YAAY,UAAgC,EAAE;QAJtC,cAAS,GAAyB,IAAI,CAAC;QACvC,YAAO,GAAuB,IAAI,CAAC;QACnC,cAAS,GAAG,E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AAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;IACH,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC;IAC/B,CAAC;IAEO,QAAQ;QACd,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBACpC,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,IAAI,EAAE,yBAAiB;gBACvB,QAAQ,EAAE,6BAAqB;gBAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,QAAQ;gBAC9B,GAAG,EAAE;oBACH,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,GAAG,EAAE,sBAAO;oBACZ,GAAG,EAAE,GAAG;iBACT;aACF,CAAC,CAAC;YAEH,uCAAkB,CAAC,IAAI,CACrB,oBAAoB,yBAAiB,KAAK,6BAAqB,UAAU;gBACvE,QAAQ,IAAI,CAAC,QAAQ,eAAe,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC,SAAS,EAAE,CAC9E,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uCAAkB,CAAC,KAAK,CAAC,mCAAmC,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;YACxF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AAzFD,sCAyFC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* UDP listener for local (LAN) control
|
|
4
|
+
*
|
|
5
|
+
* Listens on the SinricPro multicast group and answers unicast requests sent
|
|
6
|
+
* directly to this host on the same port.
|
|
7
|
+
*
|
|
8
|
+
* Emits `message` with (message: string, origin: UdpOrigin) and `error` with an Error.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.UdpListener = void 0;
|
|
15
|
+
const dgram_1 = __importDefault(require("dgram"));
|
|
16
|
+
const events_1 = require("events");
|
|
17
|
+
const SinricProSdkLogger_1 = require("../../utils/SinricProSdkLogger");
|
|
18
|
+
const network_1 = require("../../utils/network");
|
|
19
|
+
const types_1 = require("../types");
|
|
20
|
+
class UdpListener extends events_1.EventEmitter {
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
super();
|
|
23
|
+
this.socket = null;
|
|
24
|
+
this.listening = false;
|
|
25
|
+
this.port = options.port ?? types_1.UDP_MULTICAST_PORT;
|
|
26
|
+
this.multicastAddress = options.multicastAddress ?? types_1.UDP_MULTICAST_ADDRESS;
|
|
27
|
+
}
|
|
28
|
+
start() {
|
|
29
|
+
if (this.socket)
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const socket = dgram_1.default.createSocket({ type: 'udp4', reuseAddr: true });
|
|
33
|
+
this.socket = socket;
|
|
34
|
+
socket.on('error', (error) => {
|
|
35
|
+
if (!this.listening) {
|
|
36
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error(`UDP: could not listen on port ${this.port}, local control unavailable:`, error.message);
|
|
37
|
+
this.socket = null;
|
|
38
|
+
socket.close();
|
|
39
|
+
reject(error);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error('UDP socket error:', error.message);
|
|
43
|
+
this.emit('error', error);
|
|
44
|
+
});
|
|
45
|
+
socket.on('listening', () => {
|
|
46
|
+
this.listening = true;
|
|
47
|
+
this.joinMulticastGroup(socket);
|
|
48
|
+
SinricProSdkLogger_1.SinricProSdkLogger.info(`UDP: listening on port ${this.port}`);
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
socket.on('message', (data, rinfo) => {
|
|
52
|
+
const message = data.toString('utf8');
|
|
53
|
+
const origin = {
|
|
54
|
+
transport: types_1.InterfaceType.UDP,
|
|
55
|
+
address: rinfo.address,
|
|
56
|
+
port: rinfo.port,
|
|
57
|
+
};
|
|
58
|
+
SinricProSdkLogger_1.SinricProSdkLogger.debug(`UDP received from ${rinfo.address}:${rinfo.port}:`, message);
|
|
59
|
+
this.emit('message', message, origin);
|
|
60
|
+
});
|
|
61
|
+
socket.bind(this.port);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Send a reply on the *listening* socket.
|
|
66
|
+
*
|
|
67
|
+
* A separate send-only socket is what broke this feature on ESP8266: the send
|
|
68
|
+
* reported success and nothing reached the wire. Reception survives sending
|
|
69
|
+
* from the joined socket.
|
|
70
|
+
*/
|
|
71
|
+
send(message, address, port) {
|
|
72
|
+
if (!this.socket) {
|
|
73
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error('UDP: not listening, dropping reply');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!port) {
|
|
77
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error('UDP: message has no peer to answer, dropping');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const buffer = Buffer.from(message, 'utf8');
|
|
81
|
+
this.socket.send(buffer, port, address, (error) => {
|
|
82
|
+
if (error) {
|
|
83
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error(`UDP: reply to ${address}:${port} failed:`, error.message);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
SinricProSdkLogger_1.SinricProSdkLogger.debug(`UDP sent to ${address}:${port}:`, message);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
isListening() {
|
|
90
|
+
return this.listening;
|
|
91
|
+
}
|
|
92
|
+
stop() {
|
|
93
|
+
if (!this.socket)
|
|
94
|
+
return;
|
|
95
|
+
try {
|
|
96
|
+
this.socket.close();
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
SinricProSdkLogger_1.SinricProSdkLogger.debug('UDP: error while closing socket:', error);
|
|
100
|
+
}
|
|
101
|
+
this.socket = null;
|
|
102
|
+
this.listening = false;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A silently failed group join is how local control dies invisibly, so the
|
|
106
|
+
* outcome is logged either way.
|
|
107
|
+
*/
|
|
108
|
+
joinMulticastGroup(socket) {
|
|
109
|
+
const interfaces = (0, network_1.getLocalIPv4Addresses)();
|
|
110
|
+
const joined = [];
|
|
111
|
+
for (const address of interfaces) {
|
|
112
|
+
try {
|
|
113
|
+
socket.addMembership(this.multicastAddress, address);
|
|
114
|
+
joined.push(address);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
SinricProSdkLogger_1.SinricProSdkLogger.debug(`UDP: could not join ${this.multicastAddress} on ${address}:`, error.message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (joined.length === 0) {
|
|
121
|
+
// No usable interface address; let the OS pick one.
|
|
122
|
+
try {
|
|
123
|
+
socket.addMembership(this.multicastAddress);
|
|
124
|
+
joined.push('default');
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
SinricProSdkLogger_1.SinricProSdkLogger.error(`UDP: failed to join multicast group ${this.multicastAddress}, discovery will not work:`, error.message);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
SinricProSdkLogger_1.SinricProSdkLogger.info(`UDP: joined multicast group ${this.multicastAddress} on ${joined.join(', ')}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.UdpListener = UdpListener;
|
|
135
|
+
//# sourceMappingURL=UdpListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UdpListener.js","sourceRoot":"","sources":["../../../src/core/local/UdpListener.ts"],"names":[],"mappings":";AAAA;;;;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GAAG,EAC5D,KAAe,CAAC,OAAO,CACzB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,oDAAoD;YACpD,IAAI,CAAC;gBACH,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBAC5C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACzB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,uCAAkB,CAAC,KAAK,CACtB,uCAAuC,IAAI,CAAC,gBAAgB,4BAA4B,EACvF,KAAe,CAAC,OAAO,CACzB,CAAC;gBACF,OAAO;YACT,CAAC;QACH,CAAC;QAED,uCAAkB,CAAC,IAAI,CACrB,+BAA+B,IAAI,CAAC,gBAAgB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC/E,CAAC;IACJ,CAAC;CACF;AA9ID,kCA8IC"}
|
package/dist/core/types.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Core type definitions for SinricPro SDK
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PERIODIC_POLL = exports.VOICE_INTERACTION = exports.APP_INTERACTION = exports.PHYSICAL_INTERACTION = exports.EVENT_LIMIT_SENSOR_VALUE = exports.EVENT_LIMIT_STATE = exports.WEBSOCKET_PING_TIMEOUT = exports.WEBSOCKET_PING_INTERVAL = exports.SINRICPRO_SERVER_SSL_PORT = exports.SINRICPRO_SERVER_PORT = exports.SINRICPRO_SERVER_URL = exports.InterfaceType = exports.MessageType = void 0;
|
|
6
|
+
exports.PERIODIC_POLL = exports.VOICE_INTERACTION = exports.APP_INTERACTION = exports.PHYSICAL_INTERACTION = exports.MAX_QUEUED_WEBSOCKET_MESSAGES = exports.MDNS_SERVICE_PROTOCOL = exports.MDNS_SERVICE_TYPE = exports.UDP_MULTICAST_PORT = exports.UDP_MULTICAST_ADDRESS = exports.EVENT_LIMIT_SENSOR_VALUE = exports.EVENT_LIMIT_STATE = exports.WEBSOCKET_PING_TIMEOUT = exports.WEBSOCKET_PING_INTERVAL = exports.SINRICPRO_SERVER_SSL_PORT = exports.SINRICPRO_SERVER_PORT = exports.SINRICPRO_SERVER_URL = exports.WEBSOCKET_ORIGIN = exports.InterfaceType = exports.MessageType = void 0;
|
|
7
7
|
var MessageType;
|
|
8
8
|
(function (MessageType) {
|
|
9
9
|
MessageType["Request"] = "request";
|
|
@@ -15,6 +15,7 @@ var InterfaceType;
|
|
|
15
15
|
InterfaceType["WebSocket"] = "websocket";
|
|
16
16
|
InterfaceType["UDP"] = "udp";
|
|
17
17
|
})(InterfaceType || (exports.InterfaceType = InterfaceType = {}));
|
|
18
|
+
exports.WEBSOCKET_ORIGIN = { transport: InterfaceType.WebSocket };
|
|
18
19
|
// Constants
|
|
19
20
|
exports.SINRICPRO_SERVER_URL = 'ws.sinric.pro';
|
|
20
21
|
exports.SINRICPRO_SERVER_PORT = 80;
|
|
@@ -23,6 +24,13 @@ exports.WEBSOCKET_PING_INTERVAL = 300000; // 5 minutes
|
|
|
23
24
|
exports.WEBSOCKET_PING_TIMEOUT = 10000; // 10 seconds
|
|
24
25
|
exports.EVENT_LIMIT_STATE = 1000; // 1 second
|
|
25
26
|
exports.EVENT_LIMIT_SENSOR_VALUE = 60000; // 60 seconds
|
|
27
|
+
// Local control (LAN) configuration - must match the other SinricPro SDKs
|
|
28
|
+
exports.UDP_MULTICAST_ADDRESS = '224.9.9.9';
|
|
29
|
+
exports.UDP_MULTICAST_PORT = 3333;
|
|
30
|
+
exports.MDNS_SERVICE_TYPE = 'sinricpro';
|
|
31
|
+
exports.MDNS_SERVICE_PROTOCOL = 'udp';
|
|
32
|
+
/** Websocket messages queued while offline are capped so an unreachable cloud cannot exhaust memory. */
|
|
33
|
+
exports.MAX_QUEUED_WEBSOCKET_MESSAGES = 100;
|
|
26
34
|
exports.PHYSICAL_INTERACTION = 'PHYSICAL_INTERACTION';
|
|
27
35
|
exports.APP_INTERACTION = 'APP_INTERACTION';
|
|
28
36
|
exports.VOICE_INTERACTION = 'VOICE_INTERACTION';
|
package/dist/core/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAiBH,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;AACjB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,wCAAuB,CAAA;IACvB,4BAAW,CAAA;AACb,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAeY,QAAA,gBAAgB,GAAoB,EAAE,SAAS,EAAE,aAAa,CAAC,SAAS,EAAE,CAAC;AAuGxF,YAAY;AACC,QAAA,oBAAoB,GAAG,eAAe,CAAC;AACvC,QAAA,qBAAqB,GAAG,EAAE,CAAC;AAC3B,QAAA,yBAAyB,GAAG,GAAG,CAAC;AAChC,QAAA,uBAAuB,GAAG,MAAM,CAAC,CAAC,YAAY;AAC9C,QAAA,sBAAsB,GAAG,KAAK,CAAC,CAAC,aAAa;AAC7C,QAAA,iBAAiB,GAAG,IAAI,CAAC,CAAC,WAAW;AACrC,QAAA,wBAAwB,GAAG,KAAK,CAAC,CAAC,aAAa;AAE5D,0EAA0E;AAC7D,QAAA,qBAAqB,GAAG,WAAW,CAAC;AACpC,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAC1B,QAAA,iBAAiB,GAAG,WAAW,CAAC;AAChC,QAAA,qBAAqB,GAAG,KAAK,CAAC;AAC3C,wGAAwG;AAC3F,QAAA,6BAA6B,GAAG,GAAG,CAAC;AAEpC,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAC9C,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AACxC,QAAA,aAAa,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SinricProCustomDevice - Flexible device with multiple capabilities
|
|
4
|
+
*
|
|
5
|
+
* A custom device type that supports many SinricPro capabilities, allowing you to
|
|
6
|
+
* build devices with any combination of features you need.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SinricProCustomDevice = SinricProCustomDevice;
|
|
10
|
+
const SinricProDevice_1 = require("../core/SinricProDevice");
|
|
11
|
+
const PowerStateController_1 = require("../capabilities/PowerStateController");
|
|
12
|
+
const BrightnessController_1 = require("../capabilities/BrightnessController");
|
|
13
|
+
const ColorController_1 = require("../capabilities/ColorController");
|
|
14
|
+
const ColorTemperatureController_1 = require("../capabilities/ColorTemperatureController");
|
|
15
|
+
const RangeController_1 = require("../capabilities/RangeController");
|
|
16
|
+
const ModeController_1 = require("../capabilities/ModeController");
|
|
17
|
+
const LockController_1 = require("../capabilities/LockController");
|
|
18
|
+
const ThermostatController_1 = require("../capabilities/ThermostatController");
|
|
19
|
+
const TemperatureSensor_1 = require("../capabilities/TemperatureSensor");
|
|
20
|
+
const SettingController_1 = require("../capabilities/SettingController");
|
|
21
|
+
const PushNotification_1 = require("../capabilities/PushNotification");
|
|
22
|
+
const PercentageController_1 = require("../capabilities/PercentageController");
|
|
23
|
+
const PowerLevelController_1 = require("../capabilities/PowerLevelController");
|
|
24
|
+
// Apply mixins in order - combining many capabilities
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
class SinricProCustomDeviceClass extends (0, SettingController_1.SettingController)((0, PushNotification_1.PushNotification)((0, TemperatureSensor_1.TemperatureSensor)((0, ThermostatController_1.ThermostatController)((0, LockController_1.LockController)((0, ModeController_1.ModeController)((0, RangeController_1.RangeController)((0, PercentageController_1.PercentageController)((0, PowerLevelController_1.PowerLevelController)((0, ColorTemperatureController_1.ColorTemperatureController)(
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
(0, ColorController_1.ColorController)((0, BrightnessController_1.BrightnessController)((0, PowerStateController_1.PowerStateController)(SinricProDevice_1.SinricProDevice))))))))))))) {
|
|
29
|
+
constructor(deviceId, productType = 'CUSTOM_DEVICE') {
|
|
30
|
+
super(deviceId, productType);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a SinricProCustomDevice
|
|
35
|
+
*
|
|
36
|
+
* A flexible device that supports many capabilities. Register callbacks only for
|
|
37
|
+
* the capabilities you need.
|
|
38
|
+
*
|
|
39
|
+
* @param deviceId - Device ID from SinricPro portal
|
|
40
|
+
* @param productType - Optional product type (default: 'CUSTOM_DEVICE')
|
|
41
|
+
* @returns SinricProCustomDevice instance
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const device = SinricProCustomDevice('device-id');
|
|
46
|
+
*
|
|
47
|
+
* // Register only the callbacks you need
|
|
48
|
+
* device.onPowerState(async (deviceId, state) => {
|
|
49
|
+
* console.log(`Power: ${state}`);
|
|
50
|
+
* return true;
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* device.onBrightness(async (deviceId, brightness) => {
|
|
54
|
+
* console.log(`Brightness: ${brightness}`);
|
|
55
|
+
* return true;
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
function SinricProCustomDevice(deviceId, productType = 'CUSTOM_DEVICE') {
|
|
61
|
+
return new SinricProCustomDeviceClass(deviceId, productType);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=SinricProCustomDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SinricProCustomDevice.js","sourceRoot":"","sources":["../../src/devices/SinricProCustomDevice.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA8EH,sDAkBC;AA9FD,6DAA0D;AAC1D,+EAAmG;AACnG,+EAAmG;AACnG,qEAAoF;AACpF,2FAGoD;AACpD,qEAAoF;AACpF,mEAAiF;AACjF,mEAAiF;AACjF,+EAAmG;AACnG,yEAA0F;AAC1F,yEAA0F;AAC1F,uEAAuF;AACvF,+EAAmG;AACnG,+EAAmG;AAEnG,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,0BAA2B,SAAQ,IAAA,qCAAiB,EACxD,IAAA,mCAAgB,EACd,IAAA,qCAAiB,EACf,IAAA,2CAAoB,EAClB,IAAA,+BAAc,EACZ,IAAA,+BAAc,EACZ,IAAA,iCAAe,EACb,IAAA,2CAAoB,EAClB,IAAA,2CAAoB,EAClB,IAAA,uDAA0B;AACxB,8DAA8D;AAC9D,IAAA,iCAAe,EACb,IAAA,2CAAoB,EAAC,IAAA,2CAAoB,EAAC,iCAAsB,CAAC,CAAC,CACnE,CACF,CACF,CACF,CACF,CACF,CACF,CACF,CACF,CACF,CACF;IACC,YAAY,QAAgB,EAAE,cAAsB,eAAe;QACjE,KAAK,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC/B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8DAA8D;AAC9D,SAAgB,qBAAqB,CACnC,QAAgB,EAChB,cAAsB,eAAe;IAerC,OAAO,IAAI,0BAA0B,CAAC,QAAQ,EAAE,WAAW,CAAQ,CAAC;AACtE,CAAC"}
|
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.SinricProSwitch = SinricProSwitch;
|
|
7
7
|
const SinricProDevice_1 = require("../core/SinricProDevice");
|
|
8
8
|
const PowerStateController_1 = require("../capabilities/PowerStateController");
|
|
9
|
+
const SettingController_1 = require("../capabilities/SettingController");
|
|
10
|
+
const PushNotification_1 = require("../capabilities/PushNotification");
|
|
9
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
class SinricProSwitchClass extends (0, PowerStateController_1.PowerStateController)(SinricProDevice_1.SinricProDevice) {
|
|
12
|
+
class SinricProSwitchClass extends (0, SettingController_1.SettingController)((0, PushNotification_1.PushNotification)((0, PowerStateController_1.PowerStateController)(SinricProDevice_1.SinricProDevice))) {
|
|
11
13
|
constructor(deviceId) {
|
|
12
14
|
super(deviceId, 'SWITCH');
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SinricProSwitch.js","sourceRoot":"","sources":["../../src/devices/SinricProSwitch.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"SinricProSwitch.js","sourceRoot":"","sources":["../../src/devices/SinricProSwitch.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAsBH,0CAIC;AAxBD,6DAA0D;AAC1D,+EAAmG;AACnG,yEAA0F;AAC1F,uEAAuF;AAEvF,8DAA8D;AAC9D,MAAM,oBAAqB,SAAQ,IAAA,qCAAiB,EAClD,IAAA,mCAAgB,EAAC,IAAA,2CAAoB,EAAC,iCAAsB,CAAC,CAAC,CAC/D;IACC,YAAY,QAAgB;QAC1B,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC;CACF;AAED;;;;GAIG;AACH,8DAA8D;AAC9D,SAAgB,eAAe,CAC7B,QAAgB;IAEhB,OAAO,IAAI,oBAAoB,CAAC,QAAQ,CAAQ,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SinricProTemperatureSensor - Temperature and humidity sensor device
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SinricProTemperatureSensor = SinricProTemperatureSensor;
|
|
7
|
+
const SinricProDevice_1 = require("../core/SinricProDevice");
|
|
8
|
+
const TemperatureSensor_1 = require("../capabilities/TemperatureSensor");
|
|
9
|
+
const SettingController_1 = require("../capabilities/SettingController");
|
|
10
|
+
const PushNotification_1 = require("../capabilities/PushNotification");
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
class SinricProTemperatureSensorClass extends (0, SettingController_1.SettingController)(
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
(0, PushNotification_1.PushNotification)((0, TemperatureSensor_1.TemperatureSensor)(SinricProDevice_1.SinricProDevice))) {
|
|
15
|
+
constructor(deviceId) {
|
|
16
|
+
super(deviceId, 'TEMPERATURE_SENSOR');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a SinricProTemperatureSensor device
|
|
21
|
+
* @param deviceId - Device ID from SinricPro portal
|
|
22
|
+
* @returns SinricProTemperatureSensor instance
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
function SinricProTemperatureSensor(deviceId) {
|
|
26
|
+
return new SinricProTemperatureSensorClass(deviceId);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=SinricProTemperatureSensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SinricProTemperatureSensor.js","sourceRoot":"","sources":["../../src/devices/SinricProTemperatureSensor.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAuBH,gEAIC;AAzBD,6DAA0D;AAC1D,yEAA0F;AAC1F,yEAA0F;AAC1F,uEAAuF;AAEvF,8DAA8D;AAC9D,MAAM,+BAAgC,SAAQ,IAAA,qCAAiB;AAC7D,8DAA8D;AAC9D,IAAA,mCAAgB,EAAC,IAAA,qCAAiB,EAAC,iCAAsB,CAAC,CAAC,CAC5D;IACC,YAAY,QAAgB;QAC1B,KAAK,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IACxC,CAAC;CACF;AAED;;;;GAIG;AACH,8DAA8D;AAC9D,SAAgB,0BAA0B,CACxC,QAAgB;IAEhB,OAAO,IAAI,+BAA+B,CAAC,QAAQ,CAAQ,CAAC;AAC9D,CAAC"}
|
package/dist/devices/index.js
CHANGED
|
@@ -37,8 +37,11 @@ __exportStar(require("./SinricProDoorbell"), exports);
|
|
|
37
37
|
// Sensors
|
|
38
38
|
__exportStar(require("./SinricProMotionSensor"), exports);
|
|
39
39
|
__exportStar(require("./SinricProContactSensor"), exports);
|
|
40
|
+
__exportStar(require("./SinricProTemperatureSensor"), exports);
|
|
40
41
|
__exportStar(require("./SinricProAirQualitySensor"), exports);
|
|
41
42
|
__exportStar(require("./SinricProPowerSensor"), exports);
|
|
42
43
|
// Window treatments
|
|
43
44
|
__exportStar(require("./SinricProBlinds"), exports);
|
|
45
|
+
// Custom/Flexible
|
|
46
|
+
__exportStar(require("./SinricProCustomDevice"), exports);
|
|
44
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,gBAAgB;AAChB,oDAAkC;AAClC,uDAAqC;AACrC,mDAAiC;AAEjC,kBAAkB;AAClB,wDAAsC;AACtC,sDAAoC;AACpC,iDAA+B;AAC/B,mDAAiC;AAEjC,gBAAgB;AAChB,gDAA8B;AAC9B,qDAAmC;AAEnC,oBAAoB;AACpB,kDAAgC;AAChC,wDAAsC;AACtC,oDAAkC;AAClC,sDAAoC;AAEpC,UAAU;AACV,0DAAwC;AACxC,2DAAyC;AACzC,8DAA4C;AAC5C,yDAAuC;AAEvC,oBAAoB;AACpB,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,gBAAgB;AAChB,oDAAkC;AAClC,uDAAqC;AACrC,mDAAiC;AAEjC,kBAAkB;AAClB,wDAAsC;AACtC,sDAAoC;AACpC,iDAA+B;AAC/B,mDAAiC;AAEjC,gBAAgB;AAChB,gDAA8B;AAC9B,qDAAmC;AAEnC,oBAAoB;AACpB,kDAAgC;AAChC,wDAAsC;AACtC,oDAAkC;AAClC,sDAAoC;AAEpC,UAAU;AACV,0DAAwC;AACxC,2DAAyC;AACzC,+DAA6C;AAC7C,8DAA4C;AAC5C,yDAAuC;AAEvC,oBAAoB;AACpB,oDAAkC;AAElC,kBAAkB;AAClB,0DAAwC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Host network helpers shared by the websocket client and local control
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getMacAddress = getMacAddress;
|
|
10
|
+
exports.getMdnsHostName = getMdnsHostName;
|
|
11
|
+
exports.getLocalIPv4Addresses = getLocalIPv4Addresses;
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const NO_MAC = '00:00:00:00:00:00';
|
|
14
|
+
/**
|
|
15
|
+
* MAC address of the first non-internal network interface.
|
|
16
|
+
* @returns MAC address string in format XX:XX:XX:XX:XX:XX
|
|
17
|
+
*/
|
|
18
|
+
function getMacAddress() {
|
|
19
|
+
for (const netInterfaces of Object.values(os_1.default.networkInterfaces())) {
|
|
20
|
+
if (!netInterfaces)
|
|
21
|
+
continue;
|
|
22
|
+
for (const net of netInterfaces) {
|
|
23
|
+
if (!net.internal && net.mac && net.mac !== NO_MAC) {
|
|
24
|
+
return net.mac.toUpperCase();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return NO_MAC;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* mDNS host name for this machine: `sinricpro-<mac, lowercase, no separators>`.
|
|
32
|
+
*/
|
|
33
|
+
function getMdnsHostName() {
|
|
34
|
+
return `sinricpro-${getMacAddress().replace(/[:-]/g, '').toLowerCase()}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* IPv4 addresses of every non-internal interface.
|
|
38
|
+
*
|
|
39
|
+
* A host commonly has several (Docker, VPN, WSL) and the multicast group has to
|
|
40
|
+
* be joined on each of them, or discovery answers on the wrong network.
|
|
41
|
+
*/
|
|
42
|
+
function getLocalIPv4Addresses() {
|
|
43
|
+
const addresses = [];
|
|
44
|
+
for (const netInterfaces of Object.values(os_1.default.networkInterfaces())) {
|
|
45
|
+
if (!netInterfaces)
|
|
46
|
+
continue;
|
|
47
|
+
for (const net of netInterfaces) {
|
|
48
|
+
if (net.internal)
|
|
49
|
+
continue;
|
|
50
|
+
// Node <18.4 reports family as 'IPv4', newer versions as 4
|
|
51
|
+
if (net.family !== 'IPv4' && net.family !== 4)
|
|
52
|
+
continue;
|
|
53
|
+
addresses.push(net.address);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return addresses;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAUH,sCAYC;AAKD,0CAEC;AAQD,sDAeC;AAlDD,4CAAoB;AAEpB,MAAM,MAAM,GAAG,mBAAmB,CAAC;AAEnC;;;GAGG;AACH,SAAgB,aAAa;IAC3B,KAAK,MAAM,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC,YAAE,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC;QAClE,IAAI,CAAC,aAAa;YAAE,SAAS;QAE7B,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC;gBACnD,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe;IAC7B,OAAO,aAAa,aAAa,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB;IACnC,MAAM,SAAS,GAAa,EAAE,CAAC;IAE/B,KAAK,MAAM,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC,YAAE,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC;QAClE,IAAI,CAAC,aAAa;YAAE,SAAS;QAE7B,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;YAChC,IAAI,GAAG,CAAC,QAAQ;gBAAE,SAAS;YAC3B,2DAA2D;YAC3D,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,IAAK,GAAG,CAAC,MAA4B,KAAK,CAAC;gBAAE,SAAS;YAC/E,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sinricpro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Official SinricPro SDK for Node.js and TypeScript - Control IoT devices with Alexa and Google Home",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
"lint:fix": "eslint src/**/*.ts --fix",
|
|
19
19
|
"format": "prettier --write \"src/**/*.ts\" \"examples/**/*.ts\" \"test/**/*.ts\"",
|
|
20
20
|
"prepublishOnly": "npm run lint && npm run build && npm test",
|
|
21
|
-
"example:switch": "ts-node examples/switch/index.ts",
|
|
22
|
-
"example:light": "ts-node examples/light/index.ts",
|
|
23
|
-
"example:thermostat": "ts-node examples/thermostat/index.ts",
|
|
24
|
-
"example:tv": "ts-node examples/tv/index.ts",
|
|
25
|
-
"example:fan": "ts-node examples/fan/index.ts",
|
|
26
|
-
"example:lock": "ts-node examples/lock/index.ts",
|
|
27
|
-
"example:windowac": "ts-node examples/windowac/index.ts",
|
|
28
|
-
"example:speaker": "ts-node examples/speaker/index.ts"
|
|
21
|
+
"example:switch": "ts-node --project examples/tsconfig.json examples/switch/index.ts",
|
|
22
|
+
"example:light": "ts-node --project examples/tsconfig.json examples/light/index.ts",
|
|
23
|
+
"example:thermostat": "ts-node --project examples/tsconfig.json examples/thermostat/index.ts",
|
|
24
|
+
"example:tv": "ts-node --project examples/tsconfig.json examples/tv/index.ts",
|
|
25
|
+
"example:fan": "ts-node --project examples/tsconfig.json examples/fan/index.ts",
|
|
26
|
+
"example:lock": "ts-node --project examples/tsconfig.json examples/lock/index.ts",
|
|
27
|
+
"example:windowac": "ts-node --project examples/tsconfig.json examples/windowac/index.ts",
|
|
28
|
+
"example:speaker": "ts-node --project examples/tsconfig.json examples/speaker/index.ts",
|
|
29
|
+
"example:customdevice": "ts-node --project examples/tsconfig.json examples/customdevice/index.ts"
|
|
29
30
|
},
|
|
30
31
|
"keywords": [
|
|
31
32
|
"sinricpro",
|
|
@@ -36,7 +37,9 @@
|
|
|
36
37
|
"typescript",
|
|
37
38
|
"nodejs",
|
|
38
39
|
"websocket",
|
|
39
|
-
"home-automation"
|
|
40
|
+
"home-automation",
|
|
41
|
+
"local-control",
|
|
42
|
+
"mdns"
|
|
40
43
|
],
|
|
41
44
|
"author": "SinricPro",
|
|
42
45
|
"license": "CC-BY-SA-4.0",
|
|
@@ -58,6 +61,7 @@
|
|
|
58
61
|
],
|
|
59
62
|
"sideEffects": false,
|
|
60
63
|
"dependencies": {
|
|
64
|
+
"bonjour-service": "^1.2.1",
|
|
61
65
|
"ws": "^8.14.2"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|