@camera.ui/camera-ui-tuya 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/bundle.zip +0 -0
- package/package.json +16 -37
- package/CHANGELOG.md +0 -8
- package/CONTRIBUTING.md +0 -1
- package/LICENSE.md +0 -22
- package/README.md +0 -1
- package/config.schema.json +0 -296
- package/dist/camera.d.ts +0 -34
- package/dist/camera.js +0 -247
- package/dist/camera.js.map +0 -1
- package/dist/index.d.ts +0 -24
- package/dist/index.js +0 -225
- package/dist/index.js.map +0 -1
- package/dist/peer.d.ts +0 -34
- package/dist/peer.js +0 -268
- package/dist/peer.js.map +0 -1
- package/dist/tuya/cloud.d.ts +0 -35
- package/dist/tuya/cloud.js +0 -227
- package/dist/tuya/cloud.js.map +0 -1
- package/dist/tuya/const.d.ts +0 -121
- package/dist/tuya/const.js +0 -2
- package/dist/tuya/const.js.map +0 -1
- package/dist/tuya/device.d.ts +0 -14
- package/dist/tuya/device.js +0 -68
- package/dist/tuya/device.js.map +0 -1
- package/dist/tuya/mq.d.ts +0 -25
- package/dist/tuya/mq.js +0 -85
- package/dist/tuya/mq.js.map +0 -1
- package/dist/tuya/pulsar.d.ts +0 -74
- package/dist/tuya/pulsar.js +0 -198
- package/dist/tuya/pulsar.js.map +0 -1
- package/dist/tuya/utils.d.ts +0 -16
- package/dist/tuya/utils.js +0 -276
- package/dist/tuya/utils.js.map +0 -1
- package/dist/types.d.ts +0 -11
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/peer.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { ReplaySubject, Subject } from 'rxjs';
|
|
3
|
-
import { MediaStreamTrack, RTCIceCandidate, RTCPeerConnection, RTCRtpCodecParameters } from 'werift';
|
|
4
|
-
import { TuyaMQ } from './tuya/mq.js';
|
|
5
|
-
export class CustomPeerConnection {
|
|
6
|
-
pc;
|
|
7
|
-
sessionId;
|
|
8
|
-
platform;
|
|
9
|
-
cameraDevice;
|
|
10
|
-
cloudCamera;
|
|
11
|
-
cameraLogger;
|
|
12
|
-
mqtt;
|
|
13
|
-
deviceWebRTConfig;
|
|
14
|
-
mqttWebRTConfig;
|
|
15
|
-
onAudioRtp = new Subject();
|
|
16
|
-
onAudioRtcp = new Subject();
|
|
17
|
-
onVideoRtp = new Subject();
|
|
18
|
-
onVideoRtcp = new Subject();
|
|
19
|
-
onIceCandidate = new Subject();
|
|
20
|
-
onConnectionState = new ReplaySubject(1);
|
|
21
|
-
returnAudioTrack = new MediaStreamTrack({ kind: 'audio' });
|
|
22
|
-
constructor(platform, cameraDevice, cloudCamera) {
|
|
23
|
-
this.platform = platform;
|
|
24
|
-
this.cameraDevice = cameraDevice;
|
|
25
|
-
this.cloudCamera = cloudCamera;
|
|
26
|
-
this.cameraLogger = cameraDevice.logger;
|
|
27
|
-
this.sessionId = randomUUID();
|
|
28
|
-
}
|
|
29
|
-
async createPeerConnection() {
|
|
30
|
-
const deviceWebRTConfigResponse = await this.platform.cloud?.getDeviceWebRTConfig(this.cloudCamera);
|
|
31
|
-
if (!deviceWebRTConfigResponse?.success) {
|
|
32
|
-
throw new Error(`Failed to create device rtc config for ${this.cameraDevice.name}: request failed: ${deviceWebRTConfigResponse?.result}.`);
|
|
33
|
-
}
|
|
34
|
-
this.deviceWebRTConfig = deviceWebRTConfigResponse.result;
|
|
35
|
-
const mqResponse = await this.platform.cloud?.getWebRTCMQConfig(this.deviceWebRTConfig);
|
|
36
|
-
if (!mqResponse?.success) {
|
|
37
|
-
throw new Error(`Failed to create rtc mqtt config for ${this.cameraDevice.name}: request failed: ${mqResponse?.result}.`);
|
|
38
|
-
}
|
|
39
|
-
this.mqttWebRTConfig = mqResponse.result;
|
|
40
|
-
this.mqtt = new TuyaMQ(this.mqttWebRTConfig);
|
|
41
|
-
await this.mqtt.connect();
|
|
42
|
-
const iceServers = this.deviceWebRTConfig.p2p_config.ices.map((ice) => {
|
|
43
|
-
return {
|
|
44
|
-
credential: ice.credential,
|
|
45
|
-
urls: ice.urls,
|
|
46
|
-
username: ice.username,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
const pc = (this.pc = new RTCPeerConnection({
|
|
50
|
-
codecs: {
|
|
51
|
-
video: [
|
|
52
|
-
new RTCRtpCodecParameters({
|
|
53
|
-
mimeType: 'video/H264',
|
|
54
|
-
clockRate: 90000,
|
|
55
|
-
rtcpFeedback: [{ type: 'transport-cc' }, { type: 'ccm', parameter: 'fir' }, { type: 'nack' }, { type: 'nack', parameter: 'pli' }, { type: 'goog-remb' }],
|
|
56
|
-
parameters: 'packetization-mode=1;profile-level-id=640029;level-asymmetry-allowed=1',
|
|
57
|
-
}),
|
|
58
|
-
],
|
|
59
|
-
audio: [
|
|
60
|
-
new RTCRtpCodecParameters({
|
|
61
|
-
mimeType: 'audio/PCMU',
|
|
62
|
-
clockRate: 8000,
|
|
63
|
-
channels: 1,
|
|
64
|
-
payloadType: 0,
|
|
65
|
-
}),
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
iceServers,
|
|
69
|
-
iceTransportPolicy: 'all',
|
|
70
|
-
bundlePolicy: 'max-bundle',
|
|
71
|
-
}));
|
|
72
|
-
const videoTransceiver = pc.addTransceiver('video', {
|
|
73
|
-
direction: 'recvonly',
|
|
74
|
-
});
|
|
75
|
-
const audioTransceiver = pc.addTransceiver(this.returnAudioTrack, {
|
|
76
|
-
direction: 'sendrecv',
|
|
77
|
-
});
|
|
78
|
-
audioTransceiver.onTrack.subscribe((track) => {
|
|
79
|
-
track.onReceiveRtp.subscribe((rtp) => {
|
|
80
|
-
this.onAudioRtp.next(rtp);
|
|
81
|
-
});
|
|
82
|
-
track.onReceiveRtcp.subscribe((rtcp) => {
|
|
83
|
-
this.onAudioRtcp.next(rtcp);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
videoTransceiver.onTrack.subscribe((track) => {
|
|
87
|
-
track.onReceiveRtp.subscribe((rtp) => {
|
|
88
|
-
this.onVideoRtp.next(rtp);
|
|
89
|
-
});
|
|
90
|
-
track.onReceiveRtcp.subscribe((rtcp) => {
|
|
91
|
-
this.onVideoRtcp.next(rtcp);
|
|
92
|
-
});
|
|
93
|
-
track.onReceiveRtp.once(() => {
|
|
94
|
-
setInterval(() => videoTransceiver.receiver.sendRtcpPLI(track.ssrc), 4000);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
pc.onIceCandidate.subscribe((iceCandidate) => {
|
|
98
|
-
if (iceCandidate) {
|
|
99
|
-
this.onIceCandidate.next(iceCandidate);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
pc.iceConnectionStateChange.subscribe(() => {
|
|
103
|
-
if (pc.iceConnectionState === 'closed') {
|
|
104
|
-
this.onConnectionState.next('closed');
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
pc.connectionStateChange.subscribe(() => {
|
|
108
|
-
this.onConnectionState.next(pc.connectionState);
|
|
109
|
-
});
|
|
110
|
-
this.onIceCandidate.subscribe((candidate) => {
|
|
111
|
-
if (!candidate.candidate || candidate.candidate == '') {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.sendIceCandidate(candidate);
|
|
115
|
-
});
|
|
116
|
-
const offer = await this.createOffer();
|
|
117
|
-
const offerMessage = {
|
|
118
|
-
mode: 'webrtc',
|
|
119
|
-
sdp: offer.sdp,
|
|
120
|
-
auth: this.deviceWebRTConfig.auth,
|
|
121
|
-
stream_type: 1,
|
|
122
|
-
};
|
|
123
|
-
const webRTCMessage = {
|
|
124
|
-
protocol: 302,
|
|
125
|
-
pv: '2.2',
|
|
126
|
-
t: Date.now(),
|
|
127
|
-
data: {
|
|
128
|
-
header: {
|
|
129
|
-
type: 'offer',
|
|
130
|
-
from: this.mqttWebRTConfig.source_topic.split('/')[3],
|
|
131
|
-
to: this.deviceWebRTConfig.id,
|
|
132
|
-
sub_dev_id: '',
|
|
133
|
-
sessionid: this.sessionId,
|
|
134
|
-
moto_id: this.deviceWebRTConfig.moto_id,
|
|
135
|
-
tid: '',
|
|
136
|
-
},
|
|
137
|
-
msg: offerMessage,
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
this.mqtt.publish(JSON.stringify(webRTCMessage));
|
|
141
|
-
const answer = await this.createLocalDescription();
|
|
142
|
-
await this.acceptAnswer(answer);
|
|
143
|
-
}
|
|
144
|
-
async createOffer() {
|
|
145
|
-
if (!this.pc) {
|
|
146
|
-
throw new Error('Peer connection not created');
|
|
147
|
-
}
|
|
148
|
-
const offer = await this.pc.createOffer();
|
|
149
|
-
this.pc.setLocalDescription(offer);
|
|
150
|
-
return offer;
|
|
151
|
-
}
|
|
152
|
-
async acceptAnswer(answer) {
|
|
153
|
-
if (!this.pc) {
|
|
154
|
-
throw new Error('Peer connection not created');
|
|
155
|
-
}
|
|
156
|
-
await this.pc.setRemoteDescription(answer);
|
|
157
|
-
}
|
|
158
|
-
async addIceCandidate(candidate) {
|
|
159
|
-
if (!this.pc) {
|
|
160
|
-
throw new Error('Peer connection not created');
|
|
161
|
-
}
|
|
162
|
-
await this.pc.addIceCandidate(candidate);
|
|
163
|
-
}
|
|
164
|
-
async close() {
|
|
165
|
-
try {
|
|
166
|
-
this.endSession();
|
|
167
|
-
await this.pc?.close();
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
//
|
|
171
|
-
}
|
|
172
|
-
this.reset();
|
|
173
|
-
}
|
|
174
|
-
async createLocalDescription() {
|
|
175
|
-
return new Promise((resolve, reject) => {
|
|
176
|
-
const messageHandler = (_client, message) => {
|
|
177
|
-
const webRTCMessage = JSON.parse(message);
|
|
178
|
-
if (webRTCMessage.data.header.type == 'answer') {
|
|
179
|
-
const answer = webRTCMessage.data.msg;
|
|
180
|
-
resolve({
|
|
181
|
-
sdp: answer.sdp,
|
|
182
|
-
type: 'answer',
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
else if (webRTCMessage.data.header.type == 'candidate') {
|
|
186
|
-
const candidate = webRTCMessage.data.msg;
|
|
187
|
-
if (!candidate?.candidate || candidate.candidate == '') {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
this.addIceCandidate(new RTCIceCandidate({
|
|
191
|
-
candidate: candidate.candidate,
|
|
192
|
-
sdpMid: '0',
|
|
193
|
-
sdpMLineIndex: 0,
|
|
194
|
-
}));
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this.cameraLogger.error('[WebRTC] - TuyaMQ: There was an error trying to get an answer or candidate from TuyaMQ.');
|
|
198
|
-
this.mqtt?.removeMessageListener(messageHandler);
|
|
199
|
-
this.close();
|
|
200
|
-
reject(new Error('[WebRTC] - TuyaMQ: There was an error trying to get an answer or candidate from TuyaMQ.'));
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
this.mqtt?.message(messageHandler);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
async sendIceCandidate(candidate) {
|
|
207
|
-
if (!this.deviceWebRTConfig || !this.mqttWebRTConfig || !this.mqtt) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const acandidate = candidate.candidate ? `a=${candidate.candidate}` : '';
|
|
211
|
-
const candidateMessage = {
|
|
212
|
-
mode: 'webrtc',
|
|
213
|
-
candidate: acandidate,
|
|
214
|
-
};
|
|
215
|
-
const webRTCMQMessage = {
|
|
216
|
-
protocol: 302,
|
|
217
|
-
pv: '2.2',
|
|
218
|
-
t: Date.now(),
|
|
219
|
-
data: {
|
|
220
|
-
header: {
|
|
221
|
-
type: 'candidate',
|
|
222
|
-
from: this.mqttWebRTConfig.source_topic.split('/')[3],
|
|
223
|
-
to: this.deviceWebRTConfig.id,
|
|
224
|
-
sub_dev_id: '',
|
|
225
|
-
sessionid: this.sessionId,
|
|
226
|
-
moto_id: this.deviceWebRTConfig.moto_id,
|
|
227
|
-
tid: '',
|
|
228
|
-
},
|
|
229
|
-
msg: candidateMessage,
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
this.mqtt.publish(JSON.stringify(webRTCMQMessage));
|
|
233
|
-
}
|
|
234
|
-
endSession() {
|
|
235
|
-
if (!this.deviceWebRTConfig || !this.mqttWebRTConfig || !this.mqtt) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const webRTCMessage = {
|
|
239
|
-
protocol: 302,
|
|
240
|
-
pv: '2.2',
|
|
241
|
-
t: Date.now(),
|
|
242
|
-
data: {
|
|
243
|
-
header: {
|
|
244
|
-
type: 'disconnect',
|
|
245
|
-
from: this.mqttWebRTConfig.source_topic.split('/')[3],
|
|
246
|
-
to: this.deviceWebRTConfig.id,
|
|
247
|
-
sub_dev_id: '',
|
|
248
|
-
sessionid: this.sessionId,
|
|
249
|
-
moto_id: this.deviceWebRTConfig.moto_id,
|
|
250
|
-
tid: '',
|
|
251
|
-
},
|
|
252
|
-
msg: {
|
|
253
|
-
mode: 'webrtc',
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
this.mqtt.publish(JSON.stringify(webRTCMessage));
|
|
258
|
-
this.mqtt.stop();
|
|
259
|
-
}
|
|
260
|
-
reset() {
|
|
261
|
-
this.mqtt?.stop();
|
|
262
|
-
this.mqtt = undefined;
|
|
263
|
-
this.deviceWebRTConfig = undefined;
|
|
264
|
-
this.mqttWebRTConfig = undefined;
|
|
265
|
-
this.pc = undefined;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
//# sourceMappingURL=peer.js.map
|
package/dist/peer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peer.js","sourceRoot":"","sources":["../src/peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,eAAe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,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;IACtB,CAAC;CACF"}
|
package/dist/tuya/cloud.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../types.js';
|
|
2
|
-
import type { DeviceWebRTConfig, MQTTConfig, RTSPToken, TuyaDeviceConfig, TuyaDeviceStatus, TuyaHomeConfig, TuyaResponse } from './const.js';
|
|
3
|
-
export declare class TuyaCloud {
|
|
4
|
-
private readonly config;
|
|
5
|
-
private readonly nonce;
|
|
6
|
-
private session?;
|
|
7
|
-
private client;
|
|
8
|
-
private readonly userId;
|
|
9
|
-
private readonly clientId;
|
|
10
|
-
private readonly secret;
|
|
11
|
-
private readonly country;
|
|
12
|
-
private readonly whitelist;
|
|
13
|
-
private _cameras;
|
|
14
|
-
get cameras(): TuyaDeviceConfig[] | undefined;
|
|
15
|
-
constructor(config: Config);
|
|
16
|
-
login(): Promise<boolean>;
|
|
17
|
-
isLoggedIn(): boolean;
|
|
18
|
-
updateDevice(device: TuyaDeviceConfig, statuses: TuyaDeviceStatus[]): Promise<boolean>;
|
|
19
|
-
getHomeList(): Promise<TuyaHomeConfig[]>;
|
|
20
|
-
getHomeDeviceList(homeID: number): Promise<TuyaDeviceConfig[]>;
|
|
21
|
-
fetchDevices(): Promise<boolean>;
|
|
22
|
-
getRTSPS(camera: TuyaDeviceConfig): Promise<RTSPToken | undefined>;
|
|
23
|
-
getDeviceWebRTConfig(camera: TuyaDeviceConfig): Promise<TuyaResponse<DeviceWebRTConfig>>;
|
|
24
|
-
getWebRTCMQConfig(webRTCDeviceConfig: DeviceWebRTConfig): Promise<TuyaResponse<MQTTConfig>>;
|
|
25
|
-
getSessionUserId(): string | undefined;
|
|
26
|
-
get<T>(path: string, query?: {
|
|
27
|
-
[k: string]: any;
|
|
28
|
-
}): Promise<TuyaResponse<T>>;
|
|
29
|
-
post<T>(path: string, body?: {
|
|
30
|
-
[k: string]: any;
|
|
31
|
-
}): Promise<TuyaResponse<T>>;
|
|
32
|
-
private request;
|
|
33
|
-
private getStringToSign;
|
|
34
|
-
private refreshAccessTokenIfNeeded;
|
|
35
|
-
}
|
package/dist/tuya/cloud.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { randomBytes } from 'crypto';
|
|
3
|
-
import CryptoJS from 'crypto-js';
|
|
4
|
-
import { getTuyaCloudEndpoint, TUYA_COUNTRIES } from './utils.js';
|
|
5
|
-
export class TuyaCloud {
|
|
6
|
-
config;
|
|
7
|
-
// Tuya IoT Cloud API
|
|
8
|
-
nonce;
|
|
9
|
-
session = undefined;
|
|
10
|
-
client;
|
|
11
|
-
userId;
|
|
12
|
-
clientId;
|
|
13
|
-
secret;
|
|
14
|
-
country;
|
|
15
|
-
whitelist = [];
|
|
16
|
-
_cameras;
|
|
17
|
-
get cameras() {
|
|
18
|
-
return this._cameras;
|
|
19
|
-
}
|
|
20
|
-
constructor(config) {
|
|
21
|
-
this.config = config;
|
|
22
|
-
this.userId = config.home.userId;
|
|
23
|
-
this.clientId = config.home.accessId;
|
|
24
|
-
this.secret = config.home.accessKey;
|
|
25
|
-
this.nonce = CryptoJS.lib.WordArray.random(16).toString();
|
|
26
|
-
this.country = TUYA_COUNTRIES.find((value) => value.country == config.home.country);
|
|
27
|
-
this.whitelist = config.home.homeWhitelist;
|
|
28
|
-
this.client = new axios.Axios({
|
|
29
|
-
baseURL: getTuyaCloudEndpoint(this.country),
|
|
30
|
-
timeout: 5 * 1e3,
|
|
31
|
-
});
|
|
32
|
-
this._cameras = undefined;
|
|
33
|
-
}
|
|
34
|
-
async login() {
|
|
35
|
-
await this.refreshAccessTokenIfNeeded();
|
|
36
|
-
return this.isLoggedIn();
|
|
37
|
-
}
|
|
38
|
-
isLoggedIn() {
|
|
39
|
-
return this.session !== undefined && this.session.tokenExpiresAt.getTime() > Date.now();
|
|
40
|
-
}
|
|
41
|
-
// Set Device Status
|
|
42
|
-
async updateDevice(device, statuses) {
|
|
43
|
-
if (!device) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
const result = await this.post(`/v1.0/devices/${device.id}/commands`, {
|
|
47
|
-
commands: statuses,
|
|
48
|
-
});
|
|
49
|
-
return result.success && result.result;
|
|
50
|
-
}
|
|
51
|
-
// Get Homes
|
|
52
|
-
async getHomeList() {
|
|
53
|
-
const response = await this.get(`/v1.0/users/${this.userId}/homes`);
|
|
54
|
-
if (!response.success) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
return response.result;
|
|
58
|
-
}
|
|
59
|
-
async getHomeDeviceList(homeID) {
|
|
60
|
-
const response = await this.get(`/v1.0/homes/${homeID}/devices`);
|
|
61
|
-
if (!response.success) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
return response.result;
|
|
65
|
-
}
|
|
66
|
-
// Get Devices
|
|
67
|
-
async fetchDevices() {
|
|
68
|
-
const homeResponse = await this.getHomeList();
|
|
69
|
-
const cameras = [];
|
|
70
|
-
const homeIds = homeResponse.map((home) => home.home_id.toString());
|
|
71
|
-
for (const id of homeIds) {
|
|
72
|
-
if (this.whitelist.length && !this.whitelist.includes(id)) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const devices = await this.getHomeDeviceList(parseInt(id));
|
|
76
|
-
cameras.push(...devices);
|
|
77
|
-
}
|
|
78
|
-
for (const state of cameras) {
|
|
79
|
-
const response = await this.get(`/v1.0/devices/${state.id}/functions`);
|
|
80
|
-
if (!response.success) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
state.functions = response.result.functions;
|
|
84
|
-
}
|
|
85
|
-
this._cameras = cameras.filter((element) => element.category === 'sp');
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
// Camera Functions
|
|
89
|
-
async getRTSPS(camera) {
|
|
90
|
-
const response = await this.post(`/v1.0/devices/${camera.id}/stream/actions/allocate`, { type: 'rtsp' });
|
|
91
|
-
if (response.success) {
|
|
92
|
-
return {
|
|
93
|
-
url: response.result.url,
|
|
94
|
-
expires: new Date(response.t + 30 * 1000), // This will expire in 30 seconds.
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async getDeviceWebRTConfig(camera) {
|
|
102
|
-
const response = await this.get(`/v1.0/users/${this.userId}/devices/${camera.id}/webrtc-configs`);
|
|
103
|
-
return response;
|
|
104
|
-
}
|
|
105
|
-
async getWebRTCMQConfig(webRTCDeviceConfig) {
|
|
106
|
-
const response = await this.post('/v1.0/open-hub/access/config', {
|
|
107
|
-
link_id: randomBytes(8).readUInt8(),
|
|
108
|
-
uid: this.userId,
|
|
109
|
-
link_type: 'mqtt',
|
|
110
|
-
topics: 'ipc',
|
|
111
|
-
});
|
|
112
|
-
if (response.success) {
|
|
113
|
-
response.result = {
|
|
114
|
-
...response.result,
|
|
115
|
-
sink_topic: response.result.sink_topic.ipc.replace('{device_id}', webRTCDeviceConfig.id).replace('moto_id', webRTCDeviceConfig.moto_id),
|
|
116
|
-
source_topic: response.result.source_topic.ipc,
|
|
117
|
-
};
|
|
118
|
-
return response;
|
|
119
|
-
}
|
|
120
|
-
return response;
|
|
121
|
-
}
|
|
122
|
-
getSessionUserId() {
|
|
123
|
-
return this.session?.uid;
|
|
124
|
-
}
|
|
125
|
-
// Tuya IoT Cloud Requests API
|
|
126
|
-
async get(path, query = {}) {
|
|
127
|
-
return this.request('GET', path, query);
|
|
128
|
-
}
|
|
129
|
-
async post(path, body = {}) {
|
|
130
|
-
return this.request('POST', path, {}, body);
|
|
131
|
-
}
|
|
132
|
-
async request(method, path, query = {}, body = {}) {
|
|
133
|
-
if (!(await this.login())) {
|
|
134
|
-
return {
|
|
135
|
-
result: undefined,
|
|
136
|
-
success: false,
|
|
137
|
-
t: Date.now(),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
const timestamp = Date.now().toString();
|
|
141
|
-
const headers = { client_id: this.clientId };
|
|
142
|
-
const stringToSign = this.getStringToSign(method, path, query, headers, body);
|
|
143
|
-
const sign = CryptoJS.HmacSHA256(this.clientId + this.session?.accessToken + timestamp + this.nonce + stringToSign, this.secret)
|
|
144
|
-
.toString()
|
|
145
|
-
.toUpperCase();
|
|
146
|
-
const requestHeaders = {
|
|
147
|
-
client_id: this.clientId,
|
|
148
|
-
sign: sign,
|
|
149
|
-
sign_method: 'HMAC-SHA256',
|
|
150
|
-
t: timestamp,
|
|
151
|
-
access_token: this.session.accessToken,
|
|
152
|
-
'Signature-Headers': Object.keys(headers).join(':'),
|
|
153
|
-
nonce: this.nonce,
|
|
154
|
-
};
|
|
155
|
-
return this.client
|
|
156
|
-
.request({
|
|
157
|
-
method,
|
|
158
|
-
url: path,
|
|
159
|
-
data: Object.keys(body).length > 0 ? JSON.stringify(body) : undefined,
|
|
160
|
-
params: query,
|
|
161
|
-
headers: requestHeaders,
|
|
162
|
-
responseType: 'json',
|
|
163
|
-
transformResponse: (data) => JSON.parse(data),
|
|
164
|
-
})
|
|
165
|
-
.then((value) => {
|
|
166
|
-
return value.data;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
getStringToSign(method, path, query = {}, headers = {}, body = {}) {
|
|
170
|
-
const isQueryEmpty = Object.keys(query).length == 0;
|
|
171
|
-
const isHeaderEmpty = Object.keys(headers).length == 0;
|
|
172
|
-
const isBodyEmpty = Object.keys(body).length == 0;
|
|
173
|
-
const httpMethod = method.toUpperCase();
|
|
174
|
-
const url = path +
|
|
175
|
-
(isQueryEmpty
|
|
176
|
-
? ''
|
|
177
|
-
: '?' +
|
|
178
|
-
Object.keys(query)
|
|
179
|
-
.map((key) => `${key}=${query[key]}`)
|
|
180
|
-
.join('&'));
|
|
181
|
-
const contentHashed = CryptoJS.SHA256(isBodyEmpty ? '' : JSON.stringify(body)).toString();
|
|
182
|
-
const headersParsed = Object.keys(headers)
|
|
183
|
-
.map((key) => `${key}:${headers[key]}`)
|
|
184
|
-
.join('\n');
|
|
185
|
-
const headersStr = isHeaderEmpty ? '' : headersParsed + '\n';
|
|
186
|
-
const signStr = [httpMethod, contentHashed, headersStr, url].join('\n');
|
|
187
|
-
return signStr;
|
|
188
|
-
}
|
|
189
|
-
async refreshAccessTokenIfNeeded() {
|
|
190
|
-
if (this.isLoggedIn()) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
let url;
|
|
194
|
-
if (!this.session) {
|
|
195
|
-
url = '/v1.0/token?grant_type=1';
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
url = `/v1.0/token/${this.session.refreshToken}`;
|
|
199
|
-
}
|
|
200
|
-
const timestamp = new Date().getTime().toString();
|
|
201
|
-
const stringToSign = this.getStringToSign('GET', url);
|
|
202
|
-
const signString = CryptoJS.HmacSHA256(this.clientId + timestamp + stringToSign, this.secret)
|
|
203
|
-
.toString()
|
|
204
|
-
.toUpperCase();
|
|
205
|
-
const headers = {
|
|
206
|
-
t: timestamp,
|
|
207
|
-
sign_method: 'HMAC-SHA256',
|
|
208
|
-
client_id: this.clientId,
|
|
209
|
-
sign: signString,
|
|
210
|
-
};
|
|
211
|
-
const { data } = await this.client.get(url, { headers });
|
|
212
|
-
const response = JSON.parse(data);
|
|
213
|
-
if (!response.success) {
|
|
214
|
-
this.session = undefined;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
const newExpiration = new Date(Date.now() + response.result.expire_time * 1000);
|
|
218
|
-
this.session = {
|
|
219
|
-
accessToken: response.result.access_token,
|
|
220
|
-
refreshToken: response.result.refresh_token,
|
|
221
|
-
tokenExpiresAt: newExpiration,
|
|
222
|
-
uid: response.result.uid,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
//# sourceMappingURL=cloud.js.map
|
package/dist/tuya/cloud.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../src/tuya/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAclE,MAAM,OAAO,SAAS;IAkBS;IAjB7B,qBAAqB;IAEJ,KAAK,CAAS;IACvB,OAAO,GAAa,SAAS,CAAC;IAC9B,MAAM,CAAc;IAEX,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,MAAM,CAAS;IACf,OAAO,CAAuB;IAC9B,SAAS,GAAa,EAAE,CAAC;IAElC,QAAQ,CAAiC;IACjD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1D,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,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,CAAC,aAAa;gBAC3C,cAAc,EAAE,aAAa;gBAC7B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG;aACzB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/tuya/const.d.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
export interface TuyaResponse<T> {
|
|
2
|
-
success: boolean;
|
|
3
|
-
t: number;
|
|
4
|
-
result: T;
|
|
5
|
-
}
|
|
6
|
-
export interface TuyaHomeConfig {
|
|
7
|
-
geo_name: string;
|
|
8
|
-
home_id: number;
|
|
9
|
-
name: string;
|
|
10
|
-
lat: number;
|
|
11
|
-
lon: number;
|
|
12
|
-
role: string;
|
|
13
|
-
}
|
|
14
|
-
export interface TuyaDeviceConfig {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
local_key: string;
|
|
18
|
-
category: string;
|
|
19
|
-
product_id: string;
|
|
20
|
-
product_name: string;
|
|
21
|
-
sub: boolean;
|
|
22
|
-
uuid: string;
|
|
23
|
-
online: boolean;
|
|
24
|
-
icon: string;
|
|
25
|
-
ip: string;
|
|
26
|
-
time_zone: string;
|
|
27
|
-
active_time: number;
|
|
28
|
-
create_time: number;
|
|
29
|
-
update_time: number;
|
|
30
|
-
status: TuyaDeviceStatus[];
|
|
31
|
-
functions?: DeviceFunction[];
|
|
32
|
-
uid: string;
|
|
33
|
-
biz_type: number;
|
|
34
|
-
model: string;
|
|
35
|
-
owner_id: string;
|
|
36
|
-
}
|
|
37
|
-
export interface TuyaDeviceStatus {
|
|
38
|
-
code: string;
|
|
39
|
-
value: any;
|
|
40
|
-
}
|
|
41
|
-
export interface DeviceFunction {
|
|
42
|
-
code: string;
|
|
43
|
-
type: string;
|
|
44
|
-
values: string;
|
|
45
|
-
desc: string;
|
|
46
|
-
name: string;
|
|
47
|
-
}
|
|
48
|
-
export interface RTSPToken {
|
|
49
|
-
url: string;
|
|
50
|
-
expires: Date;
|
|
51
|
-
}
|
|
52
|
-
export interface MQTTConfig {
|
|
53
|
-
url: string;
|
|
54
|
-
username: string;
|
|
55
|
-
password: string;
|
|
56
|
-
client_id: string;
|
|
57
|
-
source_topic: string;
|
|
58
|
-
sink_topic: string;
|
|
59
|
-
expire_time: number;
|
|
60
|
-
}
|
|
61
|
-
export interface DeviceWebRTConfig {
|
|
62
|
-
audio_attributes: AudioAttributes;
|
|
63
|
-
auth: string;
|
|
64
|
-
id: string;
|
|
65
|
-
moto_id: string;
|
|
66
|
-
p2p_config: P2PConfig;
|
|
67
|
-
skill: string;
|
|
68
|
-
supports_webrtc: boolean;
|
|
69
|
-
vedio_clarity: number;
|
|
70
|
-
}
|
|
71
|
-
interface AudioAttributes {
|
|
72
|
-
call_mode: number[];
|
|
73
|
-
hardware_capability: number[];
|
|
74
|
-
}
|
|
75
|
-
interface P2PConfig {
|
|
76
|
-
ices: Ice[];
|
|
77
|
-
}
|
|
78
|
-
interface Ice {
|
|
79
|
-
urls: string;
|
|
80
|
-
credential?: string;
|
|
81
|
-
ttl?: number;
|
|
82
|
-
username?: string;
|
|
83
|
-
}
|
|
84
|
-
export interface WebRTCMQMessage {
|
|
85
|
-
protocol: number;
|
|
86
|
-
pv: string;
|
|
87
|
-
t: number;
|
|
88
|
-
data: {
|
|
89
|
-
header: {
|
|
90
|
-
type: 'offer' | 'answer' | 'candidate' | 'disconnect';
|
|
91
|
-
from: string;
|
|
92
|
-
to: string;
|
|
93
|
-
sub_dev_id: string;
|
|
94
|
-
sessionid: string;
|
|
95
|
-
moto_id: string;
|
|
96
|
-
tid: string;
|
|
97
|
-
};
|
|
98
|
-
msg: OfferMessage | AnswerMessage | CandidateMessage | DisconnectMessage;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
export interface OfferMessage {
|
|
102
|
-
mode: string;
|
|
103
|
-
sdp: string;
|
|
104
|
-
auth: string;
|
|
105
|
-
stream_type: number;
|
|
106
|
-
}
|
|
107
|
-
export interface AnswerMessage {
|
|
108
|
-
mode: string;
|
|
109
|
-
sdp: string;
|
|
110
|
-
stream_type: number;
|
|
111
|
-
token: Ice[];
|
|
112
|
-
replay: any;
|
|
113
|
-
}
|
|
114
|
-
export interface CandidateMessage {
|
|
115
|
-
mode: string;
|
|
116
|
-
candidate: string;
|
|
117
|
-
}
|
|
118
|
-
export interface DisconnectMessage {
|
|
119
|
-
mode: string;
|
|
120
|
-
}
|
|
121
|
-
export {};
|