getStreams

View as Markdown

getStreams

  • getStreams(): Promise<\{ streams: RoomSessionStream \}>

Obtains a list of active streams for this RoomSession. These are RTMP streams of the audio/video content of this room, which will be sent to an external party (e.g., to YouTube).

Returns

Promise<\{ streams: RoomSessionStream \}> - See RoomSessionStream for more information.

Example

In this example, we wait for a room to start and then start a stream in that room. We then use getStreams to get the list of stream objects. We then loop through the list of streams and print out the state and id of each stream. Afterwards, we 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 // get active streams
23 const activeStreams = roomSession.getStreams();
24
25 (await activeStreams).streams.forEach((stream) => {
26 console.log(`Active Steam: ${stream.id}, ${stream.state}`);
27 });
28
29 // Wait 10 seconds and stop the stream
30
31 setTimeout(() => {
32 console.log("Stopping stream");
33 stream.stop();
34 }, 10000);
35 },
36 onStreamEnded: (stream) => {
37 console.log("Stream ended", stream.id, stream.state);
38 },
39 });
40 },
41 onRoomEnded: async (roomSession) => {
42 console.log("Room ended", roomSession.displayName);
43 }
44});