Run parallel streams
EXG and impedance can run at the same time, which is how you watch electrode contact without interrupting a recording. Several consumers can also read one stream.
Run EXG and impedance together
Each stream needs its own stream_id and port. The two features are independent, so the lifecycles overlap freely.
const streams = [
{ feature: "eeg", streamId: 20, port: 9020, flush: 80 },
{ feature: "impedance", streamId: 21, port: 9021, flush: 1 },
];
const results = await Promise.allSettled(
streams.map((s) =>
client.features.executeOperation(s.feature, "add_stream", {
stream: {
stream_id: s.streamId,
protocol: "websocket",
host: "127.0.0.1",
port: s.port,
elements_before_flush: s.flush,
},
})
)
);
const added = results.filter((r) => r.status === "fulfilled" && r.value.success);
console.log(`${added.length}/${streams.length} streams added`);Promise.allSettled keeps one failed stream from rejecting the batch. Promise.all would reject on the first failure and abandon the others mid-setup, leaving streams registered on the device with no local record of them.
Watch contact during a recording
The usual arrangement: EXG into storage, impedance into a contact indicator.
The indicator receives magnitudes, not ohms. Turning them into a contact verdict needs a calibration step the SDK does not provide — see Measure contact impedance.
Share one stream between consumers
Subscribing twice to the same stream costs no extra device traffic. The SDK opens one bridge subscription and fans updates out locally.
Each call returns its own subscription id. Unsubscribing the plotter leaves the recorder running; the bridge subscription is released only when the last local callback goes.
Concurrent subscribes are safe. The SDK holds a per-stream lock, so simultaneous calls still produce one bridge subscription rather than two.
Isolate a failing callback
A callback that throws is caught and logged, and the other callbacks on that stream still run. One consumer's bug cannot silence the others or end the subscription.
It does not, however, slow-path safely: a callback that blocks delays every other callback on the stream, because they share the event loop. Keep each one short.
Tear down in order
Stop every stream before unsubscribing, and remove each one.
Wait the longest drain window of the streams in play — 2 seconds when impedance is running, rather than EXG's 1.5.
Warning: Use
Promise.allSettledin teardown, notPromise.all. A rejection from one stop would skip the remaining cleanup and leave the other stream transmitting.
Watch the stream limit
Devices declare a maximum stream count in capabilities. Check it before adding streams in a loop:
Next steps
Last updated
Was this helpful?

