The ID this peer has used to identify themselves, cross-tracker.
Store the ping timeout with each peer.
If this Peer connection has been terminated permanently.
If this Peer connection currently has an open connection.
If this Peer is currently connected, and has its internal channel open for communication.
Establish a new RTCDataChannel
A shared, unique ID to use for this channel.
Add a MediaStream or multiple MediaStreamTracks to this established connection.
This requires renegotiation, which is handled internally through a hidden DataChannel. It does not require a middleman service.
Resolves when the connection has stabilized after renegotiating the channels.
Either an existing MediaStream, or an array of MediaStreamTracks.
If media
is an array of tracks, optionally pass an existing MediaStream to add these tracks into.
A MediaStream, which contains the given tracks.
Permanently close this Peer, and kill any running background timers.
Emits a fatal Error, then terminates the Peer.
Generates an Offer object from this Peer. If one already exists, returns that instead.
This function handles all initial signaling steps, processing incoming data to establish a WebRTC Connection.
Call this function with no params to start a connection as the initiator
.
Whenever this peer emits a handshake
event, the data it produces should be relayed to the remote Peer.
Whenever the remote Peer sends handshake data, the data should be passed into this local Peer via handshake(data)
.
After an initial back-and-forth (unless Trickle ICE is enabled), no additional Handshake data should be required. Any subsequent negotiations will be handled internally via DataChannels.
The data sent from the remote peer's handshake
event, or none to initiate the handshake.
If we need to initiate the handshake.
Builds an answer in response to a connection request.
The initiator peer just needs to setRemoteDescription
this value, and the connection will be ready.
Builds a connection request.
The non-initiator should call makeAnswer
with this.
Triggered when this Peer has created a handshake packet that must be sent to the remote Peer.
If trickle ICE
is enabled, this may also contain ICE candidates.
Implementations should not worry about the content of this message, and should just relay it.
The remote peer should receive this data, then call handshake(data) with it to continue the process.
Call handshake() with no arguments to start this process on the initiator's side only.
If you are using Switchboard, these handshake events will be handled automatically for you.
A function to call, in order to unsubscribe.
Triggered when this Peer has connected. This will only ever trigger once, on the initial connect.
A function to call, in order to unsubscribe.
Triggered when this Peer's connection has become stable. This will be triggered multiple times if new Media channels are added/removed.
A function to call, in order to unsubscribe.
Triggered when this Peer's default DataChannel receives a MessageEvent.
A function to call, in order to unsubscribe.
Triggered when this Peer's default DataChannel receives a MessageEvent.
This is functionally the same as on('message'), and fires with it, except that it receives only the Event data. This callback has been implemented for better cross-compatibility.
A function to call, in order to unsubscribe.
Triggered when a new RTCDataChannel is created.
A function to call, in order to unsubscribe.
Triggered when a new MediaStream is created from the remote Peer.
A function to call, in order to unsubscribe.
Triggered when an Error is raised. This does not always mean the Peer must disconnect.
A function that can receive the Error, if any, that caused termination.
A function to call, in order to unsubscribe.
Triggered when this Peer has been closed, either locally or by the remote end. See the 'disconnect' event if you only wish to detect unexpected disconnections.
A function to call, in order to unsubscribe.
Triggered when this Peer has been unexpectedly disconnected.
A function to call, in order to unsubscribe.
Triggered when all ICE discovery finishes (or the configured timer expires).
A function to call, in order to unsubscribe.
Triggered when trickle ICE discovers another value, if trickle ICE
is enabled.
If enabled, the handshake
event already handles emitting these in the format it expects.
A function to call, in order to unsubscribe.
Same as on(), but only triggers one time & automatically cleans up.
Removes all non-permanent callbacks for the given event type, or every event type if none is given.
Remove the given data channel.
Send data to the connected Peer.
The data to send.
The channel name to use. Defaults to the "default" DataChannel created on startup.
Generated using TypeDoc
Wrapper for a Switchboard-specific Peer object, containing extra metadata from Trackers.
These are automatically created by Switchboard, and you should not attempt to manually create one.