startStream

View as Markdown

startStream

Starts streaming the audio/video of this room to an external service. You can use the returned RoomSessionStream object to interact with the stream.

Parameters

params
objectRequired

Object containing the parameters of the method.

url
stringRequired

RTMP or RTMPS url. This must be the address of a server accepting incoming RTMP/RTMPS streams.

listen
object

Object of event listeners. See RoomSessionStream Events for a list of valid events.

Returns

Promise<RoomSessionStream>

A promise that resolves to a RoomSessionStream object.

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.

1import { SignalWire } from "@signalwire/realtime-api";
2
3// Initialize the SignalWire client
4const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" });
5
6// Access video client from the main client
7const videoClient = client.video;
8
9// Setup listener for when a room starts
10await videoClient.listen({
11 onRoomStarted: async (roomSession) => {
12 console.log("Room started", roomSession.displayName);
13
14 roomSession.startStream({
15 url: "rtmp://example.com/stream"
16 })
17
18 await roomSession.listen({
19 onStreamStarted: async (stream) => {
20 console.log("Stream started", stream.state);
21
22 // Wait 10 seconds and stop the stream
23 setTimeout(() => {
24 console.log("Stopping stream");
25 stream.stop();
26 }, 10000);
27 },
28 onStreamEnded: (stream) => {
29 console.log("Stream ended", stream.id, stream.state);
30 },
31 });
32 },
33 onRoomEnded: async (roomSession) => {
34 console.log("Room ended", roomSession.displayName);
35 }
36});