Data channels
這一頁還沒有中文版,以下顯示英文原文。
A device can open two data channels. The SFU copies what the device sends to every viewer that opens them. Only the viewer that controls the device can send back.
flowchart LR
Device["Device<br/>_lossy and _reliable"] -- "copied to every viewer" --> SFU(("Realtime SFU"))
SFU --> A["Viewer A<br/>controls the device"]
SFU --> B["Viewer B<br/>waits in line"]
A -. "only the controller reaches the device" .-> SFU
SFU -.-> Device
| Label | Ordered | Retransmits | Use |
|---|---|---|---|
_lossy | no | 0 | Values you can drop, such as sensor readings |
_reliable | yes | until it arrives | Commands |
Create each channel with negotiated: true and the id from the worker. The messages are protocol.Packet from packet.proto, with the text in raw.
On the device
- Before the offer, create a negotiated channel
server-eventswith id 0. - Send the offer with
data_channels: true. - Create
_lossyand_reliablewith the ids inchannels. controltells you who controls the device.
On a viewer
The token request needs data_channels: true.
- Send
subscribewithdata: [device_id]. - Send
take_control. If someone else has control, you wait in line. - When
subscribedshowscan_reply: true, sendcontrol_readywithin 5 seconds. - Send
release_controlto give up control, or your place in line.
Control belongs to the device, not to a room. A viewer in another room of the same device can take over. When a viewer goes away for more than 30 seconds, the next viewer in line gets control.

