Skip to content

Commit

Permalink
rebroadcast: move url expansion into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 1, 2023
1 parent eef67a9 commit 82fb24e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
25 changes: 25 additions & 0 deletions plugins/prebuffer-mixin/src/local-addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sdk from '@scrypted/sdk';

export async function getUrlLocalAdresses(console: Console, url: string) {
let urls: string[];
try {
const addresses = await sdk.endpointManager.getLocalAddresses();
if (addresses) {
const [address] = addresses;
if (address) {
const u = new URL(url);
u.hostname = address;
url = u.toString();
}
urls = addresses.map(address => {
const u = new URL(url);
u.hostname = address;
return u.toString();
});
}
}
catch (e) {
console.warn('Error determining external addresses. Is Scrypted Server Address configured?', e);
}
return urls;
}
21 changes: 2 additions & 19 deletions plugins/prebuffer-mixin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import semver from 'semver';
import { Duplex } from 'stream';
import { Worker } from 'worker_threads';
import { FileRtspServer } from './file-rtsp-server';
import { getUrlLocalAdresses } from './local-addresses';
import { REBROADCAST_MIXIN_INTERFACE_TOKEN } from './rebroadcast-mixin-token';
import { connectRFC4571Parser, startRFC4571Parser } from './rfc4571';
import { RtspSessionParserSpecific, startRtspSession } from './rtsp-session';
Expand Down Expand Up @@ -1154,25 +1155,7 @@ class PrebufferSession {

url = clientPromise.url;
if (hostname) {
try {
const addresses = await sdk.endpointManager.getLocalAddresses();
if (addresses) {
const [address] = addresses;
if (address) {
const u = new URL(url);
u.hostname = address;
url = u.toString();
}
urls = addresses.map(address => {
const u = new URL(url);
u.hostname = address;
return u.toString();
});
}
}
catch (e) {
this.console.warn('Error determining external addresses. Is Scrypted Server Address configured?', e);
}
urls = await getUrlLocalAdresses(this.console, url);
}
}
else {
Expand Down

0 comments on commit 82fb24e

Please sign in to comment.