# Guide
This guide builds a first pipeline in a page, then covers the tasks that come
next: feeding audio, video and text, spreading nodes over several Workers, handling
a Worker that is lost and watching the messages. Writing a node has its own
page, [Write a browser node](write-a-node.md). How the pieces work underneath
is in [How it works](how-it-works.md); every function is in the
[API reference](api.md).
## Your first pipeline
**1. Build the bundle.** `dist/` holds a wheel of Juturna and the browser
nodes, built from checkouts of the `juturna` (3.0.0) and `juturna-nodes` (0.1.1)
repositories:
```
python3 build/build.py --juturna /path/to/juturna --nodes /path/to/juturna_nodes
```
Run it again after any change in those checkouts. `JUTURNA_REPO` and
`JUTURNA_NODES_REPO` can replace `--juturna` and `--nodes`.
**2. Serve the folder.** `serve.py` sends the isolation headers that
`SharedArrayBuffer` needs:
```
python3 serve.py 8765
```
**3. Write the page.** A module script imports the API from `src/`, builds
the pipeline, feeds it and listens to its output:
```js
import { Juturna } from './src/juturna.js';
const config = { pipeline: { name: 'demo', id: 'demo-1', folder: '/tmp/juturna/demo',
transport: 'browser',
nodes: [{ name: 'in', type: 'BrowserInput', configuration: {} },
{ name: 'out', type: 'BrowserOutput', configuration: {} }],
links: [{ from: 'in', to: 'out' }] } };
const jt = await Juturna.create();
const pipe = await jt.pipeline(config);
pipe.output('out').on('message', ({ kind, payload, meta }) => console.log(kind, meta));
pipe.onError((error) => console.error(error));
const input = pipe.input('in');
await pipe.start();
input.feed({ kind: 'audio', payload: { audio: new Float32Array(1600), sampling_rate: 16000 }, meta: { i: 0 } });
await pipe.stop();
await pipe.destroy();
jt.terminate();
```
`BrowserInput` and `BrowserOutput` are the two ends of the pipeline: what
the page feeds and what it receives. Between them go the nodes that do the
work. `Juturna.create()` takes about 3 to 4 seconds: it loads Pyodide and
installs Juturna in every Worker.
▶ Try it
`examples/microphone.html` is the same pipeline fed by
the microphone, plus an image round trip. Accept the microphone permission.
## Use the npm package
Installed from npm, the package gives a `juturna-browser` command that runs the
scripts of `build/` with python3 3.12 or later (with pip for `build`). Build a
standalone folder with the whole runtime, and fetch the third-party files of
your nodes if they declare any, into the folder your server serves:
```
npm install juturna-browser
npx juturna-browser build --plugins ./nodes --out static/juturna
npx juturna-browser vendor ./nodes --dest static/vendor
```
`static/juturna` gets `src/`, the JavaScript of the package, and `dist/`, the
bundle. Without `--juturna` and `--nodes`, `build` downloads the wheels of
Juturna 3.0.0 and juturna-nodes 0.1.1 from PyPI: the versions the JavaScript of
the package is written for. Run it again after changing a node or upgrading the
package. Only the files the build writes are replaced (the modules in `src/`; the
wheel, `wheel.txt` and `plugins.zip` in `dist/`); the rest of the folder is
left as it is. Outside a checkout, give `vendor` a `--dest`: its default,
`vendor/` of the package, would be inside `node_modules`. The nodes then load
those files from the URLs their configuration gives.
Serve the folder as static files and import it from the page. With `static/`
served at the root of the site:
```js
import { Juturna } from '/juturna/src/juturna.js';
const jt = await Juturna.create();
```
`src/` finds the bundle in `../dist/` by itself, so the page passes no `base`.
Every server that serves the page, production included, must send the two
headers that make `SharedArrayBuffer` available:
```
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
```
and the files the page loads from elsewhere must be served from the same
site (`static/vendor` above), not from another host.
With a bundler, copy the folder among the static assets the bundler serves and
publishes as they are, and import `src/juturna.js` at run time by its URL: keep
it out of the bundle, since the Worker and the bundle are found relative to
`src/juturna.js`.
`juturna-browser check ./nodes` imports your nodes with CPython, as
[Write a browser node](write-a-node.md) explains; unlike `build`, it needs
juturna and numpy installed, and a CPython of the same minor version as Pyodide
gives it the most faithful result. [examples/standalone](https://github.com/meetecho/juturna-browser/tree/main/examples/standalone)
is a working page.
## Feed audio from the microphone
The page captures the audio; `examples/microphone.html` is a complete example.
Capturing in an `AudioWorklet` and posting to a `port()` keeps the main thread
out of the way:
```js
const port = input.port(); // a MessagePort
workletNode.port.postMessage({ port }, [port]); // hand it to the worklet
// in the worklet: port.postMessage({ kind: 'audio', payload: { audio, sampling_rate: 16000 } }, [audio.buffer]);
```
Sampling rate, chunking and timestamps travel in the messages: nothing in the
nodes is configured about the page.
A node reads its configuration when it warms up. To change a value, such as
the attenuation of `denoise_dfn`, build a new pipeline:
`examples/noise-suppression` does it to process the audio it already recorded
again.
## Feed video and drop frames
A frame is an `image` message. `examples/video-blur` reads the camera with a
`