Skip to main content

RoomSessionStream

Represents a specific stream of a room session. This is an RTMP stream of the audio/video content of the room, which will be sent to an external party (e.g., to YouTube).

You can start a stream with RoomSession.startStream.

Properties

duration

Optional duration: number

Total seconds of time spent streaming, if available. This is equal to (endedAt - startedAt).


endedAt

Optional endedAt: Date

End time, if available.


id

id: string

The unique id of this stream.


roomSessionId

roomSessionId: string

The id of the room session associated to this stream.


startedAt

startedAt: Date

Start time, if available.


state

state: "streaming" | "completed"

Current state of the stream.


url

url: string

The RTMP URL of the stream.

Methods

stop

stop(): Promise<void>

Stops the stream.

Returns

Promise<void>

Example

In this example, we wait for a room to start and then start a stream in that room. We then stop the stream after 10 seconds. This example assumes that there is a RoomSession already active and that members are joining the room.

import { SignalWire } from "@signalwire/realtime-api";

// Initialize the SignalWire client
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" });

// Access video client from the main client
const videoClient = client.video;

// Setup listener for when a room starts
await videoClient.listen({
onRoomStarted: async (roomSession) => {
console.log("Room started", roomSession.displayName);

roomSession.startStream({
url: "rtmp://example.com/stream"
})

await roomSession.listen({
onStreamStarted: async (stream) => {
console.log("Stream started", stream.state);

// Wait 10 seconds and stop the stream
setTimeout(() => {
console.log("Stopping stream");
stream.stop();
}, 10000);
},
onStreamEnded: (stream) => {
console.log("Stream ended", stream.id, stream.state);
},
});
},
onRoomEnded: async (roomSession) => {
console.log("Room ended", roomSession.displayName);
}
});

Events

onStarted

RoomSessionStream({ listen: {onStarted: Callback }})

Emitted when the stream has started.

Parameters

NameTypeDescription
streamRoomSessionStreamThe stream that has started.

onEnded

RoomSessionStream({ listen: {onEnded: Callback } })

Emitted when the stream has ended.

Parameters

NameTypeDescription
streamRoomSessionStreamThe stream that has ended.