RealtimeClient
It's no longer needed to create the client manually. You can use the product constructors, like Video.Client, to access the same functionality.
A real-time Client. To construct an instance of this class, please use createClient.
Example usage:
import { createClient } from "@signalwire/realtime-api";
// Obtain a client:
const client = await createClient({ project, token });
// Listen on events:
client.video.on("room.started", async (room) => {});
// Connect:
await client.connect();
Properties
Methods
connect
▸ connect(): Promise<RealtimeClient>
Connects this client to the SignalWire network.
As a general best practice, it is suggested to connect the event listeners before connecting the client, so that no events are lost.
Returns
Promise<RealtimeClient>
Upon connection, asynchronously returns an instance of this same object.
Example
const client = await createClient({ project, token });
client.video.on("room.started", async (roomSession) => {}); // connect events
await client.connect();
disconnect
▸ disconnect(): void
Disconnects this client from the SignalWire network.
Returns
void
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. |
Example
In the below example, we are listening for the call.state
event and logging the current call state to the console.
This means this will be triggered every time the call state changes.
call.on("call.state", (call) => {
console.log("call state changed:", call.state);
});
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. |