The DataChannel represents a network channel for bidirectional peer-to-peer transfers of arbitrary data. Data channels are used to send and receive text and binary data between peers in a WebRTC connection.
Returns the label that distinguishes this DataChannel from other DataChannel objects. Scripts can create multiple DataChannel objects with the same label.
Returns the ID for this DataChannel. The value is initially null if the ID was not provided at channel creation time and the DTLS role of the SCTP transport has not yet been negotiated. After the ID is set to a non-null value, it will not change.
OnMessage can currently receive messages up to 16384 bytes in size. Check out the Detach API if you need larger message sizes. Note that browser support for larger messages is also limited.
The callback function to invoke when the channel closes.
Due to backwards compatibility, there is a chance that OnClose can be called even if GracefulClose is used. If this is problematic, deregister OnClose prior to calling GracefulClose.
Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using Send() or SendText().The value does not include framing overhead incurred by the protocol or buffering done by the operating system or network hardware. The buffered amount only increases with each call to the send methods as long as the ReadyState is open. The value does not reset to zero once the channel closes.
Returns the threshold at which the bufferedAmount is considered to be low. When the bufferedAmount decreases from above this threshold to equal or below it, the OnBufferedAmountLow event fires.The threshold is initially zero on each new DataChannel, but the application may change its value at any time.
Detaches the underlying datachannel, providing an idiomatic io.ReadWriteCloser API with .Read() and .Write() methods instead of .Send() and .OnMessage().
Before calling Detach, you must enable this behavior by calling webrtc.DetachDataChannels(). Combining detached and normal data channels is not supported. This also disables the OnMessage callback.
This is only safe to call outside of DataChannel callbacks or if in a callback, in its own goroutine. Normally, close only stops writes, and graceful close will wait for reads to be finished based on underlying SCTP association closure or a SCTP reset stream from the other side.
// In a callback, use a goroutinedc.OnMessage(func(msg webrtc.DataChannelMessage) { if string(msg.Data) == "close" { go dc.GracefulClose() }})// Outside callbacks, can call directlyerr := dc.GracefulClose()if err != nil { log.Printf("Error closing: %v", err)}