Skip to content

Commit

Permalink
feat(streams): allow changing the RTSP URI
Browse files Browse the repository at this point in the history
Adds a URI option to the describe method in the RTSP session.
If provided, it's used for that session instead of the URI that
was provided to the constructor. The latter now only serves as
default URI when none is provided to describe.
On teardown, the session control URL is restored to the default.

Fixes #1077
  • Loading branch information
steabert committed Jan 13, 2025
1 parent 9e1d7ed commit 1746030
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/streams/components/rtsp/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ type RtspState = 'idle' | 'playing' | 'paused'
* and sending request on the outgoing stream.
*/
export class RtspSession {
public auth?: Auth
public readonly commands: ReadableStream<Uint8Array>
public readonly demuxer: TransformStream<
Uint8Array,
RtpMessage | RtcpMessage | SdpMessage
>
public readonly commands: ReadableStream<Uint8Array>
public onRtcp?: (rtcp: Rtcp) => void
public retry = { max: 20, codes: [503] }
public auth?: Auth

private clockrates?: { [key: number]: number }
private cseq: number = 0
Expand All @@ -76,7 +76,7 @@ export class RtspSession {
private sessionId?: string
private state?: RtspState
private t0?: { [key: number]: number }
private uri: string
private defaultUri: string

/** Create a new RTSP session controller component. */
public constructor({
Expand All @@ -90,7 +90,7 @@ export class RtspSession {
}
this.sessionControlUrl = uri
this.state = 'idle'
this.uri = uri
this.defaultUri = uri

const parser = new RtspParser()
this.demuxer = new TransformStream({
Expand Down Expand Up @@ -151,11 +151,11 @@ export class RtspSession {
}

/** Send a DESCRIBE request to get a presentation description of available media . */
public async describe(): Promise<Sdp> {
public async describe(uri: string = this.defaultUri): Promise<Sdp> {
const rsp = await this.fetch(
new RtspRequestMessage({
method: 'DESCRIBE',
uri: this.sessionControlUrl,
uri,
headers: { ...this.headers.DESCRIBE },
})
)
Expand All @@ -167,7 +167,7 @@ export class RtspSession {
this.sessionControlUrl =
rsp.headers.get('Content-Base') ??
rsp.headers.get('Content-Location') ??
this.uri
uri

if (
rsp.headers.get('Content-Type') !== 'application/sdp' ||
Expand Down Expand Up @@ -317,8 +317,8 @@ export class RtspSession {
throw new Error(`response not OK: ${rsp.statusCode}`)
}

this.sessionControlUrl = this.defaultUri
this.sessionId = undefined

this.state = 'idle'
}

Expand Down

0 comments on commit 1746030

Please sign in to comment.