Skip to content

Commit ec2e4d6

Browse files
committed
rebroadcast: set online/offline state without prebuffer requirement
1 parent 4464444 commit ec2e4d6

File tree

6 files changed

+31
-26
lines changed

6 files changed

+31
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"scrypted.debugHost": "127.0.0.1",
2+
"scrypted.debugHost": "scrypted-nvr",
33
}

plugins/prebuffer-mixin/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/prebuffer-mixin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scrypted/prebuffer-mixin",
3-
"version": "0.10.36",
3+
"version": "0.10.37",
44
"description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.",
55
"author": "Scrypted",
66
"license": "Apache-2.0",

plugins/prebuffer-mixin/src/main.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,33 @@ class PrebufferSession {
196196
return;
197197
this.console.log(this.streamName, 'prebuffer session started');
198198
this.parserSessionPromise = this.startPrebufferSession();
199-
this.parserSessionPromise.then(pso => pso.killed.finally(() => {
200-
this.console.error(this.streamName, 'prebuffer session ended');
201-
this.parserSessionPromise = undefined;
202-
}))
199+
let active = false;
200+
this.parserSessionPromise.then(pso => {
201+
pso.once('rtsp', () => {
202+
active = true;
203+
if (!this.mixin.online)
204+
this.mixin.online = true;
205+
});
206+
207+
pso.killed.finally(() => {
208+
this.console.error(this.streamName, 'prebuffer session ended');
209+
this.parserSessionPromise = undefined;
210+
});
211+
})
203212
.catch(e => {
204213
this.console.error(this.streamName, 'prebuffer session ended with error', e);
205214
this.parserSessionPromise = undefined;
215+
216+
if (!active) {
217+
// find sessions that arent this one, and check their prebuffers to see if any data has been received.
218+
// if there's no data, then consider this camera offline.
219+
const others = [...this.mixin.sessions.values()].filter(s => s !== this);
220+
if (others.length) {
221+
const hasData = others.some(s => s.rtspPrebuffer.length);
222+
if (!hasData && this.mixin.online)
223+
this.mixin.online = false;
224+
}
225+
}
206226
});
207227
}
208228

@@ -1415,11 +1435,6 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid
14151435
}
14161436
}
14171437

1418-
if (!enabledIds.length)
1419-
this.online = true;
1420-
1421-
let active = 0;
1422-
14231438
// figure out the default stream and streams that may have been removed due to
14241439
// a config change.
14251440
const toRemove = new Set(this.sessions.keys());
@@ -1462,23 +1477,13 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid
14621477
}
14631478

14641479
session.ensurePrebufferSession();
1465-
let wasActive = false;
14661480
try {
14671481
this.console.log(name, 'prebuffer session starting');
14681482
const ps = await session.parserSessionPromise;
1469-
active++;
1470-
wasActive = true;
1471-
this.online = !!active;
14721483
await ps.killed;
14731484
}
14741485
catch (e) {
14751486
}
1476-
finally {
1477-
if (wasActive)
1478-
active--;
1479-
wasActive = false;
1480-
this.online = !!active;
1481-
}
14821487
this.console.log(this.name, 'restarting prebuffer session in 5 seconds');
14831488
await new Promise(resolve => setTimeout(resolve, 5000));
14841489
}

plugins/ring/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
{
3-
"scrypted.debugHost": "127.0.0.1",
3+
"scrypted.debugHost": "scrypted-nvr",
44
}

server/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)