npm.io
0.10.0 • Published 3 weeks ago

@dxos/client

Licence
FSL-1.1-Apache-2.0
Version
0.10.0
Deps
38
Size
2.1 MB
Vulns
0
Weekly
0
Stars
510

@dxos/client

Core DXOS Client API.

Installation

pnpm i @dxos/client

Usage

Create a client object like this:

import { Client } from '@dxos/client';
const client = new Client();

Documentation

DXOS Resources

Contributions

Your ideas, issues, and code are most welcome. Please take a look at our community code of conduct, the issue guide, and the PR contribution guide.

License: FSL-1.1-Apache-2.0 Copyright 2022 DXOS

Worker architecture

sequenceDiagram
    participant C1 as Client 1 (Leader)
    participant Coord as Coordinator (SharedWorker)
    participant W as Worker (Dedicated)
    participant C2 as Client 2 (Follower)

    Note over C1, W: 1. Leader Initialization
    C1->>Coord: Connect
    C1->>C1: Request Leader Lock (Success)
    C1->>W: Spawn Worker
    W->>C1: msg: listening
    Note right of C1: Wait for 'listening' to ensure worker<br/>doesn't miss subsequent messages
    C1->>W: msg: init (Client1_ID)
    W->>C1: msg: ready (LivenessKey)
    C1->>Coord: msg: new-leader (Leader_ID)

    Note over C1, W: 2. Client 1 Self-Connection
    C1->>Coord: msg: request-port (Client1_ID)
    Note right of Coord: Maps Client1_ID -> C1 Port
    Coord->>C1: msg: request-port (Client1_ID)
    Note right of C1: Leader acts on request
    C1->>W: msg: start-session (Client1_ID)
    W->>C1: msg: session (Client1_ID, Ports)
    C1->>Coord: msg: provide-port (Client1_ID, Ports)
    Coord->>C1: msg: provide-port (Client1_ID, Ports)
    Note right of C1: Client 1 Services Connected

    Note over C2, W: 3. Client 2 Connection
    C2->>Coord: Connect
    C2->>C2: Request Leader Lock (Waits/Fails)
    loop Polling
        C2->>Coord: msg: request-port (Client2_ID)
    end
    Note right of Coord: Maps Client2_ID -> C2 Port
    Coord->>C1: msg: request-port (Client2_ID)
    Note right of C1: Leader acts on request
    C1->>W: msg: start-session (Client2_ID)
    W->>C1: msg: session (Client2_ID, Ports)
    C1->>Coord: msg: provide-port (Client2_ID, Ports)
    Coord->>C2: msg: provide-port (Client2_ID, Ports)
    Note right of C2: Client 2 Services Connected