-
Notifications
You must be signed in to change notification settings - Fork 1
Basic rest api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a5199cd
init
roznawsk 3da5bbd
Add templates
roznawsk 9619b1e
Templates return tuple
roznawsk 5bd9024
Revert to default templates, wip test and api.
roznawsk 8ddcc78
Create tests
roznawsk 467e006
Generate openapi client
roznawsk fe3d15f
Add circleCI config
roznawsk 5847bb4
Setup lint
roznawsk b890d81
Add pylint to reqs
roznawsk ccf6cfa
Fix imports
roznawsk 4ae9cca
Add test to CI
roznawsk 3f8c395
Fix lint
roznawsk 5abd2f4
Add local dependency
roznawsk 29990fc
Remove some generated files
roznawsk b4a7a89
Remove templates
roznawsk 7753e8f
Remove project files
roznawsk 3d60abb
options check
roznawsk e1ada1c
Custom partial_header template
roznawsk fff4168
Fix docker test
roznawsk a24a085
Add all tests in docker test
roznawsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} | ||
sgfn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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""" | ||
sgfn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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): | ||
sgfn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.