Loading...
const channel = pc.createDataChannel('chat');
channel.send('hello');const channel = pc.createDataChannel('chat');
channel.addEventListener('open', () => {
channel.send('hello');
});send() throws while the channel is still connecting, so wait for the open event.
send() before the channel opens and getting an 'InvalidStateError'.open event.By default, yes: delivery is reliable and ordered. Pass ordered: false or maxRetransmits to createDataChannel() for faster, lossy delivery.
It gets the channel in the datachannel event of its RTCPeerConnection and listens for message events on it.
A data channel sends data peer to peer once signaling is done. A WebSocket always goes through a server.