The Client is the app’s way into ECHO. It holds the databases of the spaces you belong to, on the device, and connects them to the network so peers can replicate them.
A client acts for an identity. The identity owns the spaces it creates, and other peers recognize it when it joins theirs. A space is a database that a set of identities replicate between them, and every object lives in exactly one space. The app keeps all its records in one space, called Contacts.
Install the client.@dxos/client holds the Client, and it brings @dxos/echo with it.
In a React app, install @dxos/react-client instead and follow the React guide.
Configure the bundler. In the browser, ECHO loads WebAssembly in the page and in workers, so Vite needs vite-plugin-wasm for both. ConfigPlugin loads the client’s config from YAML files at the package root.
Vite plugins that apply to worker bundle. The plugins returned by this function
should be new instances every time it is called, because they are used for each
rolldown worker bundling process.
plugins: () => [
functionwasm(): any
wasm()],
6
},
7
});
8
@dxos/config/rollup-plugin and @dxos/config/esbuild-plugin export the same ConfigPlugin for Rollup and esbuild. Node needs no bundler setup.
Open the app’s space. The app does this in one function. new Client takes the app’s types, which the next page declares. initialize opens local storage and connects to the network. The client then needs an identity before it can create a space; HALO covers identities and devices. Last, it creates the space and waits until its database is ready.
1
/** Starts a client that knows the app's types, gives it an identity, and creates the space the app keeps its records in. */
Waits until the space is in the ready state, with database initialized.
waitUntilReady();
11
return {
client: Client
client,
space: Space
space };
12
};
13
space.db is the database the rest of the learning path reads and writes. services is for running the client somewhere other than the default, as the embeds on these pages do: each runs its clients in memory in the page.
new Client() uses built-in defaults. Pass a Config to choose where settings come from. Each source is a function from @dxos/config, and earlier sources override later ones.