sinricpro 2.8.1 → 2.9.1
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/.prettierrc
ADDED
package/lib/cbhandler.js
CHANGED
|
@@ -19,7 +19,7 @@ const { Bands, BandReset } = require('./contorllers/speaker_controller');
|
|
|
19
19
|
const { AdjustBands } = require('./contorllers/speaker_controller');
|
|
20
20
|
const { ToggleState } = require('./contorllers/toggle_state_controller');
|
|
21
21
|
const { Mode } = require('./contorllers/mode_controller');
|
|
22
|
-
const {
|
|
22
|
+
const { CameraStreamController } = require('./contorllers/camera_stream_controller');
|
|
23
23
|
const { UndefinedCallbackError, InvalidResponseError } = require('./errors/errors');
|
|
24
24
|
|
|
25
25
|
const jsonResponse = (client, defaultPayload, payloadValue, instanceId) => {
|
|
@@ -153,16 +153,22 @@ const handlePayload = (client, payload, signature, callbacks) => verifySignature
|
|
|
153
153
|
return ToggleState(payload, callbacks)
|
|
154
154
|
.then(([value, instanceId]) => jsonResponse(client, payload, value, instanceId))
|
|
155
155
|
.catch(handleError);
|
|
156
|
-
} else if (action === '
|
|
157
|
-
return
|
|
158
|
-
.then((
|
|
159
|
-
.catch(
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
} else if (action === 'getWebRTCAnswer') {
|
|
157
|
+
return CameraStreamController(payload, callbacks)
|
|
158
|
+
.then((answer) => jsonResponse(client, payload, { answer }))
|
|
159
|
+
.catch(handleError);
|
|
160
|
+
} else if (action === 'getCameraStreamUrl') {
|
|
161
|
+
return CameraStreamController(payload, callbacks)
|
|
162
|
+
.then((url) => jsonResponse(client, payload, { url }))
|
|
163
|
+
.catch(handleError);
|
|
164
|
+
} else if (action === 'getWebRTCOffer') {
|
|
165
|
+
return CameraStreamController(payload, callbacks)
|
|
166
|
+
.then((offer) => jsonResponse(client, payload, { offer }))
|
|
167
|
+
.catch(handleError);
|
|
162
168
|
}
|
|
163
169
|
return {};
|
|
164
170
|
})
|
|
165
171
|
.catch((err) => {
|
|
166
|
-
console.error(err
|
|
172
|
+
console.error(err);
|
|
167
173
|
});
|
|
168
174
|
module.exports = handlePayload;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
3
|
+
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
6
|
+
*/
|
|
7
|
+
const { UndefinedCallbackError, InvalidResponseError } = require("../errors/errors");
|
|
8
|
+
|
|
9
|
+
const CameraStreamController = async (payload, callbacks) => {
|
|
10
|
+
if (payload.action === "getWebRTCAnswer" && callbacks.getWebRTCAnswer) {
|
|
11
|
+
const data = await callbacks.getWebRTCAnswer(payload.deviceId, payload.value.offer);
|
|
12
|
+
|
|
13
|
+
if (data.answer) {
|
|
14
|
+
return data.answer;
|
|
15
|
+
}
|
|
16
|
+
throw new InvalidResponseError(" error");
|
|
17
|
+
}
|
|
18
|
+
if (payload.action === "getWebRTCOffer" && callbacks.getWebRTCOffer) {
|
|
19
|
+
const data = await callbacks.getWebRTCOffer(payload.deviceId);
|
|
20
|
+
|
|
21
|
+
if (data.offer) {
|
|
22
|
+
return data.offer;
|
|
23
|
+
}
|
|
24
|
+
throw new InvalidResponseError(" error");
|
|
25
|
+
}
|
|
26
|
+
else if (payload.action === "getCameraStreamUrl" && callbacks.getCameraStreamUrl) {
|
|
27
|
+
const data = await callbacks.getCameraStreamUrl(payload.deviceId, payload.value.protocol);
|
|
28
|
+
if (data.url) {
|
|
29
|
+
return data.url;
|
|
30
|
+
}
|
|
31
|
+
throw new InvalidResponseError("getCameraStreamUrl error");
|
|
32
|
+
} else {
|
|
33
|
+
throw new UndefinedCallbackError("getCameraStreamUrl callback is undefined.");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
CameraStreamController,
|
|
39
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/*
|
|
3
2
|
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
4
3
|
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
@@ -6,9 +5,9 @@
|
|
|
6
5
|
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
|
-
const uuidv4 = require(
|
|
10
|
-
const { RateLimiterMemory, BurstyRateLimiter } = require(
|
|
11
|
-
const { getSignature } = require(
|
|
8
|
+
const uuidv4 = require("uuid/v4");
|
|
9
|
+
const { RateLimiterMemory, BurstyRateLimiter } = require("rate-limiter-flexible");
|
|
10
|
+
const { getSignature } = require("../signature");
|
|
12
11
|
|
|
13
12
|
/*
|
|
14
13
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
@@ -28,37 +27,47 @@ const burstyLimiter = new BurstyRateLimiter(
|
|
|
28
27
|
duration: 60,
|
|
29
28
|
}),
|
|
30
29
|
new RateLimiterMemory({
|
|
31
|
-
keyPrefix:
|
|
30
|
+
keyPrefix: "burst",
|
|
32
31
|
points: 10,
|
|
33
32
|
duration: 60,
|
|
34
|
-
})
|
|
33
|
+
})
|
|
35
34
|
);
|
|
36
35
|
|
|
37
36
|
// @TODO resteBands
|
|
38
37
|
|
|
39
38
|
const eventNames = {
|
|
40
|
-
powerState:
|
|
41
|
-
setBrightness:
|
|
42
|
-
powerLevel:
|
|
43
|
-
color:
|
|
44
|
-
colorTemperature:
|
|
45
|
-
doorBell:
|
|
46
|
-
thermostatMode:
|
|
47
|
-
rangvalue:
|
|
48
|
-
motion:
|
|
49
|
-
contact:
|
|
50
|
-
setVolume:
|
|
51
|
-
selectInput:
|
|
52
|
-
media:
|
|
53
|
-
channel:
|
|
54
|
-
mode:
|
|
55
|
-
lock:
|
|
56
|
-
mute:
|
|
57
|
-
currentTemperature:
|
|
58
|
-
pushNotification:
|
|
39
|
+
powerState: "setPowerState",
|
|
40
|
+
setBrightness: "setBrightness",
|
|
41
|
+
powerLevel: "setPowerLevel",
|
|
42
|
+
color: "setColor",
|
|
43
|
+
colorTemperature: "setColorTemperature",
|
|
44
|
+
doorBell: "DoorbellPress",
|
|
45
|
+
thermostatMode: "setThermostatMode",
|
|
46
|
+
rangvalue: "setRangeValue",
|
|
47
|
+
motion: "motion",
|
|
48
|
+
contact: "setContactState",
|
|
49
|
+
setVolume: "setVolume",
|
|
50
|
+
selectInput: "selectInput",
|
|
51
|
+
media: "mediaControl",
|
|
52
|
+
channel: "changeChannel",
|
|
53
|
+
mode: "setMode",
|
|
54
|
+
lock: "setLockState",
|
|
55
|
+
mute: "setMute",
|
|
56
|
+
currentTemperature: "currentTemperature",
|
|
57
|
+
pushNotification: "pushNotification",
|
|
59
58
|
};
|
|
60
59
|
|
|
61
|
-
const actionArr = [
|
|
60
|
+
const actionArr = [
|
|
61
|
+
"setPowerState",
|
|
62
|
+
"setBrightness",
|
|
63
|
+
"setPowerLevel",
|
|
64
|
+
"setColor",
|
|
65
|
+
"setColorTemperature",
|
|
66
|
+
"DoorbellPress",
|
|
67
|
+
"currentTemperature",
|
|
68
|
+
"pushNotification",
|
|
69
|
+
"setThermostatMode",
|
|
70
|
+
];
|
|
62
71
|
|
|
63
72
|
const getJson = (client, eventName, deviceId, value) => {
|
|
64
73
|
const header = {
|
|
@@ -68,30 +77,30 @@ const getJson = (client, eventName, deviceId, value) => {
|
|
|
68
77
|
const payload = {
|
|
69
78
|
action: eventName,
|
|
70
79
|
cause: {
|
|
71
|
-
type:
|
|
80
|
+
type: "PHYSICAL_INTERACTION",
|
|
72
81
|
},
|
|
73
82
|
createdAt: Math.round(new Date() / 1000),
|
|
74
83
|
deviceId,
|
|
75
84
|
replyToken: uuidv4(),
|
|
76
|
-
type:
|
|
85
|
+
type: "event",
|
|
77
86
|
value,
|
|
78
87
|
};
|
|
79
88
|
const signature = {
|
|
80
89
|
HMAC: getSignature(client, JSON.stringify(payload)),
|
|
81
90
|
};
|
|
82
91
|
|
|
83
|
-
return
|
|
92
|
+
return { header, payload, signature };
|
|
84
93
|
};
|
|
85
94
|
|
|
86
95
|
const raiseEvent = async (client, eventName, deviceId, value) => {
|
|
87
96
|
if (actionArr.includes(eventName)) {
|
|
88
97
|
try {
|
|
89
|
-
await burstyLimiter.consume(
|
|
98
|
+
await burstyLimiter.consume("queue");
|
|
90
99
|
const request = JSON.stringify(getJson(client, eventName, deviceId, value));
|
|
91
|
-
if (process.env.SR_DEBUG) console.log(
|
|
100
|
+
if (process.env.SR_DEBUG) console.log(">> %j", request);
|
|
92
101
|
client.send(request);
|
|
93
102
|
} catch (rlRejected) {
|
|
94
|
-
console.log(
|
|
103
|
+
console.log("Too many events!");
|
|
95
104
|
}
|
|
96
105
|
} else {
|
|
97
106
|
console.log(`Invalid Event: ${eventName}`);
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
3
|
-
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
6
|
-
*/
|
|
7
|
-
const { UndefinedCallbackError, InvalidResponseError } = require('../errors/errors');
|
|
8
|
-
|
|
9
|
-
const WebRTC = async (payload, callbacks) => {
|
|
10
|
-
if (callbacks.webRtcOffer) {
|
|
11
|
-
const data = await callbacks.webRtcOffer(payload.deviceId, payload.value.format, payload.value.value);
|
|
12
|
-
if (data) return [payload.value, data.answer];
|
|
13
|
-
throw new InvalidResponseError('WebRTC error');
|
|
14
|
-
} else {
|
|
15
|
-
throw new UndefinedCallbackError('webRtcOffer callback is undefined.');
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
20
|
-
WebRTC,
|
|
21
|
-
};
|
package/notes-to-aruna.txt
DELETED