Skip to content

A WebRTC Client in Python using aiortc with some useful examples.

Notifications You must be signed in to change notification settings

aljanabim/simple_webrtc_python_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple WebRTC Python Client

WebRTC is an evolving technology for peer-to-peer communication on the web. This repository demonstrates how this technology can be used to establish a peer connection from a Python instance. The networking topology is based on a meshed network. Any successful WebRTC connection requires a signaling server for the peers to exchange ICE candidates and session description protocol (SDP). The WebRTC client in this repository is compatible with the signaling server created in the following repository.

Table of Contents

Installation

We recommend using Conda or (Miniconda) to manage the packages and versions of this WebRTC Python Client. You are free to choose your version manager of choice (eg. pyenv or plain pip), in that case have a look at environment.yml to see what packages you need to install. Below are the installation instructions using Miniconda.

git clone https://github.com/aljanabim/simple_webrtc_python_client.git
cd simple_webrtc_python_client
conda env create -f environment.yml
conda activate webrtc

Usage

This client works out of the box with the signaling server created in the Simple WebRTC Signaling Server repository. Make sure you have a running local or deployed instance of the signlaing server before proceeding. You can use the signaling server locally, to play with the client logic and the examples, or deploy it on the web using your deployment service of choice (eg. Heroku, GCP, AWS, Azure, Vercel, Netlify, etc.).

Development

For development make sure to update the environment variables, in /config/dev.env, according to the configuration of your signaling server. Then run:

python main.py dev [--id]

For example, python main.py --dev --id=vehicle1, where --id denotes the peer ID to use for the client. This ID must be unique for each peer. If not specified, the machine hostname will be used.

Once you have everything up and running it is time to either play with the examples or to Implement your own logic

Production

For production make sure to update the environment variables, in /config/dev.env, according to the configuration of your signaling server. Then run:

python main.py [--id]

For example, python main.py --id=vehicle1, where --id denotes the peer ID to use for the client. This ID must be unique for each peer. If not specified, the machine hostname will be used.

Once you have everything up and running it is time to either play with the examples or to Implement your own logic

Issues so far

When a Node.js peer (using wrtc) is polite (reciever), all works well. But when the Node.js peer is the offerer (we are polite), the data channel never opens. This issue doesn't occur when Python clients are connecting to each other

Installing aiortc on Aarch64 might require needing to do the following steps PyAV-Org/PyAV#619 (comment)