Recover Pending Call Invites
When a user receives an inbound call invite and then refreshes the page (or restarts the app) before answering, the Client SDK can automatically re-deliver the invite — no extra API call required.
This works because the Conversation Service stores pending events for approximately 30 seconds. When you pass the previous session ID to createSession, the server replays those events into the new session and the callInvite event (or onCallInvite delegate) fires automatically.
How it works
- Persist the session ID returned by
createSession(e.g. insessionStorageon web, orUserDefaults/SharedPreferenceson mobile). - On the next load, retrieve the saved session ID and pass it back to
createSession. - Register the invite listener before calling
createSessionso it is already in place when pending events are dispatched.
30-second window
The Conversation Service retains pending events for approximately 30 seconds. If more time has passed since the original invite arrived, it will not be re-delivered.
Edge cases
- Window expired: If the 30-second retention window has passed,
createSessionstill succeeds — you get a valid session, but the pending invite is not re-delivered. The caller will have timed out or cancelled by then. - Invalid session ID: If the stored session ID is invalid or belongs to a different user, the SDK ignores it and creates a fresh session. No pending events are replayed.
- App killed vs page refresh: On web,
sessionStorageis cleared when the tab closes, so this pattern works for in-tab refreshes. For mobile app restarts, persist the session ID in durable storage (UserDefaults/SharedPreferences).
Example
client.setCallInviteListener { inviteId, from, channelType ->
println("Received call invite $inviteId from $from on $channelType")
}
val previousSessionId = store.getSessionId()
if (previousSessionId != null) {
client.createSession(jwt, previousSessionId) { error, sessionId ->
if (error != null) {
println("Failed to reconnect session: $error")
return@createSession
}
sessionId?.let(store::saveSessionId)
println("Reconnected session: $sessionId")
}
} else {
client.createSession(jwt) { error, sessionId ->
if (error != null) {
println("Failed to create session: $error")
return@createSession
}
sessionId?.let(store::saveSessionId)
println("Session created: $sessionId")
}
}