Skip to main content

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 EnhancedEventEmitter for 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 Event RoomEvents.RoomJoined

Properties

  • state: Provides the current connection state of the Room
  • local_peer: Provides the Local Peer of the Room
  • remote_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 Event PeerEvents.ProducerAdded

  • consume: Method allows to consume a Media Stream, which emits an Event PeerEvents.ConsumerAdded

Properties

  • peer_id: Provides the Peer ID of the Peer
  • role: Provides the Role of the Peer, which can be HOST or GUEST
  • producers: Provides the list of Producers of the Peer
  • consumers: 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 its producer_id, label or using both.
  • is_producing_label: Method allows to check if the Peer is producing a Media Stream with a specific label
  • labels: Method allows to get the list of Labels of the Peer producer_ids: Method allows to get the list of Producer IDs of the Peer

Properties

  • peer_id: Provides the Peer ID of the Peer
  • role: Provides the Role of the Peer, which can be HOST or GUEST
  • labels_to_producers: Provides the mapping of Labels to Producers of the Peer

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huddle01-1.1.2.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huddle01-1.1.2-py3-none-any.whl (67.9 kB view details)

Uploaded Python 3

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

Hashes for huddle01-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4ecbf6794a3b7882bad87fdcbe1de64e251054cd8343099416ad83d0bb671b9e
MD5 f704d7b3f4961b664d91936c63ccc7dd
BLAKE2b-256 4d949d9c26d74569eddf9a0397e91cadbc60bd2be3ce2061cd2ce49d5850c46d

See more details on using hashes here.

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

Hashes for huddle01-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de21402024a90f76eb0e4e8c62794131d95e3feb29d11525b7ea40bc970b80ce
MD5 ccb6ca4c5db580b92e735201c5b017e6
BLAKE2b-256 72c18cbfd4f370ecb5f796bdafc5d590cfbf12b2179be5b59becebd42f3b8f96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page