Skip to content

Commit ee35ac5

Browse files
authored
Update openapi (#4)
* Update openapi * Fix CI workflow * Fix tests * Fix CI workflow * Update dependencies * Update API * Fix lint warning * Add fishjam namespace * Remove old examples * Remove example check from workflow * Add room manager example * Add publish workflow * Update README * Update FishjamNotifier * Requested changes * Add type checker * Update python to 3.10 * Fix imports in example * Update Readme * Requested changes * Requested changes
1 parent aa119e9 commit ee35ac5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1800
-1552
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
name: lint
1010
steps:
1111
- uses: actions/checkout@v4
12-
- name: Set up Python 3.8
12+
- name: Set up Python 3.10
1313
uses: actions/setup-python@v5
1414
with:
15-
python-version: 3.8
15+
python-version: '3.10'
1616
- name: Install poetry
1717
run: pip install poetry
1818
- name: Install project dependencies
@@ -21,12 +21,20 @@ jobs:
2121
run: poetry run lint
2222
- name: Check format
2323
run: poetry run format_check
24+
- name: Type checker
25+
run: poetry run pyright
2426

2527
test:
26-
runs-on: ubuntu-latest
27-
name: test
28-
steps:
29-
- uses: actions/checkout@v4
30-
- run: docker compose -f docker-compose-test.yaml up test --exit-code-from test
31-
- run: docker compose -f docker-compose-test.yaml down
32-
- run: docker compose -f docker-compose-test.yaml up examples --exit-code-from examples
28+
runs-on: ubuntu-latest
29+
name: test
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Log in to GitHub Container Registry
34+
run: echo "${{ secrets.PACKAGE_ACCESS_TOKEN }}" | docker login ghcr.io -u USERNAME --password-stdin
35+
36+
- name: Run tests
37+
run: docker compose -f docker-compose-test.yaml up test --exit-code-from test
38+
39+
- name: Tear down test containers
40+
run: docker compose -f docker-compose-test.yaml down

.github/workflows/publish.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: publish package
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Build and publish to pypi
13+
uses: JRubics/[email protected]
14+
with:
15+
pypi_token: ${{ secrets.PYPI_TOKEN }}

README.md

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
# Fishjam Python Server SDK
44

5-
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/fishjam-cloud/python-server-sdk/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/fishjam-cloud/python-server-sdk/tree/main)
6-
7-
Python server SDK for the [Fishjam Media Server](https://github.com/fishjam-cloud/fishjam).
5+
Python server SDK for the [Fishjam Cloud](https://fishjam.io/).
86

97
Read the docs [here](https://fishjam-cloud.github.io/python-server-sdk)
108

@@ -16,114 +14,78 @@ pip install fishjam-server-sdk
1614

1715
## Usage
1816

19-
The SDK exports two main classes for interacting with Fishjam server: `RoomApi` and `Notifier`.
17+
The SDK exports two main classes for interacting with Fishjam server:
18+
`FishjamClient` and `FishjamNotifier`.
2019

21-
`RoomApi` wraps http REST api calls, while `Notifier` is responsible for receiving real-time updates from the server.
20+
`FishjamClient` wraps http REST api calls, while `FishjamNotifier` is responsible for receiving real-time updates from the server.
2221

23-
#### RoomApi
22+
#### FishjamClient
2423

25-
Create a `RoomApi` instance, providing the fishjam server address and api token
24+
Create a `FishjamClient` instance, providing the fishjam server address and api token
2625

2726
```python
28-
from fishjam import RoomApi
27+
from fishjam import FishjamClient
2928

30-
room_api = RoomApi(server_address="localhost:5002", server_api_token="development")
29+
fishjam_client = FishjamClient(fishjam_url="localhost:5002", management_token="development")
3130
```
3231

33-
You can use it to interact with Fishjam, manage rooms, peers and components
32+
You can use it to interact with Fishjam Cloud to manage rooms and peers
3433

3534
```python
3635
# Create a room
37-
fishjam_address, room = room_api.create_room(video_codec="h264", webhook_url="http://localhost:5000/webhook")
38-
# '127.0.0.1:5002', Room(components=[], config=RoomConfig(max_peers=None, video_codec=<RoomConfigVideoCodec.H264: 'h264'>, webhook_url='http://localhost:5000/webhook'), id='1d905478-ccfc-44d6-a6e7-8ccb1b38d955', peers=[])
39-
40-
# Add peer to the room
41-
from fishjam import PeerOptionsWebRTC
36+
options = RoomOptions(video_codec="h264", webhook_url="http://localhost:5000/webhook")
37+
room = fishjam_client.create_room(options=options)
4238

43-
peer_token, peer_webrtc = room_api.add_peer(room.id, options=PeerOptionsWebRTC())
44-
# 'M8TUGhj-L11KpyG-2zBPIo', Peer(id='b1232c7e-c969-4450-acdf-ea24f3cdd7f6', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc')
39+
# Room(components=[], config=RoomConfig(max_peers=None, video_codec=<RoomConfigVideoCodec.H264: 'h264'>, webhook_url='http://localhost:5000/webhook'), id='1d905478-ccfc-44d6-a6e7-8ccb1b38d955', peers=[])
4540

46-
# Add component to the room
47-
from fishjam import ComponentOptionsHLS
41+
# Add peer to the room
42+
peer, token = fishjam_client.create_peer(room.id)
4843

49-
component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS())
50-
# ComponentHLS(id='5f062447-a9f7-45ed-8d1b-511f77dc78ae', properties=ComponentPropertiesHLS(low_latency=False, persistent=False, playable=False, subscribe_mode=<ComponentPropertiesHLSSubscribeMode.AUTO: 'auto'>, target_window_duration=None), type='hls')
44+
# Peer(id='b1232c7e-c969-4450-acdf-ea24f3cdd7f6', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc'), 'M8TUGhj-L11KpyG-2zBPIo'
5145
```
5246

53-
All methods in `RoomApi` may raise one of the exceptions deriving from `fishjam.errors.HTTPError`. They are defined in
54-
`fishjam.errors`.
47+
All methods in `FishjamClient` may raise one of the exceptions deriving from `fishjam.errors.HTTPError`. They are defined in `fishjam.errors`.
5548

56-
#### Notifier
49+
#### FishjamNotifier
5750

58-
Notifier allows for receiving real-time updates from the Fishjam Server.
51+
FishjamNotifier allows for receiving real-time updates from the Fishjam Server.
5952

6053
You can read more about notifications in the
6154
[Fishjam Docs](https://fishjam-cloud.github.io/fishjam-docs/next/getting_started/notifications).
6255

63-
Create `Notifier` instance
56+
Create `FishjamNotifier` instance
6457

6558
```python
66-
from fishjam import Notifier
59+
from fishjam import FishjamNotifier
6760

68-
notifier = Notifier(server_address='localhost:5002', server_api_token='development')
61+
fishjam_notifier = FishjamNotifier(fishjam_url='localhost:5002', management_token='development')
6962
```
7063

71-
Then define handlers for incoming messages
72-
64+
Then define a handler for incoming messages
7365
```python
7466
@notifier.on_server_notification
7567
def handle_notification(server_notification):
7668
print(f'Received a notification: {server_notification}')
77-
78-
@notifier.on_metrics
79-
def handle_metrics(metrics_report):
80-
print(f'Received WebRTC metrics: {metrics_report}')
8169
```
8270

8371
After that you can start the notifier
8472

8573
```python
8674
async def test_notifier():
87-
notifier_task = asyncio.create_task(notifier.connect())
75+
notifier_task = asyncio.create_task(fishjam_notifier.connect())
8876

8977
# Wait for notifier to be ready to receive messages
90-
await notifier.wait_ready()
78+
await fishjam_notifier.wait_ready()
9179

9280
# Create a room to trigger a server notification
93-
room_api = RoomApi()
94-
room_api.create_room()
81+
fishjam_client = FishjamClient()
82+
fishjam_client.create_room()
9583

9684
await notifier_task
9785

9886
asyncio.run(test_notifier())
9987

10088
# Received a notification: ServerMessageRoomCreated(room_id='69a3fd1a-6a4d-47bc-ae54-0c72b0d05e29')
101-
# Received WebRTC metrics: ServerMessageMetricsReport(metrics='{}')
102-
```
103-
104-
#### Cluster of Fishjams
105-
106-
The cluster of fishjams has got embedded load balancer, which means that a new room will be created on fishjam with the
107-
least usage. At the moment to modify this specific room you must communicate with the fishjam on which this room was
108-
created.
109-
110-
```python
111-
room_api = RoomApi(server_address='localhost:5002')
112-
113-
# Create a room to trigger a server notification with h264 as a codec,
114-
# that allow to use HLS.
115-
address, room = room_api.create_room(video_codec="h264")
116-
117-
# Create new room api with returned fishjam address as a room could be
118-
# created on a different fishjam instance
119-
# (if you communicate with a cluster of fishjams)
120-
new_room_api = RoomApi(server_address=address)
121-
122-
# Add HLS component with manual subscribe mode, we use here `new_room_api` as we are sure that this API refers to the fishjam on which this room was created.
123-
_hls_component = new_room_api.add_component(
124-
room.id,
125-
ComponentOptionsHLS(subscribe_mode=ComponentOptionsHLSSubscribeMode.MANUAL),
126-
)
12789
```
12890

12991
## Testing

docker-compose-test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
FJ_PORT: 5002
2121
FJ_SECRET_KEY_BASE: "super-secret-key"
2222
FJ_SIP_IP: "127.0.0.1"
23-
FJ_COMPONENTS_USED: rtsp file hls recording sip
23+
FJ_COMPONENTS_USED: "rtsp file hls recording sip"
2424
ports:
2525
- "5002:5002"
2626
- "49999:49999"
@@ -30,7 +30,7 @@ services:
3030

3131
test:
3232
container_name: test
33-
image: "cimg/python:${PYTHON_VERSION:-3.8}"
33+
image: "cimg/python:${PYTHON_VERSION:-3.10}"
3434
command: sh -c "cd /app && \ poetry config virtualenvs.in-project false && \ poetry install --no-ansi && \ poetry run pytest -s"
3535
environment:
3636
DOCKER_TEST: "TRUE"
@@ -44,7 +44,7 @@ services:
4444

4545
examples:
4646
container_name: examples
47-
image: "cimg/python:${PYTHON_VERSION:-3.8}"
47+
image: "cimg/python:${PYTHON_VERSION:-3.10}"
4848
command: sh -c "cd /app && \ poetry config virtualenvs.in-project false && \ poetry cache clear pypi --all && \ poetry install --no-ansi && \ poetry run examples"
4949
environment:
5050
DOCKER_TEST: "TRUE"

examples/mini_tutorial.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

examples/room-manager/__init__.py

Whitespace-only changes.

examples/room-manager/arguments.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import argparse
2+
3+
4+
def parse_arguments():
5+
parser = argparse.ArgumentParser(description="Room Manager")
6+
7+
parser.add_argument("--port", type=int, default=5002)
8+
parser.add_argument("--peerless_purge_timeout", type=int, default=None)
9+
parser.add_argument("--webhook_url", type=str, default=None)
10+
parser.add_argument("--enable_simulcast", type=str, default=True)
11+
parser.add_argument("--max_peers", type=str, default=None)
12+
parser.add_argument("--fishjam_url", type=str, default="http://localhost:5002")
13+
parser.add_argument("--management_token", type=str, default="development")
14+
15+
return parser.parse_args()

examples/room-manager/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import logging
2+
3+
from flask import Flask
4+
5+
from .arguments import parse_arguments
6+
from .room_service import RoomService
7+
from .routes import setup_routes
8+
9+
app = Flask(__name__)
10+
app.logger.setLevel(logging.INFO)
11+
12+
13+
if __name__ == "__main__":
14+
args = parse_arguments()
15+
16+
room_service = RoomService(args, app.logger)
17+
18+
setup_routes(app, room_service)
19+
20+
app.run()

0 commit comments

Comments
 (0)