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

video

video: Video

Access the Video API Consumer

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<T>(event, fn?): EmitterContract<ClientEvents>

Type parameters

NameType
Textends "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected"

Parameters

NameType
eventT
fn?(...args: ArgumentMap<ClientEvents>[Extract<T, "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected">]) => void

Returns

EmitterContract<ClientEvents>


on

on<T>(event, fn): EmitterContract<ClientEvents>

Type parameters

NameType
Textends "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected"

Parameters

NameType
eventT
fn(...args: ArgumentMap<ClientEvents>[Extract<T, "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected">]) => void

Returns

EmitterContract<ClientEvents>


once

once<T>(event, fn): EmitterContract<ClientEvents>

Type parameters

NameType
Textends "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected"

Parameters

NameType
eventT
fn(...args: ArgumentMap<ClientEvents>[Extract<T, "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected">]) => void

Returns

EmitterContract<ClientEvents>