Skip to content

Type Alias: TokenProvider ​

ts
type TokenProvider = (ctx) => string | Promise<string>;

Where the next access token comes from.

A provider rather than a string, because an access token is single-use. The signaling server spends its jti on connect, and a resume needs a valid access token as well — it is what proves the identity again, so that a stolen session_id alone is worthless. A client that kept the string it connected with would be refused token_replayed on its first reconnect, which is the one moment it cannot ask a user to do anything.

So the host supplies a way to get another one. Passing a plain string still works and is right for a test or a one-shot page; it simply cannot survive a reconnect, and the SDK says so with token_required rather than looping.

A provider that throws or rejects on the first connect makes connect() (or the call() or join() that connected) reject with what it threw, unwrapped. On a reconnect, the attempt fails and is retried with backoff — the provider asked again each time — until the session's 15 minutes are spent (session_expired); close() stops it sooner.

Parameters ​

ParameterType
ctx{ identity: string | null; reason: "initial" | "reconnect"; }
ctx.identitystring | null
ctx.reason"initial" | "reconnect"

Returns ​

string | Promise<string>

Talkline documentation