Quick Summary
You don’t need to handle different offline scenarios separately. The
The hook tracks offline sessions, handles retries, and updates your UI with the latest status. You don’t need to write complex logic for different scenarios.
useOfflineSessions() hook automatically manages everything, whether users have brief network interruptions or extended offline periods.The hook tracks offline sessions, handles retries, and updates your UI with the latest status. You don’t need to write complex logic for different scenarios.
Overview
The Suki Headless Web SDK provides a seamless offline experience for your users. It has an offline mode to keep your application working during network problems.Understanding Offline Sessions
An offline session is a recording that you have submitted but that has not yet reached the Suki backend server due to a network disconnection. The SDK detects when the device is offline and automatically queues these sessions. It distinguishes between brief hiccups and continuous outages:- Brief interruptions: The SDK handles these transparently without triggering an offline session state. It uses a 15-second buffer to handle temporary connection problems.
- Continuous disconnection: The session is marked as offline and queued for synchronization once the connection returns.
Estimated Data Usage
Audio files can be large. Use these estimates to plan for storage and bandwidth requirements:| Recording Duration | Approximate File Size |
|---|---|
| 10 minutes | ~19.2 MB |
| 30 minutes | ~57.6 MB |
Offline Sessions Hook (Recommended)
TheuseOfflineSessions hook allows you to track the progress of sessions that are waiting to sync. You use this hook to build UI elements that show the user which files are pending, uploading, or finished.
How It Works
The hook returns a reactive list of sessions and a subscription method for listening to updates.What It Returns
It returns the following values:sessions
sessions
Sessions
This is an array of all current offline sessions. The array list automatically updates whenever a session’s status changes (for example, when it moves fromsyncing to synced), so your UI always shows the latest information.Each object in the array represents a single session and contains details about its submission status.
Session Statuses
Sessions submitted while offline can have one of the following statuses that reflect their submission journey:| Session Status | Description |
|---|---|
idle | The session is queued locally and waiting for a network connection to begin uploading. |
syncing | The session is currently uploading to the Suki backend server. |
synced | The upload is complete. The Suki backend server has successfully received the audio. |
failed | The submission attempt failed. The SDK will automatically attempt to re-submit it in the background. |
on
on
On
Theon property lets you listen for session updates. You can register a function that runs automatically whenever a session’s status changes (for example, when it moves from syncing to synced).This function returns a cleanup function. You must call this function to unsubscribe from the event and prevent memory leaks.
Example Code
The following example demonstrates how to use theuseOfflineSessions hook within a React component to display the status of sessions.
React
Direct Subscription via PlatformClient (Alternative)
While we recommend using theuseOfflineSessions hook for individual components, you may sometimes need to track session updates globally, for example, for centralized logging or analytics.
In these cases, you can subscribe to events directly on the PlatformClient instance using the on method.
How It Works
You listen for theambient:offlineSessionsUpdate event. The client triggers your callback function whenever the list of offline sessions changes, providing the updated array of sessions.
Example Code
React
Troubleshooting
How do we fetch the note later?
How do we fetch the note later?
Watch for
status === 'complete' in useOfflineSessions().What if user offline for hours?
What if user offline for hours?
SDK retries every 15 minutes plus immediately when browser goes online.
Need to resubscribe after reload?
Need to resubscribe after reload?
No -
useOfflineSessions() auto-hydrates pending sessions.Is local audio cleaned up?
Is local audio cleaned up?
Yes - right after
status === 'complete'.