ring: stream import options, direct sdp usage

This commit is contained in:
Koushik Dutta
2022-03-10 09:47:47 -08:00
parent 0da966afd3
commit eae580708b
5 changed files with 106 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import net, { AddressInfo } from 'net';
import net from 'net';
import { once } from 'events';
import dgram from 'dgram';
@@ -8,6 +8,16 @@ export async function listenZero(server: net.Server) {
return (server.address() as net.AddressInfo).port;
}
export function closeQuiet(socket: dgram.Socket) {
if (!socket)
return;
try {
socket.close()
}
catch (e) {
}
}
export async function bindUdp(server: dgram.Socket, usePort: number) {
server.bind(usePort);
await once(server, 'listening');

View File

@@ -1,3 +1,11 @@
export function replacePorts(sdp: string, audioPort: number, videoPort: number) {
let outputSdp = sdp
.replace(/c=IN .*/, `c=IN IP4 127.0.0.1`)
.replace(/m=audio \d+/, `m=audio ${audioPort}`)
.replace(/m=video \d+/, `m=video ${videoPort}`);
return outputSdp;
}
export function addTrackControls(sdp: string) {
let lines = sdp.split('\n').map(line => line.trim());
lines = lines.filter(line => !line.includes('a=control:'));