rtcpool.pool
- class Pool(base_config, signaller)
A pool of WebRTC connections. All negotiations are handled internally, and while RTCPeerConnections can be directly accessed by connection ID, this class has sufficient functionality to manage media and data channels without directly interacting with them.
Create an RTC pool from a TURN/STUN config and a signaller.
- Arguments
base_config (
Object()
) – The TURN/STUN configuration.signaller (
signalling()
) – Thesignalling()
channel.
- Pool.connections
type: array
A list of all RTCPeerConnections, each with an additional ‘uid’ attribute representing the ID of the endpoint that it is connected to.
- Pool.events
type: EventTarget
The interface for all events triggered by connections. The events which are exposed and dispatched to this EventTarget are ‘join’, ‘close’, and ‘describe.’
- Pool.id
type: string
The ID of this endpoint. Will be null if no pool has been joined successfully.
- Pool.nconnections
type: number
The number of connections open.
- Pool.add_media(medium)
Add media which will be streamed/opened on all peers, current and future.
- Arguments
medium (
RTCStream|BroadcastDataChannel()
) – An object representing media to be broadcast.
- Pool.broadcastDataChannel(label, options)
Creates an object representing a broadcast data channel. It will open a data channel with all existing peers, and any future peers that join.
- Arguments
label (
string()
) – The label to assign to the data channel(s) that are created.options (
Object()
) – The RTCDataChannel options to create the channel with.
- Pool.close(evt_type)
Closes all connections, as well as the signalling channel. Causes a ‘close’ event to be dispatched to {this.events}
- Pool.dataChannel(conn_id, label, options)
Creates a one-to-one data channel with the endpoint identified by conn_id with the given label and options.
- Arguments
conn_id (
string()
) – The ID of the connection to create a data channel for.label (
string()
) – The label to assign to the data channel.options (
Object()
) – The RTCDataChannel options to create the channel with.
- Returns
RTCDataChannel|null – - An RTCDataChannel to the desired endpoint, or null if the connection doesn’t exist.
- Pool.get_connection(uid)
Gets the RTCPeerConnection associated with the specified endpoint.
- Arguments
uid (
string()
) – The ID of the endpoint connection to get.
- Returns
RTCPeerConnection|null – The RTCPeerConnection to the desired endpoint, or null if it does not exist.
- Pool.get_description(uid)
Gets the description associated with the specified endpoint.
- Arguments
uid (
string()
) – The ID of the endpoint whose description to get.
- Returns
Object|null|undefined – The description of the endpoint, null if the description is null, and undefined if the endpoint does not exist.
- Pool.get_media()
Internally recalculates which media should be retained, and returns the list of media. Media which are removed are those which have been closed.
- Returns
array – The list of media currently being broadcast by this endpoint.
- Pool.join(pool)
Sends a ‘join’ message to the signalling server to join a pool. This method will not throw an exception, but if this endpoint is already part of one, the signalling server will return an error.
- Arguments
pool (
string()
) – The ID of the pool to join.