API reference
Safety.
DroidHub decides who can drive and enforces it at the media server. It also tells your robot what it decided, so the robot can do its part: stop.
What DroidHub guarantees
- Only the controller's connection can send data. DroidHub grants it when that identity joins, and takes it away when control moves on, the connection ends, an e-stop latches or the controller times out.
- An e-stop holds until someone clears it. While it holds, nobody can be given control and only robots can send data.
- Every change reaches your robot through the room's metadata, pushed by the media server.
What your robot does
- Acts only on input from the identity named in
controller. Cameras and other devices can send data too. - Stops when input goes quiet (400 ms is a good default), when
estopis set orcontrolleris null, and when the room disconnects. - With a control timeout, stops when the controller has sent nothing for
controlTimeoutMs, then reports it once. - With a max lag, pings the controller and holds still while the round trip is over
maxLagMs.
The robot example in Hardware & devices does all four.
Room state
Read room.metadata after connecting, and again on every RoomMetadataChanged event.
{
"droidhub": {
"v": 1,
"controller": { "identity": "operator-jane", "assignmentId": "Wc8kR…" },
"estop": null, // { at, reason } while an e-stop holds
"controlTimeoutMs": 1000, // null = off
"maxLagMs": 300 // null = off
}
}E-stop
Latching the e-stop revokes the controller, takes data permission from everyone except robots, and refuses new assignments and controller tokens with 409 estopped. Calling it again keeps the first time and reason.
| Body | Type | Description |
|---|---|---|
| reason | string | Optional, up to 200 chars. Shown to robots and in the dashboard. |
Clearing gives cameras their data permission back. Nobody holds control until you assign a controller.
In the dashboard
Every stream page has an E-stop button. Any member can press it; owners and admins clear it.Control timeout and max lag
Both are off by default. Set them on the stream; robots read them from the room state.
| Body | Type | Description |
|---|---|---|
| controlTimeoutMs | integer | null | 200–10000. How long the controller may send nothing before robots stop and control is revoked. |
| maxLagMs | integer | null | 50–10000. The longest robot-to-controller round trip robots drive with. |
The controller keeps the robot informed on data topic dh.hb, sent lossy:
| Message | From | When |
|---|---|---|
| {"hb": 42} | Controller | While it holds control. Every 250 ms covers any control timeout. |
| {"ping": 1764140000000} | Robot → controller | Every 100–250 ms while the stream has a max lag. |
| {"pong": 1764140000000} | Controller → robot | Immediately, echoing the ping's number. |
const encode = (msg) => new TextEncoder().encode(JSON.stringify(msg));
// While holding control: a heartbeat every 250 ms.
let seq = 0;
const heartbeat = setInterval(() => {
room.localParticipant.publishData(encode({ hb: ++seq }), {
reliable: false,
topic: "dh.hb",
});
}, 250);
// Echo every ping straight back to the robot that sent it.
room.on(RoomEvent.DataReceived, (payload, participant, _kind, topic) => {
if (topic !== "dh.hb" || !participant) return;
const { ping } = JSON.parse(new TextDecoder().decode(payload));
if (typeof ping !== "number") return;
room.localParticipant.publishData(encode({ pong: ping }), {
reliable: false,
topic: "dh.hb",
destinationIdentities: [participant.identity],
});
});The dashboard's drive pad does both, so you can test a robot against these policies without writing a controller.
Report a timeout
After it stops for a quiet controller, your robot reports it once per assignment. DroidHub revokes control with reason timeout. Authenticated by the stream key, like the device token exchange.
| Body | Type | Description |
|---|---|---|
| streamKeyrequired | string | The stream's dh_sk_… key. |
| identityrequired | string | controller.identity from the room state. |
| assignmentId | string | controller.assignmentId, so a newer assignment is never revoked. |
| 409 code | When |
|---|---|
| control_timeout_off | The stream has no control timeout. |
| not_current_controller | That identity doesn't hold control, or a newer assignment exists. |
| too_early | The assignment is younger than one control timeout. |
Revoke reasons
controller.revoked webhooks and safety.lastRevoke on the stream say why control ended.
| Reason | When |
|---|---|
| api | DELETE /v1/streams/:id/controller |
| dashboard | Revoke or Release in the dashboard |
| disconnected | The controller's connection ended |
| timeout | A robot reported the controller quiet |
| estop | An e-stop latched |
E-stops send stream.estopped and stream.estop_cleared. See Webhooks.