getPlaybacks

View as Markdown

getPlaybacks

Obtains a list of playbacks for the current room session.

Returns

Promise<{ playbacks: RoomSessionPlayback }>

A promise that resolves to an object containing the list of RoomSessionPlayback objects.

Example

In this example, we wait for a room to start and then start a playback in that room. When a second member joins the roomSession, we use getPlaybacks to get the list of playback objects. We then loop through the list of playbacks and print out the state, url, and id of each playback. 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 the 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 // play wait music
15 await roomSession.play({
16 url: "https://cdn.signalwire.com/default-music/welcome.mp3",
17 listen: {
18 onStarted: () => console.log("Playback started"),
19 onUpdated: (playback) => console.log("Playback updated", playback.state),
20 onEnded: () => console.log("Playback ended")
21 }
22 }).onStarted();
23
24 // Setup listener for when a member joins
25 await roomSession.listen({
26 onMemberJoined: async (member) => {
27 console.log("Member joined", member.name);
28
29 // get roomSessions playbacks
30 let roomPlaybacks = await roomSession.getPlaybacks();
31
32 // loop through playbacks and print out state, url, and id
33 roomPlaybacks.playbacks.forEach((playback) => {
34 console.log(playback.state, playback.url, playback.id);
35 });
36 },
37 onMemberLeft: (member) => {
38 console.log("Member left", member.name);
39 },
40 });
41 },
42 onRoomEnded: async (roomSession) => {
43 console.log("Room ended", roomSession.displayName);
44 }
45});