Watch and share a world
The live view draws a client’s world in a browser. This page shows how to watch a client on your machine, and how to share its stream.
Watch a client locally
Section titled “Watch a client locally”-
Start the dev server (
mk server) and the daemon (mk daemon). -
Start a client with the camera bundle,
packages/, built as a client bundle. The daemon API takes it in theview/ camera/ camera.ts bundlesrecord ofPOST /clients. The view’s own tests do this inpackages/:view/ test/ client.ts bundles[`view-${path.basename(entry, ".ts")}`] = yield* buildBundle(project, path.join(project, entry), "@minekube/client/prelude");const api = yield* HttpApiClient.make(Api);yield* api.clients.create({ payload: { name, server: "localhost:25569", bundles } });The camera writes the world stream to
minekube/in the client’s game directory. The daemon serves it atworld/ stream.ndjson GET /.clients/ <name>/ world -
Start the web app in
apps/web:Terminal window bun run devVite forwards
/daemonto the daemon on127.0.0.1:4775. No other site can talk to the daemon, because the browser reaches it through the dev server instead of CORS. -
Open
/watch?client=<name>on the address that Vite prints.
Share a stream
Section titled “Share a stream”mk share sends a client’s world stream to a relay, where browsers anywhere can watch it:
MINEKUBE_PUBLISH_KEY=<key> mk share <client> --relay https://games.minekube.comIt prints the address to watch, https://, and says when someone starts or stops watching.
- The key is the one the relay was deployed with. Only holders of the key can publish.
- The stream flows only while someone watches. When the first viewer arrives, the relay asks
mk sharefor a snapshot of the current world, then forwards each change. When the last viewer leaves,mk sharesends nothing but a ping now and then, to keep the connection open. - A viewer who joins late gets the snapshot from the relay, which keeps it in memory.
- Anyone with the link can watch. Choose who may watch before you share something private.
Run your own relay
Section titled “Run your own relay”The relay for streams is a Cloudflare Worker, Web, with one Durable Object Stream per stream. It also serves the web app. infra/alchemy.run.ts declares it with Alchemy:
- Put the publish key in
infra/.envasMINEKUBE_PUBLISH_KEY. The deploy binds it as a secret. - Run
bun run planininfrato see what changes, thenbun run deploy. It buildsapps/weband deploys the Worker. - Pass your Worker’s URL to
mk share --relay, or setMINEKUBE_RELAY.
alchemy dev in infra runs the same Worker locally.
Related
Section titled “Related”- Live view: how the stream and the renderer work.
- Test with bot clients: the daemon API that starts clients.
Was this helpful?
Thanks for the feedback.