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

id
stringrequired

The unique id of this stream.

roomId
stringrequired

The id of the room associated to this stream.

roomSessionId
stringrequired

The id of the room session associated to this stream.

state
"streaming" | "completed"required

Current state of the stream.

url
string

The RTMP URL of the stream.

duration
number

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

startedAt
Date

Start time, if available.

endedAt
Date

End time, if available.

hasEnded
booleanrequired

Whether the stream has ended. Returns true if the state is "completed".

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

stream
RoomSessionStreamrequired

The stream that has started. See RoomSessionStream.

onEnded

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

Emitted when the stream has ended.

Parameters

stream
RoomSessionStreamrequired

The stream that has ended. See RoomSessionStream.