Caja de correo
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
The showcase examples (../showcase.json) each bring a real device UI: one HTML page that their device serves and the Connectivitizer app shows. The landing page of the web app and the press kit show the same pages with pretend data, so that nobody needs the hardware to see them.
stub.js is the pretend host. src/connectivitizer/scripts/build-demos.mjs writes, for every example in showcase.json, a copy of its page with stub.js and the example's ui/demo-data.js put in front of everything else, to src/connectivitizer/public/demos/<id>/ui.html. The page itself is never changed for the demo.
src/examples/<id>/
README.md what it is, what you need, how to run it, what has been tested
ui/<id>.html the device UI: one self-contained page
ui/manifest.json what the device serves as /.cz/ui.json: { "name", "entry", "version", "theme" }
ui/demo-data.js the pretend device for the demo
<device code> the sketch, script or program that serves the page and the endpointsThe build fails when a page breaks one of the first three:
src=, href= or url(...) that names another file or a web address; pictures and fonts as data: URIs or drawn in SVG, canvas or CSS.localStorage, sessionStorage or cookies. What has to be kept belongs on the device.fetch("/path") with a path, or connectivitizer.webSocket("/path"). A browser new WebSocket(...) does not reach the device.window.connectivitizer is there only in the app (and in the demo). Use it behind a check, so the page also opens in a browser straight from the device.prefers-reduced-motion.czDemo.define({
device: { name: 'greenhouse', title: 'Greenhouse' },
routes: {
'GET /state': (request, ctx) => ({ soil: 41 + Math.sin(ctx.seconds() / 20) * 6, pump: ctx.state.pump === true }),
'POST /pump': (request, ctx) => {
ctx.state.pump = request.json()?.on === true;
return { ok: true };
},
},
sockets: {
'/events': (socket, ctx) => {
const timer = setInterval(() => socket.send({ t: ctx.seconds() }), 1000);
socket.onclose = () => clearInterval(timer);
},
},
});'<METHOD> <path>' without the query. It gets request (method, path, query as URLSearchParams, headers as Headers, body as the page sent it, a Blob for a photo, text, json()) and ctx. Routes can be added and removed while the demo runs (routes['GET /entries/' + id] = …): the stub looks each request up in the object it was given.Blob or ArrayBuffer as it is, nothing as 204, and ctx.respond(status, body, headers?) for any other status. A path without a route answers 404.ctx.rand() and ctx.between(min, max) give seeded random numbers (?seed=<number> on the address chooses the sequence), ctx.seconds() the time since the demo started, and ctx.state is the demo's own memory.send(stringOrObject), close(), onmessage, onclose.npm run demos -w connectivitizer # writes public/demos/<id>/ui.html
npm run dev -w connectivitizer # then open /demos/<id>/ui.htmlThe built page also opens straight from the file system.
For a page of your own, tools/screen-preview/screen-preview.mjs (a download for customers, with this stub inside) serves it with a demo-data.js-style file, node screen-preview.mjs ui.html --fake fake-device.js, or with the requests sent to a real device, --device http://<address>, and reloads on save.