diff --git a/plugins/prebuffer-mixin/.vscode/settings.json b/plugins/prebuffer-mixin/.vscode/settings.json index 79c896063..7cad3e305 100644 --- a/plugins/prebuffer-mixin/.vscode/settings.json +++ b/plugins/prebuffer-mixin/.vscode/settings.json @@ -1,3 +1,3 @@ { - "scrypted.debugHost": "127.0.0.1", + "scrypted.debugHost": "scrypted-nvr", } \ No newline at end of file diff --git a/plugins/prebuffer-mixin/package-lock.json b/plugins/prebuffer-mixin/package-lock.json index 006976d85..32b39f86b 100644 --- a/plugins/prebuffer-mixin/package-lock.json +++ b/plugins/prebuffer-mixin/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.36", + "version": "0.10.37", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.36", + "version": "0.10.37", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/prebuffer-mixin/package.json b/plugins/prebuffer-mixin/package.json index 46379a962..1313e2655 100644 --- a/plugins/prebuffer-mixin/package.json +++ b/plugins/prebuffer-mixin/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/prebuffer-mixin", - "version": "0.10.36", + "version": "0.10.37", "description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/prebuffer-mixin/src/main.ts b/plugins/prebuffer-mixin/src/main.ts index 3f670231c..c64dc9af9 100644 --- a/plugins/prebuffer-mixin/src/main.ts +++ b/plugins/prebuffer-mixin/src/main.ts @@ -196,13 +196,33 @@ class PrebufferSession { return; this.console.log(this.streamName, 'prebuffer session started'); this.parserSessionPromise = this.startPrebufferSession(); - this.parserSessionPromise.then(pso => pso.killed.finally(() => { - this.console.error(this.streamName, 'prebuffer session ended'); - this.parserSessionPromise = undefined; - })) + let active = false; + this.parserSessionPromise.then(pso => { + pso.once('rtsp', () => { + active = true; + if (!this.mixin.online) + this.mixin.online = true; + }); + + pso.killed.finally(() => { + this.console.error(this.streamName, 'prebuffer session ended'); + this.parserSessionPromise = undefined; + }); + }) .catch(e => { this.console.error(this.streamName, 'prebuffer session ended with error', e); this.parserSessionPromise = undefined; + + if (!active) { + // find sessions that arent this one, and check their prebuffers to see if any data has been received. + // if there's no data, then consider this camera offline. + const others = [...this.mixin.sessions.values()].filter(s => s !== this); + if (others.length) { + const hasData = others.some(s => s.rtspPrebuffer.length); + if (!hasData && this.mixin.online) + this.mixin.online = false; + } + } }); } @@ -1415,11 +1435,6 @@ class PrebufferMixin extends SettingsMixinDeviceBase implements Vid } } - if (!enabledIds.length) - this.online = true; - - let active = 0; - // figure out the default stream and streams that may have been removed due to // a config change. const toRemove = new Set(this.sessions.keys()); @@ -1462,23 +1477,13 @@ class PrebufferMixin extends SettingsMixinDeviceBase implements Vid } session.ensurePrebufferSession(); - let wasActive = false; try { this.console.log(name, 'prebuffer session starting'); const ps = await session.parserSessionPromise; - active++; - wasActive = true; - this.online = !!active; await ps.killed; } catch (e) { } - finally { - if (wasActive) - active--; - wasActive = false; - this.online = !!active; - } this.console.log(this.name, 'restarting prebuffer session in 5 seconds'); await new Promise(resolve => setTimeout(resolve, 5000)); } diff --git a/plugins/ring/.vscode/settings.json b/plugins/ring/.vscode/settings.json index 77ccdbd6d..a620593fa 100644 --- a/plugins/ring/.vscode/settings.json +++ b/plugins/ring/.vscode/settings.json @@ -1,4 +1,4 @@ { - "scrypted.debugHost": "127.0.0.1", + "scrypted.debugHost": "scrypted-nvr", } \ No newline at end of file diff --git a/server/package-lock.json b/server/package-lock.json index 93bd7bae2..263f99432 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.121.4", + "version": "0.121.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.121.4", + "version": "0.121.5", "hasInstallScript": true, "license": "ISC", "dependencies": {