Janus Client in Python
This is a Janus webrtc client written in Python, to be used with asyncio.
Install
pip install janus-client
Description
The package is implementing a general purpose client that can communicate with a Janus server.
Examples like VideoRoom plugin are also included in the package, but currently it depends on GStreamer for WebRTC and media streaming, and it will not be automatically installed. The reason for this is because it's not trivial to install/recompile it. Please refer to Quirks section.
Features
✔️ Connect to Janus server through websocket (using websockets)
✔️ Handle transactions with Janus
✔️ Create/destroy sessions
✔️ Create/destroy plugins
✔️ Handle multiple sessions and or multiple plugins at the same time
✔️ Support authentication with shared static secret (API key) and/or stored token
✔️ Expose Admin/Monitor API client
In Progress
🕒 Emit events to respective session and plugin handlers
🕒 Create plugin for videoroom plugin
🕒 Documentation
Dependencies
Usage
In main.py, you will see an example on how to use the client in general, such as connecting and creating sessions.
I use it to develop this package.
For more details, please Read The Docs
Example:
import asyncio
import ssl
import pathlib
from janus_client import JanusClient
from janus_client.plugin_video_room import JanusVideoRoomPlugin
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
localhost_pem = pathlib.Path(__file__).with_name("lt_limmengkiat_name_my.crt")
ssl_context.load_verify_locations(localhost_pem)
async def main():
# Connect to server
client = JanusClient("wss://lt.limmengkiat.name.my/janusws/")
await client.connect(ssl=ssl_context)
# Create session
session = await client.create_session()
# Create plugin
plugin_handle = await session.create_plugin_handle(JanusVideoRoomPlugin)
participants = await plugin_handle.list_participants(1234)
if len(participants) > 0:
# Publishers available
participants_data_1 = participants[0]
participant_id = participants_data_1["id"]
# Subscribe to publisher, will get jsep (sdp offer)
await plugin_handle.subscribe(1234, participant_id)
# WebRTC streaming not implemented for subscriber yet
await asyncio.sleep(5)
# Unsubscribe from the publisher
await plugin_handle.unsubscribe()
# Destroy plugin
await plugin_handle.destroy()
# Destroy session
await session.destroy()
# Destroy connection
await client.disconnect()
asyncio.run(main())
Quirks
-
On my RPI 2 Raspbian Buster, there's a problem with GStreamer installed from distribution repository. It's complaining about ssl and then failing DTLS.
Referring to this PR: webrtcbin: fix DTLS when receivebin is set to DROP
I believe there is a bug in the distributed GStreamer version (v1.14.4) thus I recompiled it on my RPI 2
There's also a chance that it's a problem with openssl itself, an incompatibility. Refering to this gist: OpenSSL DTLS problem in Debian busterBecause of these, please recompile GStreamer with version above 1.14.4.
-
When recompiling GStreamer on RPI, there's this issue: rpicamsrc 1.18.3 failed.
You can patch the build with this PR: rpicamsrc: depend on posix threads and vchiq_arm or build with master branch. -
The example was still unable to setup a peer connection to my janus server at lt.limmengkiat.name.my. I had to enable ice_tcp (ice_tcp=true) in janus.jcfg for it to work. I don't know why yet.
Recompiling GStreamer
Please refer to our Wiki page: Compiling GStreamer