Skip to content
Meshline
SDK 0.1.0-alpha.2 · 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 initial account establishment, 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 from the establishment options if the SDK should select a verified active relay. On an ordinary restart, call client.start() after initialization. An existing account route with no authorized local device requires deliberate recovery, not a second automatic establishment.

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