Skip to content

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

ParameterTypeRequiredDescription
tokenStringYesA 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:

Notes

  • Use refreshSession to proactively update the token before it expires, avoiding a session error.
  • The new token must be for the same user (sub claim) and application (application_id claim) as the current session.
  • Unlike createSession, this method does not replay queued events. If you need to recover pending call invites after a disconnect, call createSession with the previous session ID instead.
  • If the session has already been terminated server-side, refreshSession will return an error. In that case, create a new session with createSession.

Built with VitePress.