Skip to main content

Janus WebRTC gateway Python async client.

Project description

Python Janus Client

Janus WebRTC gateway Python async client.

PyPI - License PyPI - Status PyPI - Downloads Documentation Status Code Coverage


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:
    • Websocket
    • HTTP
  • 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

# Protocol will be derived from base_url
base_url = "wss://janusmy.josephgetmyip.com/janusbasews/janus"
# OR
base_url = "https://janusmy.josephgetmyip.com/janusbase/janus"

session = JanusSession(base_url=base_url)

plugin_handle = JanusEchoTestPlugin()

# Attach to Janus session
await plugin_handle.attach(session=session)

# Destroy plugin handle
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():
    # Create session
    session = JanusSession(
        base_url="wss://janusmy.josephgetmyip.com/janusbasews/janus",
    )

    # Create plugin
    plugin_handle = JanusVideoCallPlugin()

    # Attach to Janus session
    await plugin_handle.attach(session=session)

    # Prepare username and media stream
    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")

    # Register myself as testusernameout
    result = await plugin_handle.register(username=username_out)

    # Call testusernamein
    result = await plugin_handle.call(
        username=username, player=player, recorder=recorder
    )

    # Wait awhile then hangup
    await asyncio.sleep(30)

    result = await plugin_handle.hangup()

    # Destroy plugin
    await plugin_handle.destroy()

    # Destroy session
    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.

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

janus_client-0.7.1.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

janus_client-0.7.1-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file janus_client-0.7.1.tar.gz.

File metadata

  • Download URL: janus_client-0.7.1.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.4 Windows/10

File hashes

Hashes for janus_client-0.7.1.tar.gz
Algorithm Hash digest
SHA256 a1ff50064c44fc5b1d023c505b0e73cc8e17d3ed8b8df61134a8df3d7ead4018
MD5 208ca21a6294bcae94a2304d7182aab9
BLAKE2b-256 f297e1bfcde6bf8c72457e4e40770f6ab3f5a357a316dbbb0d6aff57d05dfea5

See more details on using hashes here.

File details

Details for the file janus_client-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: janus_client-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.4 Windows/10

File hashes

Hashes for janus_client-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f995175ea3e0181421773ccee5094e6069abfe1d91811205ca7fadc6dbf03cf
MD5 fe87752fb8ae49b30a5ccc8ce1e31fbb
BLAKE2b-256 97f41e814813d1f38ba757be4e8dc5e842bcbb46736a563dc5ac111ca799b7c5

See more details on using hashes here.

Supported by

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