Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2.1

orbs:
python: circleci/[email protected]

executors:
machine_executor_amd64:
machine:
image: ubuntu-2204:2022.04.2
environment:
architecture: "amd64"
platform: "linux/amd64"


jobs:
lint:
executor: python/default
steps:
- checkout
- python/install-packages:
pkg-manager: pip
- run:
name: Lint
command: pylint --rcfile=pylintrc jellyfish tests
- persist_to_workspace:
root: ~/project
paths:
- .

test:
executor: machine_executor_amd64
steps:
- checkout
- run: docker compose -f docker-compose-test.yaml run test


workflows:
build:
jobs:
- lint
- test
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
46 changes: 46 additions & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: "3"

services:
jellyfish:
image: "ghcr.io/jellyfish-dev/jellyfish:${TAG:-edge}"
container_name: jellyfish
restart: on-failure
healthcheck:
test: >
curl --fail -H "authorization: Bearer development" http://jellyfish:5002/room || exit 1
interval: 3s
retries: 2
timeout: 2s
start_period: 30s
environment:
VIRTUAL_HOST: "jellyfish"
USE_INTEGRATED_TURN: "true"
INTEGRATED_TURN_IP: "${INTEGRATED_TURN_IP:-127.0.0.1}"
INTEGRATED_TURN_LISTEN_IP: "0.0.0.0"
INTEGRATED_TURN_PORT_RANGE: "50000-50050"
INTEGRATED_TCP_TURN_PORT: "49999"
SERVER_API_TOKEN: "development"
PORT: 5002
SECRET_KEY_BASE: "super-secret-key"
ports:
- "5002:5002"
- "49999:49999"
- "50000-50050:50000-50050/udp"
networks:
- network

test:
image: python:3.7-alpine3.18
command: sh -c "cd app/ && pip install -r requirements.txt && pytest"
environment:
- DOCKER_TEST=TRUE
volumes:
- .:/app
networks:
- network
depends_on:
- jellyfish

networks:
network:
driver: bridge
12 changes: 12 additions & 0 deletions generate_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

rm -rf openapi
openapi-generator-cli generate \
-i https://raw.githubusercontent.com/jellyfish-dev/jellyfish/main/openapi.yaml \
-g python \
-o openapi \
-t templates \
--package-name openapi_client \
--global-property apis,models,modelTests=false,supportingFiles

rm -rf openapi/{docs,test,.github,.openapi-generator,.gitignore,.gitlab-ci.yml,.travis.yml,.openapi-generator-ignore,git_push.sh,README.md,setup.cfg,test-requirements.txt,tox.ini}
16 changes: 16 additions & 0 deletions jellyfish/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Python server SDK for [Jellyfish](https://github.com/jellyfish-dev/jellyfish) media server.
"""

__version__ = "0.1.0"

# pylint: disable=locally-disabled, no-name-in-module, import-error

from pydantic.error_wrappers import ValidationError

from openapi_client import Room, RoomConfig, Peer, Component
from openapi_client import ComponentOptions, ComponentOptionsRTSP, PeerOptionsWebRTC

from openapi_client.exceptions import UnauthorizedException, NotFoundException, BadRequestException

from jellyfish.room_api import RoomApi
73 changes: 73 additions & 0 deletions jellyfish/room_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
RoomApi used to manage rooms
"""

import openapi_client as jellyfish_api

from openapi_client import (AddPeerRequest, AddComponentRequest, PeerOptions,
ComponentOptions, Room, RoomConfig, Peer, Component)


class RoomApi:
"""Allows for managing rooms"""

def __init__(self, server_address: str, server_api_token: str):
self._configuration = jellyfish_api.Configuration(
host=server_address,
access_token=server_api_token
)

self._api_client = jellyfish_api.ApiClient(self._configuration)
self._room_api = jellyfish_api.RoomApi(self._api_client)

def create_room(self, max_peers: int = None, video_codec: str = None) -> (str, Room):
"""Creates a room"""

room_config = RoomConfig(maxPeers=max_peers, videoCodec=video_codec)
resp = self._room_api.create_room(room_config)

return (resp.data.jellyfish_address, resp.data.room)

def delete_room(self, room_id: str) -> None:
"""Deletes a room"""

return self._room_api.delete_room(room_id)

def get_all_rooms(self) -> list:
"""Returns list of all rooms"""

return self._room_api.get_all_rooms().data

def get_room(self, room_id: str) -> Room:
"""Returns room with the given id"""

return self._room_api.get_room(room_id).data

def add_peer(self, room_id: str, peer_type: str, options) -> (str, Peer):
"""Creates peer in the room"""

options = PeerOptions(options)
request = AddPeerRequest(type=peer_type, options=options)

resp = self._room_api.add_peer(room_id, request)
return (resp.data.token, resp.data.peer)

def delete_peer(self, room_id: str, peer_id: str) -> None:
"""Deletes peer"""

return self._room_api.delete_peer(room_id, peer_id)

def add_component(self, room_id: str, component_type: str, options=None) -> Component:
"""Creates component in the room"""

if options is not None:
options = ComponentOptions(options)

request = AddComponentRequest(type=component_type, options=options)

return self._room_api.add_component(room_id, request).data

def delete_component(self, room_id: str, component_id: str) -> None:
"""Deletes component"""

return self._room_api.delete_component(room_id, component_id)
Loading