Client
You can use instances of this class to subscribe to video events.
Video Client​
Setting up a Video Client​
To create a Video
client, you will first need to create a SignalWire Realtime-Client
. After the
SignalWire Client
is created, you can access the Video
client using the Video
namespace.
Example​
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const videoClient = client.video;
Methods​
getRoomSessions​
â–¸ getRoomSessions(): Promise
<{ roomSessions:
RoomSession[]
}>
Returns the currently active room sessions.
Returns​
Promise
<{ roomSessions:
RoomSession[]
}>
A promise that resolves to an array of RoomSession[]
objects
that can be used to access the room session's information and methods.
Example​
In this example, we get the currently active room sessions and log their names.
This example assumes that you have already active RoomSession
.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const videoClient = client.video;
const { roomSessions } = await videoClient.getRoomSessions();
console.log(roomSessions.forEach(room => console.log(room.name)));
getRoomSessionById​
â–¸ getRoomSessionById(id
): Promise
<{ roomSession:
RoomSession
}>
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​
In this example, we use the getRoomSessions
method to get
the currently active room sessions and then use the getRoomSessionById
method to get the first room session's information.
This example assumes that you have already active RoomSession
.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const videoClient = client.video;
const { roomSessions } = await videoClient.getRoomSessions();
const room = await videoClient.getRoomSessionById(roomSessions[0].id);
console.log(room.roomSession.displayName)
Returns​
Promise
<{ roomSession:
RoomSession
}>
A promise that resolves to a RoomSession
object
that can be used to access the room session's information and methods.
listen​
â–¸ listen({ event: Callback }
): Promise
<RoomSession Events
>
Listens to events on the video
client. You can use this method to listen to any of the events listed in the Events
section.
Parameters​
Name | Type | Description |
---|---|---|
params | object | |
params.EVENT | Callback | The event to listen to. List of events can be found here. Example event: (E.g: onRoomStarted) |
Returns​
Promise
<RoomSession Events
>
A promise that resolves to a RoomSession Events
object
that can be used to access the RoomSession's events.
Example​
In this example, we use the listen
method to listen to the onRoomStarted
event and log the room session's name.
This example assumes that you already have an active RoomSession
.
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
const videoClient = client.video;
await videoClient.listen({
onRoomStarted: async (room) => {
console.log("Room started", room.displayName);
},
onRoomEnded: async (room) => {
console.log("Room ended", room.displayName);
},
});
Events​
onRoomEnded​
• client.video.listen({ onRoomEnded: Callback }
)
Emitted when a room session ends. Your event handler receives an object which is an instance
of RoomSessionFullState
.
Parameters​
Name | Type |
---|---|
roomSession | RoomSession |
onRoomStarted​
• client.video.listen( { onRoomStarted: Callback }
)
Emitted when a room session is started. Your event handler receives an object
which is an instance of RoomSessionFullState
.
Parameters​
Name | Type |
---|---|
roomSession | RoomSession |