Lifecycle
The session lifecycle is identical to the web widget except reconnect: on mobile a dropped socket comes back as a fresh guest session, never a resume — the server binds a mobile session to the merchant, not the individual shopper, so per-subject continuity is not currently scheduled. Everything else — minimize, teardown, close codes — matches web. The single most important behavior to get right:
minimize() is UI-only — the session and WebSocket stay alive. endSession() ends the session
(sends {type:"end"}) and tears everything down. In your custom UI, wire your "collapse" control to
minimize() and your "X" to endSession().
The lifecycle table
| You do | What happens on the wire | Backend |
|---|---|---|
startSession() (React Native) · startVoiceSession() / startTextSession() (Flutter) | issue token → open WS → handshake (ready) | ready → session_state |
minimize() | nothing — UI-only collapse; WS + session stay alive, no end sent | session stays active |
restore() | nothing — un-collapse | — |
| app backgrounded | WS may drop | socket drop noted |
| → return (any time, even < 60s) | reconnect → fresh guest session — no resume, no recap | new session, bound to the merchant not the shopper |
endSession() | sends {type:"end", reason:"user_closed"} → real end + teardown | end_session(reason="client_end") |
| bot ends / fatal close | SDK emits ended / a failed state, tears down | end_session(...) |
screen unmount / destroy() | hard teardown (no end sent) | client_disconnect |
Backgrounding → fresh guest session
When the app is backgrounded the OS may drop the socket. On the mobile SDK, returning to the foreground
always starts a fresh guest session — there is no resume and no recap, even if you reconnect within
60 seconds with the same conversation_id. The server binds a mobile session to the merchant, not the
individual shopper, so per-subject continuity is not currently scheduled. The SDK still sends
your current app context on the new session (see Context enrichment); only the
prior conversation is not carried over.
The 60s Redis reattach window (reattach_session → resume, DB recap after 60s) is a web-widget behavior
— it does not apply to the mobile SDK.
This is not an end. You never send end on backgrounding.
foreground ──tap launcher──▶ session live (WS open)
│
├─ minimize() ──────────────────────────────▶ session live (UI collapsed, WS open, NO end)
│
├─ app backgrounded ──▶ WS drops ──▶ return (any time) ─▶ fresh guest session (no resume, no recap)
│
└─ endSession() ─────────────────────────────▶ {type:"end"} ─▶ real end + teardown
Availability
As on the web, the app shows its entry point only while an employee of the site is on shift. Both SDKs read
the flags for you, and MonoverseLauncher renders nothing while its channel is off.
- React Native
- Flutter
import { useMonoverseAvailability } from '@monoverse/react-native';
function ChatEntry() {
const { chat } = useMonoverseAvailability();
return chat ? <OpenChatButton /> : null;
}
client.availability holds the latest { voice, chat }, and client.onAvailabilityChange(fn) calls you on
each change. startSession() rejects with MonoverseUnavailableError, opening no socket, while chat is off.
ValueListenableBuilder<MobileAvailability?>(
valueListenable: client.availability,
builder: (context, open, _) =>
open == null || open.chat ? const ChatEntry() : const SizedBox.shrink(),
);
null means the API has not answered yet. No socket opens while chat is off; voice off opens a text session.
A client of your own reads the same flags on the wire:
- Read
availabilityfrom the token response:{ "voice": true, "chat": true, "recheck_after_seconds": 300 }. Hide the voice or the chat entry point while its flag isfalse. - After
recheck_after_seconds, re-read it fromGET /api/v1/mobile/availabilitywithAuthorization: Bearer <session_token>and your app id inX-Monoverse-App-Id(wire protocol). availabilityisnullwhen the key's connection has no site: treat the entry point as available.
Reconnect policy
The transport reconnects on transient drops with exponential backoff + jitter, capped at ≤3 attempts, then settles into a graceful state without crashing. A heartbeat ping runs about every 25s; if no pong is seen in ~30s the SDK closes and reconnects.
Fatal close codes are NOT retried — they mean the session cannot continue:
| Code | Meaning |
|---|---|
4400 | malformed request |
4401 | invalid/expired token (or key blocked by the billing kill-switch) |
4403 | app_id not allowed |
4404 | no one is on shift — silent: collapse the entry point with no error, then recheck availability |
4503 | voice provider down |
1008 | session limit |
1011 | server crash |
All other drops are reconnected (within the ≤3 cap). See the wire protocol §8.
Observing state
- React Native
- Flutter
const session = await client.startSession({ lang: 'uk' });
session.on('status', (s) => console.log(s.status)); // idle | connecting | … | ended
session.on('ended', (e) => console.log('ended:', e.reason));
session.on('error', (e) => console.warn(e.code, e.message));
session.minimize(); // UI-only — session stays alive
session.restore();
await session.endSession(); // the X — real end
await session.destroy(); // hard teardown on unmount (no end sent)
client.dispose(); // closes the session and stops every timer
final session = await client.startVoiceSession(config: const SessionConfig(lang: 'uk'));
// Coarse status, or the sealed states for richer handling.
session.status.listen((s) => print(s.name));
session.states.listen((s) {
// SessionConnecting | SessionReady | SessionReconnecting | SessionEnded | SessionFailed
});
session.minimize(); // UI-only — session stays alive
session.restore();
await session.endSession(); // the X — real end
await session.dispose(); // hard teardown
await client.destroy();
Parity note. The web widget does not yet wire an explicit "X to end" button (the backend frame exists but is unwired on web today). The mobile SDKs expose it as
endSession().