Send Data
The sendData
method allows the Local Peer to send data messages to other peers in the room. It is limited to 280 characters per message.
Parameters
Name | Type | Description |
---|---|---|
to | string[] | "*" | An array of peer IDs or "*" for all peers. |
payload | string | The data message to send (limited to 1KB). |
label | string | The label of the data message. |
Events
Name | Description | Returns |
---|---|---|
receive-data | Triggered when data is received. | TDataMessage |
receive-volatile-data | Invoked when a new volatile data message is received from the other Remote Peers | { data: TDataMessage } |
Example
// Send a message to specific peers
huddleClient.localPeer.sendData({ to: ["peerID1", "peerID2"], payload: "Hello, everyone!", label: 'chat' });
// Sending message to all peers
huddleClient.localPeer.sendData({ to: "*", payload: "Hello, everyone!", label: 'greeting' });
// Listen for data messages
huddleClient.localPeer.on('receive-data', (data) => {
console.log(data);
});