rebroadcast: fix bug where packet length was parsed as signed integer.

This commit is contained in:
Koushik Dutta
2022-03-02 10:33:33 -08:00
parent 2782d8cc4d
commit e217b315c2
6 changed files with 36 additions and 9 deletions

View File

@@ -109,7 +109,13 @@ export class RtspClient extends RtspBase {
async request(method: string, headers?: Headers, path?: string, body?: Buffer) {
headers = headers || {};
const line = `${method} ${this.url}${path || ''} RTSP/1.0`;
let fullUrl: string;
if (path)
fullUrl = new URL(path, this.url).toString();
else
fullUrl = this.url;
const line = `${method} ${fullUrl} RTSP/1.0`;
headers['CSeq'] = (this.cseq++).toString();
this.write(line, headers, body);

View File

@@ -15,3 +15,22 @@ export function parsePayloadTypes(sdp: string) {
videoPayloadTypes,
}
}
function getTrackId(track: string) {
if (!track)
return;
const lines = track.split('\n').map(line => line.trim());
const control = lines.find(line => line.startsWith('a=control:'));
return control?.split('a=control:')?.[1];
}
export function parseTrackIds(sdp: string) {
const tracks = sdp.split('m=');
const audioTrack = tracks.find(track => track.startsWith('audio'));
const videoTrack = tracks.find(track => track.startsWith('video'));
return {
audio: getTrackId(audioTrack),
video: getTrackId(videoTrack),
};
}