unifi-protect: fix login timeout. use rtsps by default.

This commit is contained in:
Koushik Dutta
2022-03-10 09:47:12 -08:00
parent 0e4a19b04d
commit 0da966afd3
6 changed files with 14 additions and 21 deletions

View File

@@ -10,6 +10,7 @@
"port": 10081,
"request": "attach",
"skipFiles": [
"**/plugin-remote-worker.*",
"<node_internals>/**"
],
"preLaunchTask": "scrypted: deploy+debug",

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/unifi-protect",
"version": "0.0.102",
"version": "0.0.104",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/unifi-protect",
"version": "0.0.102",
"version": "0.0.104",
"license": "Apache",
"dependencies": {
"@koush/unifi-protect": "file:../../external/unifi-protect",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/unifi-protect",
"version": "0.0.102",
"version": "0.0.104",
"description": "Unifi Protect Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",

View File

@@ -189,17 +189,6 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco
return mediaManager.createMediaObject(Buffer.from(data), 'image/jpeg');
}
getDefaultOrderedVideoStreamOptions(vsos: MediaStreamOptions[]) {
if (!vsos || !vsos.length)
return vsos;
const defaultStream = this.getDefaultStream(vsos);
if (!defaultStream)
return vsos;
vsos = vsos.filter(vso => vso.id !== defaultStream?.id);
vsos.unshift(defaultStream);
return vsos;
}
getDefaultStream(vsos: MediaStreamOptions[]) {
let defaultStreamIndex = vsos.findIndex(vso => vso.id === this.storage.getItem('defaultStream'));
if (defaultStreamIndex === -1)
@@ -309,13 +298,14 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco
const rtspChannel = camera.channels.find(check => check.id.toString() === vso.id);
const { rtspAlias } = rtspChannel;
const u = `rtsp://${this.protect.getSetting('ip')}:7447/${rtspAlias}`
const u = `rtsps://${this.protect.getSetting('ip')}:7441/${rtspAlias}`
return mediaManager.createMediaObject({
const data = Buffer.from(JSON.stringify({
url: u,
container: 'rtsp',
mediaStreamOptions: this.createMediaStreamOptions(rtspChannel),
} as MediaStreamUrl, ScryptedMimeTypes.MediaStreamUrl);
} as MediaStreamUrl));
return mediaManager.createMediaObject(data, ScryptedMimeTypes.MediaStreamUrl);
}
createMediaStreamOptions(channel: ProtectCameraChannelConfig) {
@@ -346,10 +336,10 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco
async getVideoStreamOptions(): Promise<MediaStreamOptions[]> {
const camera = this.findCamera();
const video: MediaStreamOptions[] = camera.channels
const vsos = camera.channels
.map(channel => this.createMediaStreamOptions(channel));
return this.getDefaultOrderedVideoStreamOptions(video);
return vsos;
}
async setVideoStreamOptions(options: MediaStreamOptions): Promise<void> {
@@ -361,7 +351,7 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco
const channel = camera.channels.find(channel => channel.id.toString() === options.id);
const sanitizedBitrate = Math.min(channel.maxBitrate, Math.max(channel.minBitrate, bitrate));
this.console.log('bitrate change requested', bitrate, 'clamped to', sanitizedBitrate);
this.console.log(channel.name, 'bitrate change requested', bitrate, 'clamped to', sanitizedBitrate);
channel.bitrate = sanitizedBitrate;
const cameraResult = await this.protect.api.updateCameraChannels(camera);
if (!cameraResult) {

View File

@@ -11,6 +11,7 @@ import { UnifiLock } from "./lock";
const { deviceManager } = sdk;
const filter = [
'channels',
'recordingSchedules',
'stats',
'wifiConnectionState',

View File

@@ -1,2 +1,3 @@
export * from '@koush/unifi-protect'
// export * from '@koush/unifi-protect'
export * from '@koush/unifi-protect/src/index'
// export * from '../../../external/unifi-protect/src/index'