Skip to content
Meshline
SDK 0.1.0-alpha.6 · GuideView source on GitHub

Quick start

Choose the packages for your runtime in the SDK overview. These commands install the current alpha packages from npm.

Install in your application

Install the core and the adapters for your runtime together.

Node.js:

npm install @meshline/sdk@alpha @meshline/storage-node@alpha @meshline/transport-node@alpha

Browser:

npm install @meshline/sdk@alpha @meshline/storage-browser@alpha

Native Expo:

npm install @meshline/sdk@alpha @meshline/expo@alpha

Expo also needs matching native dependencies, the Android compatibility command, and a rebuilt native application. Follow Expo setup.

Open a session

Supply ApplicationDependencies: a trusted NetworkContext, accountId, RelayRegistry, persistent SecretProtector, and an AccountSigner for operations requiring account authority. Read application integrations before implementing these interfaces.

Use the helper for your runtime:

Runtime Function Source
Node.js migrateAndOpenNodeClient(path, application) node.ts
Browser migrateAndOpenBrowserClient(databaseName, application) browser.ts
Expo migrateAndOpenExpoClient(databaseName, application) expo.ts

Each helper opens one database, migrates it, and initializes MeshlineClient. It returns { client, dispose }. Use a distinct database for each network, account, and local device; retain the same database and protector on restart.

Establish or resume

For explicit account establishment or device reauthorization, use this function from workflows.ts on the initialized client. Types in these excerpts are imported from @meshline/sdk; the source file includes the imports.

export async function establishAndStart(client: MeshlineClient, relayId: string) {
    await client.establishAccount({ relayId });
    await client.start();
}

Omit relayId to retain an existing route or select a verified active relay for a new account. establishAccount also authorizes a fresh installation and resumes interrupted setup; it preserves other devices and existing profile settings. On an ordinary restart with valid retained local data, call client.start() after initialization. See account establishment for device selection, explicit reauthorization, and structured failures.

Starting activates synchronization, outgoing delivery, subscriptions, and polling. Use the managers on client for application actions. Start with profiles and contacts, then direct messages.

Close the session

Use try/finally around the application's session lifetime and call await session.dispose() in the finally block. The example session disposes the client, pool, and store in order and attempts all three even if cleanup fails. Track and finish application-owned event work separately.

See lifecycle and ownership for suspension and resource management.

All guides