Python Real-Time-SDK for Huddle01 dRTC Network
Project description
Huddle01 Python SDK
Overview
The Huddle01 Python SDK provides a comprehensive solution for interacting with Huddle01's infrastructure. It enables developers to build real-time communication systems with support for rooms, peers, active speakers, permissions, and WebSocket-based connections.
Features
- Access Token Management: Generate and manage access tokens for secure communication.
- Room Management: Create and manage rooms with various permissions and roles.
- Local and Remote Peers: Define and manage local and remote peers, including their producers and roles.
- WebSocket Communication: Connect to Huddle01's WebSocket server for real-time data exchange.
- Enhanced Event Handling: Utilize
EnhancedEventEmitterfor subscribing and handling events seamlessly. - Active Speaker Tracking: Manage active speakers within a room.
- Produce and Consume Media: Produce and consume media tracks like video, audio, and screen sharing.
Installation
To use the SDK, install it via pip:
pip install huddle01
Getting Started
Here's a quick example to get started:
1. Create a Huddle01 Room
Every interaction with the Huddle01 dRTC Network start with a Room, which is a container for peers and media streams.
You can read how to create a room here.
2. Create an Access Token
Generate an access token using your API key and room ID.
from huddle01.access_token import AccessToken, AccessTokenData, Role
data = AccessTokenData(
api_key="your_api_key",
room_id="room_id",
role=Role.HOST
)
token = AccessToken(data)
jwt_token = await token.to_jwt()
3. Initialize the Huddle Client
Connect to a room using the generated token.
from huddle01.huddle_client import HuddleClient, HuddleClientOptions
options = HuddleClientOptions(autoConsume=True)
client = HuddleClient(project_id="project_id", options=options)
room = await client.create(room_id="room_id", token=jwt_token)
4. Work with Peers and Rooms
Manage peers, producers, and permissions.
# Example: Access the local peer
local_peer = room.local_peer
# Example: List remote peers
remote_peers = room.remote_peers
5. Produce and Consume Media
Produce and consume tracks like video, audio, or screen.
Producing Media
To produce media, use the LocalPeer.produce() method.
track = "video_track" # Replace with the actual media track
producer = await local_peer.produce(track)
Consuming Media
To consume media from a remote peer, use the LocalPeer.consume() method.
producer_id = "producer_id" # Replace with the actual producer ID
consumer = await local_peer.consume(producer_id)
Auto-Consuming Media
To automatically consume media from all producers, set the autoConsume option to True.
options = HuddleClientOptions(autoConsume=True)
client = HuddleClient(project_id="project_id", options=options)
room = await client.create(room_id="room_id", token=jwt_token)
5. Close the Connection
Always close the connection when done.
await client.close()
Modules
1. access_token
Manages access tokens, including permissions and roles.
2. huddle_client
Main entry point for connecting to the Huddle01 infrastructure. Manages rooms, peers, and communication.
3. room
Defines the structure and management of rooms.
4. remote_peer
Handles remote peers connected to a room.
5. socket
Manages WebSocket connections with advanced features like reconnection.
Room
Its defined as the grouping of Peers sharing Media Streams with one another,
Methoods
connect: Method allows to connect to a Room, which emits an EventRoomEvents.RoomJoined
Properties
state: Provides the current connection state of the Roomlocal_peer: Provides the Local Peer of the Roomremote_peers: Provides the list of Remote Peers connected to the Room
LocalPeer
Its defined as the Peer connected to the Room, which can Produce and Consume Media Streams.
Methods
-
produce: Method allows to produce a Media Stream, which emits an EventPeerEvents.ProducerAdded -
consume: Method allows to consume a Media Stream, which emits an EventPeerEvents.ConsumerAdded
Properties
peer_id: Provides the Peer ID of the Peerrole: Provides the Role of the Peer, which can beHOSTorGUESTproducers: Provides the list of Producers of the Peerconsumers: Provides the list of Consumers of the Peer
RemotePeer
Its defined as the Peer connected to the Room, which can Produce and Consume Media Streams.
Methods
get_producer: Method allows to get a Producer by itsproducer_id,labelor using both.is_producing_label: Method allows to check if the Peer is producing a Media Stream with a specificlabellabels: Method allows to get the list of Labels of the Peerproducer_ids: Method allows to get the list of Producer IDs of the Peer
Properties
peer_id: Provides the Peer ID of the Peerrole: Provides the Role of the Peer, which can beHOSTorGUESTlabels_to_producers: Provides the mapping of Labels to Producers of the Peer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file huddle01-1.1.2.tar.gz.
File metadata
- Download URL: huddle01-1.1.2.tar.gz
- Upload date:
- Size: 50.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ecbf6794a3b7882bad87fdcbe1de64e251054cd8343099416ad83d0bb671b9e
|
|
| MD5 |
f704d7b3f4961b664d91936c63ccc7dd
|
|
| BLAKE2b-256 |
4d949d9c26d74569eddf9a0397e91cadbc60bd2be3ce2061cd2ce49d5850c46d
|
File details
Details for the file huddle01-1.1.2-py3-none-any.whl.
File metadata
- Download URL: huddle01-1.1.2-py3-none-any.whl
- Upload date:
- Size: 67.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de21402024a90f76eb0e4e8c62794131d95e3feb29d11525b7ea40bc970b80ce
|
|
| MD5 |
ccb6ca4c5db580b92e735201c5b017e6
|
|
| BLAKE2b-256 |
72c18cbfd4f370ecb5f796bdafc5d590cfbf12b2179be5b59becebd42f3b8f96
|