Skip to main content

Offline and Sync

The MOSA SDK is designed with an offline-first architecture, allowing dock operations to work without internet connectivity and automatically syncing data when connectivity is restored.

Offline Behavior​

What Works Offline​

The SDK supports the following operations offline:

  • Dock Operations: Unlock and lock operations work completely offline once an unlock key is obtained
  • Session Events: All session events are queued locally for sync
  • Key Caching: Unlock keys are cached locally and can be reused until expiry
  • Session Data: Session data is stored locally and persists across app restarts

What Requires Internet​

The following operations require internet connectivity:

  • Requesting Unlock Keys: Initial key requests require backend connectivity
  • Data Sync: Syncing queued events to backend requires connectivity

Offline Limits​

  • Key Expiry: Keys expire after a certain time (each key might have different expiry time) regardless of connectivity
  • Event Queue: Events are queued locally but should be synced regularly

Sync Patterns​

Automatic Sync​

The SDK automatically syncs data when:

  1. Connectivity Restored: When internet connectivity is detected
  2. Periodic Sync: Background sync every 30 minutes (when app is active)
  3. App Launch: Sync on app launch if pending events exist

Manual Sync​

You can manually trigger sync:

lifecycleScope.launch {
sdk.forceSyncNow()
}

Sync Status​

Monitor sync status:

// Check if syncing
val isSyncing = sdk.isSyncingStateFlow().value

// Get pending events count
val pendingCount = sdk.getPendingEventsCount()

// Observe sync state
sdk.isSyncingStateFlow().collect { syncing ->
if (syncing) {
// Show sync indicator
}
}

Next Steps​


For platform-specific details, see the Platform Guides.