Skip to content

Class: TalklineClient ​

TalklineClient — the only export a host needs: one per signed-in user, created once and kept while the page is open.

A class you instantiate, with no state at module level, so two clients in one page — two widgets, two identities in a test — are an ordinary case.

Everything the SDK sends is a request with a response, everything it raises is a TalklineError whose code is the contract, and nothing in it contains a word a user should read.

Extends ​

Constructors ​

Constructor ​

ts
new TalklineClient(opts): TalklineClient;

Parameters ​

ParameterType
optsTalklineClientOptions

Returns ​

TalklineClient

Overrides ​

Emitter.constructor

Accessors ​

activeCall ​

Get Signature ​

ts
get activeCall(): Call | null;

The current call: one placed with call(), or one ringing this client (incomingCall) — a ringing incoming call is the active call too. Once it ends it stays here, status and endReason saying how, until the next call replaces it. Null before the first.

Returns ​

Call | null


connectionState ​

Get Signature ​

ts
get connectionState(): ConnectionState;
Returns ​

ConnectionState


grants ​

Get Signature ​

ts
get grants(): Grants | null;

What the server actually granted. Render buttons from this.

Returns ​

Grants | null


localParticipant ​

Get Signature ​

ts
get localParticipant(): LocalParticipant;
Returns ​

LocalParticipant


protocol ​

Get Signature ​

ts
get protocol(): ProtocolInfo;

This build's protocol release beside the deployment's, and whether an update is due. The server's fields are empty until connected.

Returns ​

ProtocolInfo


room ​

Get Signature ​

ts
get room(): Room | null;

The room this client is seated in, or null: null until a room is joined, and null again once it is left — by leave(), or by the end of a call, on both sides of it. roomJoined and roomLeft say when. Whenever it is not null it is the same object, whose contents follow the state, so a host may hold it.

Returns ​

Room | null


session ​

Get Signature ​

ts
get session(): string | null;
Returns ​

string | null

Methods ​

call() ​

ts
call(opts): Promise<Call>;

Place a call, which creates the room for you: to the identities in to, or to a queue (its slug or id), whose members the server rings one at a time until one answers. Exactly one of the two.

Media is opened before the call is created, so the caller's tracks exist by the time the callee accepts and negotiation can start on the first RoomState rather than on a second round trip.

Refused invalid_state while this client is in a room, or entering one: leave it first.

Parameters ​

ParameterType
optsCallOptions

Returns ​

Promise<Call>


close() ​

ts
close(): Promise<void>;

Returns ​

Promise<void>


connect() ​

ts
connect(token?): Promise<void>;

Connects if it is not already connected. Idempotent, so join and call can both begin with it.

Parameters ​

ParameterType
token?TokenSource

Returns ​

Promise<void>


emit() ​

ts
emit<K>(event, ...args): void;

A throwing listener must not stop the others, and must not fail the transition that emitted the event: an exception in a host's onError handler would otherwise tear down the call it was reporting on.

Type Parameters ​

Type Parameter
K extends keyof ClientEvents

Parameters ​

ParameterType
eventK
...argsClientEvents[K]

Returns ​

void

Inherited from ​

Emitter.emit


getStats() ​

ts
getStats(): Promise<RTCStatsReport | null>;

Returns ​

Promise<RTCStatsReport | null>


join() ​

ts
join(opts?): Promise<Room>;

Join a room and take a seat in it. One round trip: the reply is the snapshot (JoinRoomResponse.state).

The room name is optional because a token may already name one — Grants.room is "a room sid or a name" — and a tenant that mints per-room tokens should not have to repeat itself. Where the token says nothing, opts.room must.

Refused invalid_state while this client is in a room, or entering one: leave it first. The join waits for that leave to be answered.

Parameters ​

ParameterType
opts{ autoSubscribe?: boolean; room?: string; token?: TokenSource; }
opts.autoSubscribe?boolean
opts.room?string
opts.token?TokenSource

Returns ​

Promise<Room>


listenerCount() ​

ts
listenerCount(event): number;

Parameters ​

ParameterType
eventkeyof ClientEvents

Returns ​

number

Inherited from ​

Emitter.listenerCount


off() ​

ts
off<K>(event, listener): void;

Type Parameters ​

Type Parameter
K extends keyof ClientEvents

Parameters ​

ParameterType
eventK
listenerListener<ClientEvents[K]>

Returns ​

void

Inherited from ​

Emitter.off


on() ​

ts
on<K>(event, listener): () => void;

Type Parameters ​

Type Parameter
K extends keyof ClientEvents

Parameters ​

ParameterType
eventK
listenerListener<ClientEvents[K]>

Returns ​

() => void

Inherited from ​

Emitter.on


once() ​

ts
once<K>(event, listener): () => void;

Type Parameters ​

Type Parameter
K extends keyof ClientEvents

Parameters ​

ParameterType
eventK
listenerListener<ClientEvents[K]>

Returns ​

() => void

Inherited from ​

Emitter.once


removeAllListeners() ​

ts
removeAllListeners(): void;

Returns ​

void

Inherited from ​

Emitter.removeAllListeners


resumeAudio() ​

ts
resumeAudio(): Promise<void>;

Retries playback of every attached element. Call it from a user gesture after needsUserGesture — Safari's autoplay block.

Returns ​

Promise<void>


setAvailability() ​

ts
setAvailability(availability): Promise<void>;

What this person chose — available, away or dnd — kept beyond the session as the identity's, and sent at once to everyone watching it. The same value your backend sets with PUT /v1/identities/{identity}: queues offer calls only to available members.

Parameters ​

ParameterType
availability"available" | "away" | "dnd"

Returns ​

Promise<void>


unwatchPresence() ​

ts
unwatchPresence(identities): Promise<void>;

Parameters ​

ParameterType
identitiesstring[]

Returns ​

Promise<void>


watchPresence() ​

ts
watchPresence(identities): Promise<PresenceInfo[]>;

Watch identities' presence: at most maxPresenceSubscriptions per session, 200 today. Resolves with each one's state now, offline included; every change after that arrives as presence. Kept across reconnects.

Parameters ​

ParameterType
identitiesstring[]

Returns ​

Promise<PresenceInfo[]>

Talkline documentation