mirror of
https://github.com/koush/scrypted.git
synced 2026-02-10 17:22:03 +00:00
unifi-protect: fetch talkback url on every intercom start
This commit is contained in:
4
plugins/unifi-protect/package-lock.json
generated
4
plugins/unifi-protect/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/unifi-protect",
|
||||
"version": "0.0.67",
|
||||
"version": "0.0.68",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/unifi-protect",
|
||||
"version": "0.0.67",
|
||||
"version": "0.0.68",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"@koush/unifi-protect": "^0.0.7",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/unifi-protect",
|
||||
"version": "0.0.67",
|
||||
"version": "0.0.68",
|
||||
"description": "Unifi Protect Plugin for Scrypted",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache",
|
||||
|
||||
@@ -8,6 +8,7 @@ import { createInstanceableProviderPlugin, enableInstanceableProviderMode, isIns
|
||||
import { recommendRebroadcast } from "../../rtsp/src/recommend";
|
||||
import { fitHeightToWidth } from "../../../common/src/resolution-utils";
|
||||
import { listenZero } from "../../../common/src/listen-cluster";
|
||||
import { readLength } from "../../../common/src/read-length";
|
||||
import net from 'net';
|
||||
import WS from 'ws';
|
||||
import { once } from "events";
|
||||
@@ -24,7 +25,6 @@ class UnifiCamera extends ScryptedDeviceBase implements Camera, VideoCamera, Vid
|
||||
lastMotion: number;
|
||||
lastRing: number;
|
||||
lastSeen: number;
|
||||
talkbackUrl: string;
|
||||
|
||||
constructor(protect: UnifiProtect, nativeId: string, protectCamera: Readonly<ProtectCameraConfigInterface>) {
|
||||
super(nativeId);
|
||||
@@ -281,39 +281,35 @@ class UnifiDoorbell extends UnifiCamera implements Intercom, Notifier {
|
||||
const ffmpegInput = JSON.parse(buffer.toString()) as FFMpegInput;
|
||||
|
||||
const camera = this.findCamera();
|
||||
if (!this.talkbackUrl) {
|
||||
const params = new URLSearchParams({ camera: camera.id });
|
||||
const response = await this.protect.api.loginFetch(this.protect.api.wsUrl() + "/talkback?" + params.toString());
|
||||
const tb = await response.json() as Record<string, string>;
|
||||
const params = new URLSearchParams({ camera: camera.id });
|
||||
const response = await this.protect.api.loginFetch(this.protect.api.wsUrl() + "/talkback?" + params.toString());
|
||||
const tb = await response.json() as Record<string, string>;
|
||||
|
||||
// Adjust the URL for our address.
|
||||
const tbUrl = new URL(tb.url);
|
||||
tbUrl.hostname = this.protect.getSetting('ip');
|
||||
this.talkbackUrl = tbUrl.toString();
|
||||
}
|
||||
// Adjust the URL for our address.
|
||||
const tbUrl = new URL(tb.url);
|
||||
tbUrl.hostname = this.protect.getSetting('ip');
|
||||
const talkbackUrl = tbUrl.toString();
|
||||
|
||||
const websocket = new WS(this.talkbackUrl, { rejectUnauthorized: false });
|
||||
const websocket = new WS(talkbackUrl, { rejectUnauthorized: false });
|
||||
|
||||
const server = new net.Server(async (socket) => {
|
||||
server.close();
|
||||
|
||||
this.console.log('sending audio data to', this.talkbackUrl);
|
||||
this.console.log('sending audio data to', talkbackUrl);
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
await once(socket, 'readable');
|
||||
while (true) {
|
||||
const data = socket.read();
|
||||
if (!data)
|
||||
break;
|
||||
websocket.send(data, e => {
|
||||
if (e)
|
||||
socket.destroy();
|
||||
});
|
||||
}
|
||||
const data = await readLength(socket, 1024);
|
||||
if (!data)
|
||||
break;
|
||||
websocket.send(data, e => {
|
||||
if (e)
|
||||
socket.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
finally {
|
||||
websocket.close();
|
||||
this.cp.kill();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user