DataConnection
Wraps WebRTC's DataChannel. To get one, use peer.connect or listen for the connection event.
.send
dataConnection.send(data);
data is serialized by BinaryPack by default and sent to the remote peer.
data
You can send any type of data, including objects, strings, and blobs.
.close
dataConnection.close();
Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections.
.on
dataConnection.on(event, callback);
Set listeners for data connection events.
'data'
dataConnection.on('data', function(data) { ... });
Emitted when data is received from the remote peer.
'open'
dataConnection.on('open', function() { ... });
Emitted when the connection is established and ready-to-use.
'close'
dataConnection.on('close', function() { ... });
Emitted when either you or the remote peer closes the data connection.
'error'
dataConnection.on('error', function(err) { ... });
.dataChannel (object)
A reference to the RTCDataChannel object associated with the connection.
.label (string)
The optional label passed in or assigned by PeerJS when the connection was initiated.
.metadata
Any type of metadata associated with the connection, passed in by whoever initiated the connection.
.open (boolean)
This is true if the connection is open and ready for read/write.
.peerConnection (object)
A reference to the RTCPeerConnection object associated with the connection.
.peer (string)
The ID of the peer on the other end of this connection.
.reliable (boolean)
Whether the underlying data channels are reliable; defined when the connection was initiated.
.serialization (string)
The serialization format of the data sent over the connection. Can be binary (default), binary-utf8, json, or none.
.type (string)
For data connections, this is always 'data'.
.bufferSize (number)
The number of messages queued to be sent once the browser buffer is no longer full.