Networking 🚧
Native Rust networking layers are still in progress. Until then, JS implementations are available.
You can attach a WebSocket sync server to a NodeJS http server like so:
import express from "express";
import { attachWebsocketServer } from "@vlcn.io/ws-server";
import * as http from "http";
const PORT = parseInt(process.env.PORT || "8080");
const app = express(); // express or whatever you use
const server = http.createServer(app);
// attach websocket server
// you can provide an optional auth handler to verify tokens from
// the client.
attachWebsocketServer(server, {
dbFolder: "./dbs",
schemaFolder: "./src/schemas",
pathPattern: /\/sync/,
});
server.listen(PORT, () =>
console.log("info", `listening on http://localhost:${PORT}!`)
);
And use it on the client:
import SyncWorker from "./sync-worker.js?worker";
import { useSync } from "@vlcn.io/react";
const worker = new SyncWorker();
function App() {
useSync({
dbname,
endpoint: "ws://localhost:8080/sync",
room,
worker,
});
}
- Check out the vlcn-vite-starter (opens in a new tab) for a complete example.
- Also the rest example (opens in a new tab) for syncing over a REST API.