pyrtc.pool
- class pyrtc.pool.Pool(name, is_async=False)
Represents a WebRTC connection pool.
- add_endpoint(transceiver)
Accepts a Transceiver and adds it to the pool as an endpoint.
- allows(endpoint)
A method which returns a boolean value telling whether the given endpoint is allowed to join this pool. Subclasses may return False in some cases, blocking certain endpoints from joining.
- broadcast(evt_type, evt_data, *exclude)
Broadcasts the specified event to all connections in the pool, except for those whose Transceiver is in
exclude
.- Parameters
evt_type (str) – The type of event to broadcast to the peers.
evt_data (dict) – The event data.
- close()
Sends a signal to close all connections in the pool, and closes the signalling channels.
- property closed
Whether this pool has been closed.
- describe(test, desc)
Sets the description of the specified connection.
- Parameters
test – The unique ID or Transceiver identifying the peer connection
desc – The description to assign to the specified endpoint. Must be a JSON-serializable dictionary or None.
- get_connection(test)
If test is a string, gets a connection by its ID. If test is a Transceiver, gets the connection associated with it. If no connection is found, None is returned.
- Parameters
test – The unique ID or transceiver associated with the desired connection.
- Returns
A dictionary with keys ‘socket’ (a Transceiver instance), ‘id’ (the unique ID), and ‘description’ (the description of the endpoint).
- get_peer_ids()
- Returns
A tuple of the IDs of all connected peers.
- Return type
tuple
- property name
The pool’s unique name.
- update()
Prunes closed connections and notifies peers of the closure.
- class pyrtc.pool.PoolManager(private=True, is_async=False)
A class responsible for managing multiple pools. An endpoint that wants access to the pool must be added to the PoolManager containing that pool in order to join it.
- add_endpoint(transceiver)
Adds an endpoint to this PoolManager. This means that this PoolManager will now handle all events received from the given endpoint:
- Parameters
transceiver (Transceiver) – The transceiver representing the connection to an endpoint.
- add_pool(pool)
Adds a pool to the list of available pools in this PoolManager.
- Parameters
pool (Pool) – The pool to add.
- close()
Closes this pool manager.
- get_connection_for(test)
Like
get_pool_for()
, but returns the connection information as a dict.- Parameters
test (Transceiver or str) – The Transceiver or connection ID.
- Returns
The connection information if it exists, otherwise None.
- Return type
dict or None
- get_pool(name)
Gets a pool by name.
- Parameters
name (str) – The name of the pool to get.
- Returns
The pool with the given name, or None if it does not exist.
- Return type
Pool or None
- get_pool_for(test)
Gets a pool by a connection identifier, either the Transceiver associated with an endpoint or the connection ID.
- Parameters
test (Transceiver or str) – The Transceiver or connection ID.
- Returns
The pool if one exists, otherwise None.
- Return type
Pool or None
- handle_event(event, source)
Handles a single event from the specified source, returning a list of messages and endpoints that should be sent in response to the event.
- Param
event
- Parameters
source (Transceiver) –
- Returns
An iterator that provides tuples in the format (destination, event_type, event_data) where destination is a
Transceiver
, event_type is a str, and event_data is a dict- Return type
iter<tuple>
- remove_pool(name)
Removes a pool from this manager. When calling this, be sure the pool has been closed, as this method does not do this automatically.
- Parameters
name (str) – The name of the pool to close.
- Returns
True if the pool exists and was removed, False otherwise.
- Return type
bool
- update()
Handles all messages from clients. Should be called soon after new data is available from any endpoint handled by this pool manager.