@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/dist/camera.js DELETED
@@ -1,247 +0,0 @@
1
- import { RTSPSingleServer, WebRTCReceiver } from '@camera.ui/rtsp';
2
- import { MediaStreamTrack, RTCPeerConnection, RTCRtpCodecParameters, RTCSessionDescription } from 'werift';
3
- import { CustomPeerConnection } from './peer.js';
4
- import { TuyaDevice } from './tuya/device.js';
5
- export class Camera extends WebRTCReceiver {
6
- cameraDevice;
7
- cloudCamera;
8
- platform;
9
- cloud;
10
- logger;
11
- cameraLogger;
12
- ffmpegPath;
13
- pc;
14
- rtspServer;
15
- motionTimeout;
16
- binaryTimeout;
17
- previousDoorbellRing;
18
- previousMotion;
19
- constructor(platform, cloud, cloudCamera, logger) {
20
- super();
21
- this.platform = platform;
22
- this.cloud = cloud;
23
- this.cloudCamera = cloudCamera;
24
- this.logger = logger;
25
- this.cameraLogger = logger;
26
- }
27
- async createCameraDevice() {
28
- await this.createRTSPServer();
29
- const sourceName = 'P2P';
30
- const streamUrls = [this.rtspServer.streamUrl];
31
- const cameraDevice = Array.from(this.platform.cameras.values()).find((camera) => camera.nativeId === this.cloudCamera.id);
32
- if (!cameraDevice) {
33
- this.logger.log('Adding camera', this.cloudCamera.name);
34
- this.cameraDevice = await this.platform.api.deviceManager.createCamera({
35
- name: this.cloudCamera.name,
36
- nativeId: this.cloudCamera.id,
37
- hasBinarySensor: TuyaDevice.isDoorbell(this.cloudCamera),
38
- hasLight: TuyaDevice.hasLightSwitch(this.cloudCamera),
39
- info: {
40
- manufacturer: 'Tuya',
41
- model: this.cloudCamera.model,
42
- serialNumber: this.cloudCamera.id,
43
- supportUrl: 'https://support.tuya.com/en/help',
44
- },
45
- sources: [
46
- {
47
- name: sourceName,
48
- roles: ['high-resolution', 'snapshot'],
49
- urls: streamUrls,
50
- },
51
- ],
52
- });
53
- }
54
- else {
55
- this.cameraDevice = cameraDevice;
56
- await this.cameraDevice.updateCameraSource(cameraDevice.streamSource._id, { urls: streamUrls });
57
- }
58
- this.cameraLogger = this.cameraDevice.logger;
59
- this.cameraDevice.setDelegate('cameraDelegate', this);
60
- const ffmpegPath = await this.platform.api.coreManager.getFFmpegPath();
61
- this.rtspServer.changeFFmpegPath(ffmpegPath);
62
- await this.cameraDevice.connect();
63
- }
64
- async onOffer(offerSdp) {
65
- this.cameraLogger.debug('Preparing stream...');
66
- let timeout;
67
- const cleanup = () => {
68
- clearTimeout(timeout);
69
- tuyaPeerConnection.onAudioRtcp.unsubscribe();
70
- tuyaPeerConnection.onVideoRtcp.unsubscribe();
71
- tuyaPeerConnection.onIceCandidate.unsubscribe();
72
- tuyaPeerConnection.close();
73
- pc.connectionStateChange.allUnsubscribe();
74
- pc.onTrack.allUnsubscribe();
75
- pc.close();
76
- this.cameraLogger.debug('Stream stopped!');
77
- };
78
- const tuyaPeerConnection = new CustomPeerConnection(this.platform, this.cameraDevice, this.cloudCamera);
79
- tuyaPeerConnection.createPeerConnection();
80
- const audioTrack = new MediaStreamTrack({ kind: 'audio' });
81
- const videoTrack = new MediaStreamTrack({ kind: 'video' });
82
- tuyaPeerConnection.onAudioRtp.subscribe((rtp) => {
83
- audioTrack.writeRtp(rtp);
84
- });
85
- tuyaPeerConnection.onVideoRtp.subscribe((rtp) => {
86
- videoTrack.writeRtp(rtp);
87
- });
88
- const pc = (this.pc = this.createPeerCoonection());
89
- pc.onIceCandidate.subscribe((candidate) => {
90
- if (candidate) {
91
- this.events.emit('candidate', candidate);
92
- }
93
- });
94
- pc.connectionStateChange.subscribe((ev) => {
95
- this.cameraLogger.debug(`connectionStateChange: ${ev}`);
96
- if (ev === 'disconnected' || ev === 'failed' || ev === 'closed') {
97
- cleanup();
98
- }
99
- if (ev === 'connecting') {
100
- timeout = setTimeout(() => {
101
- this.cameraLogger.warn('Connection timeout!');
102
- cleanup();
103
- }, 10000);
104
- }
105
- if (ev === 'connected') {
106
- this.cameraLogger.log('Stream started!');
107
- clearTimeout(timeout);
108
- }
109
- });
110
- pc.onTrack.subscribe((track) => {
111
- if (track.kind === 'audio') {
112
- track.onReceiveRtp.subscribe((rtp) => {
113
- tuyaPeerConnection.returnAudioTrack.writeRtp(rtp);
114
- });
115
- }
116
- });
117
- pc.addTransceiver(videoTrack, { direction: 'sendonly' });
118
- pc.addTransceiver(audioTrack, { direction: 'sendonly' });
119
- const offer = new RTCSessionDescription(offerSdp, 'offer');
120
- await pc.setRemoteDescription(offer);
121
- const answer = await pc.createAnswer();
122
- await pc.setLocalDescription(answer);
123
- return answer.sdp;
124
- }
125
- async onCandidate(candidate) {
126
- await this.pc?.addIceCandidate(candidate);
127
- }
128
- async snapshot() {
129
- return;
130
- }
131
- async reboot() {
132
- return;
133
- }
134
- updateState() {
135
- if (TuyaDevice.hasMotionDetection(this.cloudCamera)) {
136
- const motionDetectedStatus = TuyaDevice.getMotionDetectionStatus(this.cloudCamera);
137
- if (motionDetectedStatus) {
138
- if (!this.previousMotion) {
139
- this.previousMotion = motionDetectedStatus.value;
140
- }
141
- else if (this.previousMotion !== motionDetectedStatus.value) {
142
- this.previousMotion = motionDetectedStatus.value;
143
- this.triggerMotion();
144
- }
145
- }
146
- }
147
- if (TuyaDevice.isDoorbell(this.cloudCamera)) {
148
- const doorbellRingStatus = TuyaDevice.getDoorbellRing(this.cloudCamera);
149
- if (doorbellRingStatus) {
150
- if (!this.previousDoorbellRing) {
151
- this.previousDoorbellRing = doorbellRingStatus.value;
152
- }
153
- else if (this.previousDoorbellRing !== doorbellRingStatus.value) {
154
- this.previousDoorbellRing = doorbellRingStatus.value;
155
- this.triggerBinaryState();
156
- }
157
- }
158
- }
159
- if (TuyaDevice.hasLightSwitch(this.cloudCamera)) {
160
- const state = TuyaDevice.getLightSwitchStatus(this.cloudCamera)?.value;
161
- this.cameraDevice.updateState('light', { state: this.toBool(state) });
162
- }
163
- }
164
- triggerBinaryState() {
165
- clearTimeout(this.binaryTimeout);
166
- this.cameraDevice.updateState('doorbell', { state: true });
167
- this.binaryTimeout = setTimeout(() => {
168
- this.cameraDevice.updateState('doorbell', { state: false });
169
- }, 10 * 1000);
170
- }
171
- triggerMotion() {
172
- const timeoutCallback = () => {
173
- this.cameraDevice.updateState('motion', { state: false, detections: [] });
174
- this.motionTimeout = undefined;
175
- };
176
- if (!this.motionTimeout) {
177
- this.motionTimeout = setTimeout(timeoutCallback, 10 * 1000);
178
- this.cameraDevice.updateState('motion', { state: true, detections: [] });
179
- }
180
- else {
181
- // Cancel the timeout and start again.
182
- clearTimeout(this.motionTimeout);
183
- this.motionTimeout = setTimeout(timeoutCallback, 10 * 1000);
184
- }
185
- }
186
- async createRTSPServer() {
187
- const webrtcStreamConfig = {
188
- name: 'Tuya',
189
- receiver: this,
190
- addBackchannel: true,
191
- };
192
- const rtspStreamConfig = {
193
- name: 'Tuya',
194
- url: async () => {
195
- const rtsps = await this.platform.cloud?.getRTSPS(this.cloudCamera);
196
- if (!rtsps) {
197
- throw new Error(`Failed to capture stream for ${this.cloudCamera.name}: RTSPS link not found.`);
198
- }
199
- return rtsps.url;
200
- },
201
- };
202
- const rtspLogger = {
203
- // log: this.cameraLogger.log.bind(this.logger),
204
- warn: (...args) => {
205
- this.cameraLogger.warn(...args);
206
- },
207
- error: (...args) => {
208
- this.cameraLogger.error(...args);
209
- },
210
- // debug: this.cameraLogger.trace.bind(this.logger),
211
- };
212
- const stream = this.platform.config.home.useWebRTC ? webrtcStreamConfig : rtspStreamConfig;
213
- this.rtspServer = await RTSPSingleServer.initialize({ stream }, rtspLogger);
214
- await this.rtspServer.listen();
215
- }
216
- createPeerCoonection() {
217
- return new RTCPeerConnection({
218
- codecs: {
219
- video: [
220
- new RTCRtpCodecParameters({
221
- mimeType: 'video/H264',
222
- clockRate: 90000,
223
- payloadType: 96,
224
- rtcpFeedback: [{ type: 'transport-cc' }, { type: 'ccm', parameter: 'fir' }, { type: 'nack' }, { type: 'nack', parameter: 'pli' }, { type: 'goog-remb' }],
225
- parameters: 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f',
226
- }),
227
- ],
228
- audio: [
229
- new RTCRtpCodecParameters({
230
- mimeType: 'audio/PCMU',
231
- clockRate: 8000,
232
- channels: 1,
233
- payloadType: 0,
234
- }),
235
- ],
236
- },
237
- bundlePolicy: 'max-bundle',
238
- });
239
- }
240
- toBool(value) {
241
- if (typeof value === 'string' && value.toLowerCase() === 'false') {
242
- return false;
243
- }
244
- return !!value;
245
- }
246
- }
247
- //# sourceMappingURL=camera.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS9C,MAAM,OAAO,MAAO,SAAQ,cAAc;IACjC,YAAY,CAAgB;IAC5B,WAAW,CAAmB;IAE7B,QAAQ,CAAO;IACf,KAAK,CAAY;IACjB,MAAM,CAAgB;IACtB,YAAY,CAAgB;IAC5B,UAAU,CAAU;IAEpB,EAAE,CAAqB;IACvB,UAAU,CAAoB;IAE9B,aAAa,CAAkB;IAC/B,aAAa,CAAkB;IAC/B,oBAAoB,CAAW;IAC/B,cAAc,CAAW;IAEjC,YAAY,QAAc,EAAE,KAAgB,EAAE,WAA6B,EAAE,MAAqB;QAChG,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MA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jC,CAAC;IAEO,oBAAoB;QAC1B,OAAO,IAAI,iBAAiB,CAAC;YAC3B,MAAM,EAAE;gBACN,KAAK,EAAE;oBACL,IAAI,qBAAqB,CAAC;wBACxB,QAAQ,EAAE,YAAY;wBACtB,SAAS,EAAE,KAAK;wBAChB,WAAW,EAAE,EAAE;wBACf,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;wBACxJ,UAAU,EAAE,wEAAwE;qBACrF,CAAC;iBACH;gBACD,KAAK,EAAE;oBACL,IAAI,qBAAqB,CAAC;wBACxB,QAAQ,EAAE,YAAY;wBACtB,SAAS,EAAE,IAAI;wBACf,QAAQ,EAAE,CAAC;wBACX,WAAW,EAAE,CAAC;qBACf,CAAC;iBACH;aACF;YACD,YAAY,EAAE,YAAY;SAC3B,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,KAAc;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC;YACjE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;CACF"}
package/dist/index.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { TuyaCloud } from './tuya/cloud.js';
2
- import { TuyaPulsar } from './tuya/pulsar.js';
3
- import type { BasePlugin, CameraDevice, FormSubmitResponse, LoggerService, PluginAPI } from '@camera.ui/types';
4
- import type { Config } from './types.js';
5
- export default class Tuya implements BasePlugin {
6
- config: Config;
7
- logger: LoggerService;
8
- api: PluginAPI;
9
- cameras: Map<string, CameraDevice>;
10
- private tuyaCameras;
11
- cloud?: TuyaCloud;
12
- pulsar?: TuyaPulsar;
13
- private cleanOrphanedCamerasTimeout?;
14
- constructor(logger: LoggerService, api: PluginAPI);
15
- configureCameras(cameras: CameraDevice[]): void;
16
- onFormSubmit(actionId: string, payload: any): Promise<FormSubmitResponse | void>;
17
- private start;
18
- private stop;
19
- private connect;
20
- private handlePulsarMessage;
21
- private addOrUpdateDevice;
22
- private deviceRemoved;
23
- private checkOrphanedCameras;
24
- }
package/dist/index.js DELETED
@@ -1,225 +0,0 @@
1
- import { Camera } from './camera.js';
2
- import { TuyaCloud } from './tuya/cloud.js';
3
- import { TuyaPulsar } from './tuya/pulsar.js';
4
- import { getTuyaPulsarEndpoint, TUYA_COUNTRIES } from './tuya/utils.js';
5
- export default class Tuya {
6
- config;
7
- logger;
8
- api;
9
- cameras = new Map();
10
- tuyaCameras = new Map();
11
- cloud;
12
- pulsar;
13
- cleanOrphanedCamerasTimeout;
14
- constructor(logger, api) {
15
- this.logger = logger;
16
- this.api = api;
17
- this.config = api.configService.all();
18
- if (!this.config.home) {
19
- this.config.home = {};
20
- }
21
- this.config.home.homeWhitelist = api.configService.get('home.homeWhitelist', [], (value) => Array.isArray(value), false, true);
22
- this.api.on('finishLaunching', this.start.bind(this));
23
- this.api.on('shutdown', this.stop.bind(this));
24
- }
25
- configureCameras(cameras) {
26
- for (const camera of cameras) {
27
- this.cameras.set(camera.id, camera);
28
- }
29
- }
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- async onFormSubmit(actionId, payload) { }
32
- async start() {
33
- try {
34
- await this.connect();
35
- }
36
- catch (error) {
37
- this.logger.error('An error occured during connecting:', error);
38
- }
39
- // this.cleanOrphanedCamerasTimeout = setTimeout(() => {
40
- // this.checkOrphanedCameras();
41
- // }, 45 * 1000);
42
- }
43
- stop() {
44
- clearTimeout(this.cleanOrphanedCamerasTimeout);
45
- this.pulsar?.stop();
46
- this.cloud = undefined;
47
- this.pulsar = undefined;
48
- this.logger.log('Plugin stopped');
49
- }
50
- async connect() {
51
- try {
52
- const userId = this.config.home.userId;
53
- const accessId = this.config.home.accessId;
54
- const accessKey = this.config.home.accessKey;
55
- const country = TUYA_COUNTRIES.find((value) => value.country == this.config.home.country);
56
- const missingItems = [];
57
- if (!userId) {
58
- missingItems.push('User Id');
59
- }
60
- if (!accessId) {
61
- missingItems.push('Access Id');
62
- }
63
- if (!accessKey) {
64
- missingItems.push('Access Key');
65
- }
66
- if (!country) {
67
- missingItems.push('Country');
68
- }
69
- if (missingItems.length > 0) {
70
- this.logger.error(`You must provide your ${missingItems.join(', ')}.`);
71
- return;
72
- }
73
- if (!this.cloud) {
74
- this.cloud = new TuyaCloud(this.config);
75
- }
76
- // If it cannot fetch devices, then that means it's permission denied.
77
- // For some reason, when generating a token does not validate authorization.
78
- if (!(await this.cloud.fetchDevices())) {
79
- this.logger.error('Failed to log in with credentials. Please try again.');
80
- this.cloud = undefined;
81
- return;
82
- }
83
- this.logger.log('Successsfully logged in with credentials! Now discovering devices.');
84
- if (this.pulsar) {
85
- this.pulsar.stop();
86
- }
87
- const config = {
88
- accessId: accessId,
89
- accessKey: accessKey,
90
- url: getTuyaPulsarEndpoint(country),
91
- };
92
- this.logger.debug('Connecting to TuyaPulsar...');
93
- this.pulsar = new TuyaPulsar(config, this.logger);
94
- this.pulsar.open(() => {
95
- this.logger.log('TulsaPulse: opened connection.');
96
- });
97
- this.pulsar.message(async (ws, message) => {
98
- this.pulsar?.ackMessage(message.messageId);
99
- const tuyaDevice = await this.handlePulsarMessage(message);
100
- if (!tuyaDevice) {
101
- return;
102
- }
103
- tuyaDevice.updateState();
104
- });
105
- // this.pulsar.reconnect(() => {
106
- // this.logger.log('TuyaPulse: restarting connection.');
107
- // });
108
- // this.pulsar.close(() => {
109
- // this.logger.warn('TuyaPulse: closed connection.');
110
- // });
111
- // this.pulsar.error((ws, error) => {
112
- // // console.log('TuyaPulse: error', ws, error);
113
- // // this.logger.error(`TuyaPulse: ${error}`);
114
- // });
115
- this.pulsar.maxRetries(() => {
116
- this.logger.error('There was an error trying to connect to Message Service (TuyaPulse). Connection Max Reconnection Timed Out');
117
- });
118
- this.pulsar.start();
119
- for (const cloudCamera of this.cloud.cameras || []) {
120
- await this.addOrUpdateDevice(cloudCamera);
121
- }
122
- }
123
- catch (error) {
124
- this.logger.error('An error occured during connecting:', error);
125
- }
126
- }
127
- async handlePulsarMessage(message) {
128
- const data = message.payload.data;
129
- const { devId } = data;
130
- let refreshDevice = false;
131
- const device = this.cloud?.cameras?.find((c) => c.id === devId);
132
- const pulsarMessageLogs = ['Received new TuyaPulsar Message:'];
133
- if (data.bizCode) {
134
- if (device && (data.bizCode === 'online' || data.bizCode === 'offline')) {
135
- // Device status changed
136
- const isOnline = data.bizCode === 'online';
137
- device.online = isOnline;
138
- refreshDevice = true;
139
- pulsarMessageLogs.push(`- Changed device to ${data.bizCode} for ${device.name}`);
140
- }
141
- else if (device && data.bizCode === 'delete') {
142
- // Device needs to be deleted
143
- // - devId
144
- // - uid
145
- pulsarMessageLogs.push(`- Delete ${device.name}`);
146
- this.deviceRemoved(device);
147
- }
148
- else if (data.bizCode === 'add') {
149
- // There is a new device added, refetch
150
- pulsarMessageLogs.push(`- Add new device with devId: ${data.devId}`);
151
- this.cloud?.fetchDevices();
152
- for (const cloudCamera of this.cloud?.cameras || []) {
153
- if (this.tuyaCameras.get(cloudCamera.id)) {
154
- continue;
155
- }
156
- await this.addOrUpdateDevice(cloudCamera);
157
- }
158
- }
159
- else {
160
- pulsarMessageLogs.push(`- Unknown bizCode: ${data.bizCode} with data: ${JSON.stringify(data.bizData)}.`);
161
- }
162
- }
163
- else if (device && data.status) {
164
- const newStatus = data.status || [];
165
- pulsarMessageLogs.push(`- ${device.name} received new status updates:`);
166
- newStatus.forEach((item) => {
167
- pulsarMessageLogs.push(`\t- ${JSON.stringify(item)}`);
168
- const index = device.status.findIndex((status) => status.code == item.code);
169
- if (index !== -1) {
170
- device.status[index].value = item.value;
171
- }
172
- });
173
- refreshDevice = true;
174
- }
175
- else {
176
- pulsarMessageLogs.push(`- Unknown TuyaPulsar message received: ${JSON.stringify(data)}`);
177
- }
178
- pulsarMessageLogs.push('');
179
- this.logger.log(pulsarMessageLogs.join('\n'));
180
- if (refreshDevice) {
181
- return this.tuyaCameras.get(devId);
182
- }
183
- }
184
- async addOrUpdateDevice(cloudCamera) {
185
- try {
186
- const nativeId = cloudCamera.id;
187
- if (this.tuyaCameras.get(nativeId)) {
188
- this.logger.debug(`Device ${cloudCamera.name} already exists, skipping...`);
189
- return;
190
- }
191
- const camera = new Camera(this, this.cloud, cloudCamera, this.logger);
192
- await camera.createCameraDevice();
193
- this.cameras.set(camera.cameraDevice.id, camera.cameraDevice);
194
- this.tuyaCameras.set(nativeId, camera);
195
- this.cameras.set(camera.cameraDevice.id, camera.cameraDevice);
196
- }
197
- catch (error) {
198
- this.logger.error('Failed to create camera:', error);
199
- }
200
- }
201
- async deviceRemoved(cloudCamera) {
202
- const nativeId = cloudCamera.id;
203
- this.logger.debug(`A device has been removed: ${cloudCamera.name}`);
204
- this.tuyaCameras.delete(nativeId);
205
- this.cameras.forEach(async (cameraDevice) => {
206
- if (cameraDevice.nativeId === nativeId) {
207
- this.logger.debug(`Removing camera ${cameraDevice.name}`);
208
- this.cameras.delete(cameraDevice.id);
209
- await this.api.deviceManager.removeCameraById(cameraDevice.id);
210
- }
211
- });
212
- }
213
- async checkOrphanedCameras() {
214
- // Remove orphaned cameras
215
- for (const [cameraId, cameraDevice] of this.cameras) {
216
- const nativeId = cameraDevice.nativeId;
217
- if (!this.tuyaCameras.get(nativeId)) {
218
- this.logger.warn('Removing camera', cameraDevice.name);
219
- this.cameras.delete(cameraId);
220
- await this.api.deviceManager.removeCameraById(cameraDevice.id);
221
- }
222
- }
223
- }
224
- }
225
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM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;YACjE,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
package/dist/peer.d.ts DELETED
@@ -1,34 +0,0 @@
1
- import { ReplaySubject, Subject } from 'rxjs';
2
- import { MediaStreamTrack, RTCIceCandidate } from 'werift';
3
- import type { BasicPeerConnection, CameraDevice } from '@camera.ui/types';
4
- import type { RtcpPacket, RTCSessionDescription, RtpPacket } from 'werift';
5
- import type Tuya from './index.js';
6
- import type { TuyaDeviceConfig } from './tuya/const.js';
7
- export declare class CustomPeerConnection implements BasicPeerConnection {
8
- private pc?;
9
- private sessionId;
10
- private platform;
11
- private cameraDevice;
12
- private cloudCamera;
13
- private cameraLogger;
14
- private mqtt?;
15
- private deviceWebRTConfig?;
16
- private mqttWebRTConfig?;
17
- onAudioRtp: Subject<RtpPacket>;
18
- onAudioRtcp: Subject<RtcpPacket>;
19
- onVideoRtp: Subject<RtpPacket>;
20
- onVideoRtcp: Subject<RtcpPacket>;
21
- onIceCandidate: Subject<RTCIceCandidate>;
22
- onConnectionState: ReplaySubject<"closed" | "failed" | "disconnected" | "new" | "connecting" | "connected">;
23
- returnAudioTrack: MediaStreamTrack;
24
- constructor(platform: Tuya, cameraDevice: CameraDevice, cloudCamera: TuyaDeviceConfig);
25
- createPeerConnection(): Promise<void>;
26
- createOffer(): Promise<RTCSessionDescription>;
27
- acceptAnswer(answer: RTCSessionDescription): Promise<void>;
28
- addIceCandidate(candidate: RTCIceCandidate): Promise<void>;
29
- close(): Promise<void>;
30
- private createLocalDescription;
31
- private sendIceCandidate;
32
- private endSession;
33
- private reset;
34
- }