Get started with the Offline Protocol SDK in 5 minutes.
Want to see a complete working example? Check out the React Native Example App that demonstrates all SDK features.
npm install @offline-protocol/mesh-sdk
cd ios && pod install # iOS onlyimport { OfflineProtocol, MessagePriority } from '@offline-protocol/mesh-sdk';
const protocol = new OfflineProtocol({
appId: 'my-app',
userId: 'current-user-id',
});
await protocol.start();const messageId = await protocol.sendMessage({
recipient: 'friend-user-id',
content: 'Hello!',
priority: MessagePriority.Medium,
});protocol.on('message_received', (event) => {
console.log(`From ${event.sender}: ${event.content}`);
// Update your UI here
});protocol.on('transport_switched', (event) => {
console.log(`Now using ${event.to}`);
});
// Fires once this device has actually been carrying traffic for other
// devices — it reports what happened, not what the device is capable of.
protocol.on('relay_promoted', () => {
console.log('This device is now relaying for the mesh!');
});No transport can observe the host's battery, so the SDK only learns it from you. Until it does, DORS energy scoring skips its battery term, the floor that stops a dying phone carrying other people's traffic never applies, and mesh forwarding runs at full effort on every device — a healthy laptop and a phone at 20% carry an equal share, rather than the laptop carrying more.
(The relay events are the exception: they report traffic this device has actually carried, so they fire with or without a battery reading.)
// On start, and again on each platform battery notification.
await protocol.setBatteryState(level, isCharging);Report isCharging where the platform provides it: a charging device is
deliberately excused the soft minBatteryForRelay floor, so sending the level
alone strips relay duty from plugged-in devices that should keep it.
That's it! Your app now works offline with automatic transport switching.
Native (no React Native) integration needs the full
ProtocolConfig, permission setup, and a call toinitializeMls(secureStorage, protocolStateStorage)with two storage providers you supply — there is no auto-initialization on the native path, and encryption is fail-closed, so sends fail until MLS is initialized. See the Android Integration Guide for the complete walkthrough — the snippet below is just the shape.
cargo build --release --target aarch64-linux-androidThis produces liboffline_protocol_uniffi.so.
Copy it into app/src/main/jniLibs/arm64-v8a/ as libuniffi_offline_protocol.so (the name
UniFFI's loader expects). The scripts/build-uniffi-android.sh helper builds every ABI and
renames automatically.
import uniffi.offline_protocol.*
// Build `config` with the full ProtocolConfig(...) — see the Android integration guide.
val protocol = OfflineProtocol(config)
protocol.start()
val messageId = protocol.sendMessage(
recipient = "friend",
content = "Hello!",
priority = MessagePriority.HIGH,
replyToMsg = null,
)Native (no React Native) integration needs the full
ProtocolConfig, permission setup, and a call toinitializeMls(secureStorage:protocolStateStorage:)with two storage providers you supply — there is no auto-initialization on the native path, and encryption is fail-closed, so sends fail until MLS is initialized. See the iOS Integration Guide for the complete walkthrough — the snippet below is just the shape.
cargo build --release --target aarch64-apple-iosThis produces liboffline_protocol_uniffi.a.
Add liboffline_protocol_uniffi.a (or the device/simulator slices from
scripts/build-uniffi-ios.sh) and the generated offline_protocol.swift to your project.
// Build `config` with the full ProtocolConfig(...) — see the iOS integration guide.
let mesh = try OfflineProtocol(config: config)
try mesh.start()
let messageId = try mesh.sendMessage(
recipient: "friend",
content: "Hello!",
priority: .high,
replyToMsg: nil
)- Upgrading - Read this first if you are moving an existing app onto the storage-split release
- React Native Example App - Complete working example
- React Native Integration Guide - Full SDK integration walkthrough
- Integration Guide - Step-by-step project setup
- API Reference
- Configuration Guide
- Reticulum Transport
- Nostr Transport
- Architecture Overview
- All Documentation
Make sure you've run:
- iOS:
cd ios && pod install - Android: Rebuild the app
Ensure libuniffi_offline_protocol.so is in the correct jniLibs folder for your architecture.
Link against the Rust static library in Xcode Build Settings.
- React Native Example App - See complete implementation
- React Native Integration Guide - Full SDK integration walkthrough
- Integration Guide - Step-by-step project setup
- GitHub Issues
- All Documentation