rebroadcast: add external url request support

This commit is contained in:
Koushik Dutta
2023-02-24 18:58:28 -08:00
parent e169a6e02d
commit 1e41af77fa
4 changed files with 23 additions and 9 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.9.72",
"version": "0.9.73",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/prebuffer-mixin",
"version": "0.9.72",
"version": "0.9.73",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.9.72",
"version": "0.9.73",
"description": "Video Stream Rebroadcast, Prebuffer, and Management Plugin for Scrypted.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -1114,7 +1114,8 @@ class PrebufferSession {
return chunk;
}
const client = await listenZeroSingleClient();
const hostname = options?.route === 'external' ? '0.0.0.0' : undefined;
const client = await listenZeroSingleClient(hostname);
const rtspServerPath = '/' + crypto.randomBytes(8).toString('hex');
socketPromise = client.clientPromise.then(async (socket) => {
sdp = addTrackControls(sdp);
@@ -1148,6 +1149,19 @@ class PrebufferSession {
return socket;
})
url = client.url.replace('tcp://', 'rtsp://') + rtspServerPath;
if (hostname) {
try {
const addresses = await sdk.endpointManager.getLocalAddresses();
const [address] = addresses;
if (address) {
const u = new URL(url);
u.hostname = address;
url = u.toString();
}
}
catch (e) {
}
}
}
else {
const client = await listenZeroSingleClient();

View File

@@ -1,15 +1,15 @@
import { once } from 'events';
import net from 'net';
export async function listenZero(server: net.Server) {
server.listen(0);
export async function listenZero(server: net.Server, hostname?: string) {
server.listen(0, hostname);
await once(server, 'listening');
return (server.address() as net.AddressInfo).port;
}
export async function listenZeroSingleClient() {
export async function listenZeroSingleClient(hostname?: string) {
const server = new net.Server();
const port = await listenZero(server);
const port = await listenZero(server, hostname);
const clientPromise = new Promise<net.Socket>((resolve, reject) => {
const timeout = setTimeout(() => {
@@ -24,7 +24,7 @@ export async function listenZeroSingleClient() {
});
});
clientPromise.catch(() => {});
clientPromise.catch(() => { });
return {
server,