Janus WebRTC gateway Python async client.
Install
pip install janus-client
Requires Python >=3.7 <3.11
NOTE: MacBook Air M1 macOS Ventura requires Python >=3.8
Description
Easily send and share WebRTC media through Janus WebRTC server.
This client is using aiortc
for WebRTC communication and subsequently PyAV
for media stack.
✅ Features ✅
- Connect to Janus server using:
- Authentication with shared static secret (API key) and/or stored token
- Support Admin/Monitor API:
- Generic requests
- Configuration related requests
- Token related requests
- Support Janus plugins:
- Simple interface
- Minimum dependency
- Extendable Janus transport
Examples
Simple Connect And Disconnect
import asyncio
from janus_client import JanusSession, JanusEchoTestPlugin, JanusVideoRoomPlugin
base_url = "wss://janusmy.josephgetmyip.com/janusbasews/janus"
base_url = "https://janusmy.josephgetmyip.com/janusbase/janus"
session = JanusSession(base_url=base_url)
plugin_handle = JanusEchoTestPlugin()
await plugin_handle.attach(session=session)
await plugin_handle.destroy()
This will create a plugin handle and then destroy it.
Notice that we don't need to call connect or disconnect explicitly. It's managed internally.
Make Video Calls
import asyncio
from janus_client import JanusSession, JanusVideoCallPlugin
from aiortc.contrib.media import MediaPlayer, MediaRecorder
async def main():
session = JanusSession(
base_url="wss://janusmy.josephgetmyip.com/janusbasews/janus",
)
plugin_handle = JanusVideoCallPlugin()
await plugin_handle.attach(session=session)
username = "testusernamein"
username_out = "testusernameout"
player = MediaPlayer(
"desktop",
format="gdigrab",
options={
"video_size": "640x480",
"framerate": "30",
"offset_x": "20",
"offset_y": "30",
},
)
recorder = MediaRecorder("./videocall_record_out.mp4")
result = await plugin_handle.register(username=username_out)
result = await plugin_handle.call(
username=username, player=player, recorder=recorder
)
await asyncio.sleep(30)
result = await plugin_handle.hangup()
await plugin_handle.destroy()
await session.destroy()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
This example will register to the VideoCall plugin using username testusernameout
. It will then call the user registered using the username testusernamein
.
A portion of the screen will be captured and sent in the call media stream.
The incoming media stream will be saved into videocall_record_out.mp4
file.
Documentation
https://janus-client-in-python.readthedocs.io/
Experiments
FFmpeg support for VideoRoom plugin has now been moved to experiments
folder, together with GStreamer support.