Skip to main content

Realtime Client

Deprecated

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​

NameTypeDescription
eventstringName of the event. See Events for the list of available events.
fn?FunctionAn event handler which had been previously attached.

on​

â–¸ on(event, fn)

Attaches an event handler to the specified event.

Parameters​

NameTypeDescription
eventstringName of the event. See Events for the list of available events.
fnFunctionAn 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​

NameTypeDescription
eventstringName of the event. See Events for the list of available events.
fnFunctionAn event handler.

removeAllListeners​

â–¸ removeAllListeners(event?)

Detaches all event listeners for the specified event.

Parameters​

NameTypeDescription
event?stringName of the event (leave this undefined to detach listeners for all events). See Events for the list of available events.