Video.Client
You can use instances of this class to subscribe to video events.
Example
const video = new Video.Client({
project: "<project-id>",
token: "<project-token>"
});
video.on("room.started", async (roomSession) => {
console.log("Room started");
});
video.on("room.ended", async (roomSession) => {
console.log("Room ended");
});
const { roomSessions } = await video.getRoomSessions();
Constructors
constructor
• new Client(opts
)
Create a new Client instance.
Parameters
Name | Type | Description |
---|---|---|
opts | Object | - |
opts.project | string | SignalWire project id, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f |
opts.token | string | SignalWire project token, e.g. PT9e5660c101cd140a1c93a0197640a369cf5f16975a0079c9 |
opts.debug? | Object | - |
opts.debug.logWsTraffic? | boolean | If true , logs all WebSocket traffic. Default is false . |
Example
const video = new Video.Client({
project: "<project-id>",
token: "<project-token>",
});
Methods
disconnect
▸ disconnect(): void
Disconnects this client. The client will stop receiving events and you will need to create a new instance if you want to use it again.
Returns
void
Example
client.disconnect();
getRoomSessions
▸ getRoomSessions(): Promise<{roomSessions: RoomSession[] }>
- See RoomSession for more details.
Returns the currently active room sessions.
Returns
Promise<{roomSessions: RoomSession[] }>
- See RoomSession for more details.
Example
const video = new Video.Client({
project: "<project-id>",
token: "<project-token>",
});
const { roomSessions } = await video.getRoomSessions();
getRoomSessionById
▸ getRoomSessionById(id
): Promise<{roomSessions: RoomSession[] }>
- See RoomSession for more details.
Returns a room session given its id. Only in-progress room sessions are currently returned.
Parameters
Name | Type | Description |
---|---|---|
id | string | Id of the room session. |
Example
const video = new Video.Client({
project: "<project-id>",
token: "<project-token>",
});
const { roomSession } = await video.getRoomSessionById();
off
▸ off(event
, fn?
)
Remove an event handler.
Parameters
Name | Type | Description |
---|---|---|
event | string | Name of the event. See Events for the list of available events. |
fn? | Function | An event handler which had been previously attached. |
on
▸ on(event
, fn
)
Attaches an event handler to the specified event.
Parameters
Name | Type | Description |
---|---|---|
event | string | Name of the event. See Events for the list of available events. |
fn | Function | An event handler. |
once
▸ once(event
, fn
)
Attaches an event handler to the specified event. The handler will fire only once.
Parameters
Name | Type | Description |
---|---|---|
event | string | Name of the event. See Events for the list of available events. |
fn | Function | An event handler. |
removeAllListeners
▸ removeAllListeners(event?
)
Detaches all event listeners for the specified event.
Parameters
Name | Type | Description |
---|---|---|
event? | string | Name of the event (leave this undefined to detach listeners for all events). See Events for the list of available events. |
Events
room.ended
• room.ended(roomSession
)
Emitted when a room session ends. Your event handler receives an object which is an instance of Video.RoomSession.
const video = new Video.Client(...)
video.on('room.ended', async (roomSession) => {
console.log(roomSession.name)
})
Parameters
Name | Type |
---|---|
roomSession | RoomSession |
room.started
• room.started(roomSession
)
Emitted when a room session is started. Your event handler receives an object which is an instance of Video.RoomSession. Example:
const video = new Video.Client(...)
video.on('room.started', async (roomSession) => {
console.log(roomSession.name)
})
Parameters
Name | Type |
---|---|
roomSession | RoomSession |