Skip to main content

RoomSessionPlayback

Instances of this class allow you to control (e.g., pause, resume, stop) the playback inside a room session. You can obtain instances of this class by starting a playback from the desired RoomSession (see RoomSession.play)

Properties

id
stringrequired

Unique id for this playback.

roomId
stringrequired

Id of the room associated to this playback.

roomSessionId
stringrequired

Id of the room session associated to this playback.

url
stringrequired

Url of the file reproduced by this playback.

state
"paused" | "completed" | "playing"required

Current state of the playback.

position
numberrequired

Current playback position, in milliseconds.

seekable
booleanrequired

Whether the seek functions (seek, forward, rewind) can be used for this playback.

volume
numberrequired
Default: 0

Audio volume at which the playback file is reproduced.

startedAt
Date

Start time, if available.

endedAt
Date

End time, if available.

hasEnded
booleanrequired

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

Methods

forward

forward(offset): Promise<void>

Seeks the current playback forward by the specified offset.

Parameters

offset
number
Default: 5000

Relative number of milliseconds to seek forward from the current position.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback and forward it by 10 seconds after 5 seconds. This example assumes that a RoomSession is active and 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 the video client from the SignalWire client
const videoClient = client.video

// Setup a listener for when a room starts
await videoClient.listen({
onRoomStarted: async (roomSession) => {
// Start a playback
const playback = await roomSession.play({ url: "https://cdn.signalwire.com/default-music/welcome.mp3" })

setTimeout(async () => {
// Forward the playback by 5 seconds
await playback.forward(10000)
}, 5000)
}
})

pause

pause(): Promise<void>

Pauses the playback.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback. After 5 seconds, we pause the playback. This example assumes that a RoomSession is active and 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 the video client from the SignalWire client
const videoClient = client.video

// Setup a listener for when a room starts
await videoClient.listen({
onRoomStarted: async (roomSession) => {
// Start a playback
const playback = await roomSession.play({ url: "https://cdn.signalwire.com/default-music/welcome.mp3" })

// Resume the playback after 5 seconds
setTimeout(async () => {
// Pause the playback
await playback.pause()
}, 5000)
}
})

resume

resume(): Promise<void>

Resumes the playback.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback and pause it. After 5 seconds, we resume the playback. This example assumes that a RoomSession is active and 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 the video client from the SignalWire client
const videoClient = client.video

// Setup a listener for when a room starts
await videoClient.listen({
onRoomStarted: async (roomSession) => {
// Start a playback
const playback = await roomSession.play({ url: "https://cdn.signalwire.com/default-music/welcome.mp3" })
// Pause the playback
await playback.pause()

// Resume the playback after 5 seconds
setTimeout(async () => {
// Pause the playback
await playback.resume()
}, 5000)
}
})

rewind

rewind(offset): Promise<void>

Seeks the current playback backwards by the specified offset.

Parameters

offset
number
Default: 5000

Relative number of milliseconds to seek backwards from the current position.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback. After 10 seconds, we rewind the playback by 5 seconds. This example assumes that a RoomSession is active and 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 the video client from the SignalWire client
const videoClient = client.video

// Setup a listener for when a room starts
await videoClient.listen({
onRoomStarted: async (roomSession) => {
// Start a playback
const playback = await roomSession.play({ url: "https://cdn.signalwire.com/default-music/welcome.mp3" })

setTimeout(async () => {
// Rewind the playback by 5 seconds after 10 seconds
await playback.rewind(5000)
}, 10000)
}
})

seek

seek(timecode): Promise<void>

Seeks the current playback to the specified absolute position.

Parameters

timecode
numberrequired

The absolute position in milliseconds to seek to in the playback.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback. We then seek the playback to the 30th second. This example assumes that a RoomSession is active and members are joining the room.

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

// Initialize the SignalWire client
const client = await SignalWire({ project: "Project ID Here", token: "API Token Here" })

// Access the 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);

// play wait music
await roomSession.play({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
listen: {
onStarted: (playback) => {
console.log("Playback started");
// Seek to 30 seconds
console.log("Skipping to 30 seconds");
playback.seek(30000)
},
onUpdated: (playback) => console.log("Playback updated", playback.state),
onEnded: (playback) => console.log("Playback ended", playback.state),
}
})
}
})

setVolume

setVolume(volume): Promise<void>

Sets the audio volume for the playback.

Parameters

volume
numberrequired
Default: 0

The desired volume. Values range from -50 to 50.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback. After 5 seconds, we set the volume to -50dB. This example assumes that a RoomSession is active and 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);

// play wait music
let roomPlayback = roomSession.play({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
listen: {
onStarted: () => {
console.log("Playback started");
setTimeout(() => {
roomPlayback.setVolume(-50);
}, 5000);
}
}
});
await roomSession.listen({
onMemberJoined: (member) => {
console.log("Member joined", member.name);
},
onMemberLeft: (member) => {
console.log("Member left", member.name);
},
});
},
onRoomEnded: async (roomSession) => {
console.log("Room ended", roomSession.displayName);
}
})

stop

stop(): Promise<void>

Stops the playback.

Returns

Promise<void>

Example

In this example, we wait for the RoomSession to start, then we start a playback. After 5 seconds, we stop the playback. This example assumes that a RoomSession is active and 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);

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

// play wait music
let roomPlayback = roomSession.play({
url: "https://cdn.signalwire.com/default-music/welcome.mp3",
listen: {
onStarted: () => {
console.log("Playback started");
},
onEnded: () => {
console.log("Playback ended");
},
onUpdated: (playback) => {
console.log("Playback updated", playback);
},
}
});

// wait for 5 seconds then stop the playback
setTimeout(() => {
roomPlayback.stop();
}, 5000);

await roomSession.listen({
onMemberJoined: (member) => {
console.log("Member joined", member.name);
},
onMemberLeft: (member) => {
console.log("Member left", member.name);
},
});
},
onRoomEnded: async (roomSession) => {
console.log("Room ended", roomSession.displayName);
}
});
}
});

Events

onStarted

RoomSessionPlayback(listen: {onStarted: Callback })

Emitted when the playback starts.

Parameters

playback
RoomSessionPlaybackrequired

The playback that started. See RoomSessionPlayback.

onUpdated

RoomSessionPlayback(listen: {onUpdated: Callback })

Emitted when the playback is updated.

Parameters

playback
RoomSessionPlaybackrequired

The playback that updated. See RoomSessionPlayback.

onEnded

RoomSessionPlayback(listen: {onEnded: Callback })

Emitted when the playback ends.

Parameters

playback
RoomSessionPlaybackrequired

The playback that ended. See RoomSessionPlayback.