Refresh Session
Refreshes an active session by providing a new JWT token. This extends the session's validity without disconnecting the WebSocket or interrupting event delivery.
Prefer createSession for reconnection
If you need to recover pending events (e.g. unanswered call invites), use createSession with the previous sessionId instead. createSession replays all queued events, while refreshSession only updates the token.
Signature
// Callback version
fun refreshSession(token: String, callback: (Exception?) -> Unit)
// Suspend version
suspend fun refreshSession(token: String)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
token | String | Yes | A new valid JWT minted by your backend. Must contain the same sub (username) and application_id claims as the original session token. |
Return Type
Returns void (or Promise<void> for Web). Completion indicates the session token has been updated successfully.
Usage Example
// Callback
client.refreshSession("token") { err ->
when {
err != null -> { } // handle error
}
}
// Coroutine
try {
client.refreshSession("token")
}
catch (e:Error) {
// Handle Error in creation session
}
Errors
This method can throw the following error types:
SESSION_ERROR— no active session to refreshTOKEN_ERROR— invalid or expired tokenUNKNOWN_ERROR— any unmapped exception (e.g. session already deleted server-side)
Notes
- Use
refreshSessionto proactively update the token before it expires, avoiding a session error. - The new token must be for the same user (
subclaim) and application (application_idclaim) as the current session. - Unlike
createSession, this method does not replay queued events. If you need to recover pending call invites after a disconnect, callcreateSessionwith the previous session ID instead. - If the session has already been terminated server-side,
refreshSessionwill return an error. In that case, create a new session withcreateSession.
Related Actions
createSession— Create a new session (with optional event replay)deleteSession— End the current session