IPC Messages
這一頁還沒有中文版,以下顯示英文原文。
Send data to a program on the device, and receive its answers. The device must run pi-webrtc with --enable-ipc. pi-webrtc passes the messages to a Unix socket on the device. See IPC messages in the pi-webrtc docs.
You choose the channel for each message:
reliable(the default) sends the message again until it arrives.lossymay drop the message, but has less delay.
import { ChannelRole, PiCamera } from '@mazupo/client';
const camera = new PiCamera({
uid: 'your-custom-uid',
mqttHost: 'your.mqtt.cloud',
mqttPath: '/mqtt',
mqttPort: 8084,
mqttUsername: 'hakunamatata',
mqttPassword: 'Wonderful',
stunUrls: ['stun:stun1.l.google.com:19302'],
datachannelOnly: true,
});
camera.onDatachannel = (role) => {
if (role === ChannelRole.Reliable) {
camera.sendText('Hello! this is @mazupo/client!');
}
};
camera.onMessage = (data) => {
const text = new TextDecoder('utf-8').decode(data);
console.log(text);
};
camera.connect();Use sendData() to send binary data. Messages larger than 64 KB are split into parts, and only work on reliable. See sendText.
Camera Controls
Change image controls, such as brightness and contrast, while the camera runs. This works only for libcamera cameras on a Raspberry Pi.
Gamepad
Read a gamepad in the browser, and send each reading to the device. On the device, pi-webrtc writes the gamepad state to a Unix socket as JSON lines. See Gam...

