Skip to content

Commit

Permalink
rebroadcast: keep trying to restart rtsp server
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Jul 2, 2023
1 parent cc0283e commit 8f5e9e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions plugins/prebuffer-mixin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/prebuffer-mixin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.9.94",
"version": "0.9.95",
"description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.",
"author": "Scrypted",
"license": "Apache-2.0",
Expand Down
22 changes: 18 additions & 4 deletions plugins/prebuffer-mixin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,12 +1079,25 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid

this.delayStart();

this.startRtspServer();
(async () => {
let retry = 1000;
while (true) {
try {
await this.startRtspServer();
break;
}
catch (e) {
this.console.warn('Error starting RTSP Rebroadcast Server. Retrying shortly. If this problem persists, consider assigning a different port. This warning can be ignored if the rebroadcast URL is not in use.', e);
await sleep(retry);
retry = Math.min(60000, retry * 2);
}
}
})();

this.settingsListener = systemManager.listenDevice(this.id, ScryptedInterface.Settings, () => this.ensurePrebufferSessions());
}

startRtspServer() {
async startRtspServer() {
closeQuiet(this.rtspServer);

this.rtspServer = new net.Server(async (client) => {
Expand Down Expand Up @@ -1159,10 +1172,10 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid

this.rtspServer.listen(this.streamSettings.storageSettings.values.rebroadcastPort || 0);

once(this.rtspServer, 'listening').then(() => {
await once(this.rtspServer, 'listening').then(() => {
const port = (this.rtspServer.address() as AddressInfo).port;
this.streamSettings.storageSettings.values.rebroadcastPort = port;
})
});
}

delayStart() {
Expand Down Expand Up @@ -1490,6 +1503,7 @@ class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements Vid
}

async release() {
closeQuiet(this.rtspServer);
this.settingsListener.removeListener();
this.online = true;
super.release();
Expand Down

0 comments on commit 8f5e9e5

Please sign in to comment.