fishjam-server-sdk 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fishjam_server_sdk-0.5.0/PKG-INFO +176 -0
- fishjam_server_sdk-0.5.0/README.md +150 -0
- fishjam_server_sdk-0.5.0/fishjam/__init__.py +85 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/__init__.py +7 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/__init__.py +1 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/health/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/health/healthcheck.py +129 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/hls/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/hls/get_hls_content.py +243 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/recording/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/recording/delete_recording.py +161 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/recording/get_recording_content.py +171 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/recording/get_recordings.py +133 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/add_component.py +181 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/add_peer.py +185 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/create_room.py +162 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/delete_component.py +171 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/delete_peer.py +171 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/delete_room.py +157 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/get_all_rooms.py +129 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/get_room.py +159 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/room/subscribe_to.py +193 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/sip/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/sip/dial.py +193 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/api/sip/end_call.py +175 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/client.py +274 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/errors.py +14 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/__init__.py +107 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/add_component_json_body.py +181 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/add_peer_json_body.py +74 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_details_response.py +156 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_file.py +109 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_hls.py +100 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_file.py +70 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_hls.py +121 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_hls_subscribe_mode.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_recording.py +104 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_recording_subscribe_mode.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_rtsp.py +94 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_sip.py +72 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_options_sipsip_credentials.py +74 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_file.py +67 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_hls.py +93 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_hls_subscribe_mode.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_recording.py +66 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_recording_subscribe_mode.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_rtsp.py +88 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_sip.py +72 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_properties_sipsip_credentials.py +74 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_recording.py +100 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_rtsp.py +100 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/component_sip.py +100 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/dial_config.py +60 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/error.py +60 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/health_report.py +98 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/health_report_distribution.py +79 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/health_report_status.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/healthcheck_response.py +66 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/peer.py +107 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/peer_details_response.py +66 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/peer_details_response_data.py +84 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/peer_options_web_rtc.py +60 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/peer_status.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/recording_list_response.py +60 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room.py +203 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room_config.py +111 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room_config_video_codec.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room_create_details_response.py +68 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room_create_details_response_data.py +73 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/room_details_response.py +66 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/rooms_listing_response.py +75 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/s3_credentials.py +84 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/sip_credentials.py +74 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/subscription_config.py +62 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/track.py +84 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/models/track_type.py +11 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/py.typed +1 -0
- fishjam_server_sdk-0.5.0/fishjam/_openapi_client/types.py +52 -0
- fishjam_server_sdk-0.5.0/fishjam/_webhook_notifier.py +19 -0
- fishjam_server_sdk-0.5.0/fishjam/_ws_notifier.py +151 -0
- fishjam_server_sdk-0.5.0/fishjam/api/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/api/_base_api.py +26 -0
- fishjam_server_sdk-0.5.0/fishjam/api/_recording_api.py +37 -0
- fishjam_server_sdk-0.5.0/fishjam/api/_room_api.py +237 -0
- fishjam_server_sdk-0.5.0/fishjam/errors.py +47 -0
- fishjam_server_sdk-0.5.0/fishjam/events/__init__.py +42 -0
- fishjam_server_sdk-0.5.0/fishjam/events/_protos/__init__.py +0 -0
- fishjam_server_sdk-0.5.0/fishjam/events/_protos/fishjam/__init__.py +270 -0
- fishjam_server_sdk-0.5.0/pyproject.toml +64 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fishjam-server-sdk
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Python server SDK for the Fishjam media server
|
|
5
|
+
Home-page: https://github.com/fishjam-dev/python-server-sdk
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Author: Fishjam Team
|
|
8
|
+
Requires-Python: >=3.8,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Dist: aenum (>=3.1.15,<4.0.0)
|
|
17
|
+
Requires-Dist: attrs (>=21.3.0)
|
|
18
|
+
Requires-Dist: betterproto (==2.0.0b6)
|
|
19
|
+
Requires-Dist: httpx (>=0.20.0,<0.26.0)
|
|
20
|
+
Requires-Dist: python-dateutil (>=2.8.2,<3.0.0)
|
|
21
|
+
Requires-Dist: urllib3 (>=1.25.3,<2)
|
|
22
|
+
Requires-Dist: websockets (>=11.0.3,<12.0.0)
|
|
23
|
+
Project-URL: Documentation, https://fishjam-dev.github.io/python-server-sdk/fishjam
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Fishjam Python Server SDK
|
|
27
|
+
|
|
28
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/fishjam-dev/python-server-sdk/tree/main)
|
|
29
|
+
|
|
30
|
+
Python server SDK for the [Fishjam Media Server](https://github.com/fishjam-dev/fishjam).
|
|
31
|
+
|
|
32
|
+
Read the docs [here](https://fishjam-dev.github.io/python-server-sdk)
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install fishjam-server-sdk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
The SDK exports two main classes for interacting with Fishjam server:
|
|
43
|
+
`RoomApi` and `Notifier`.
|
|
44
|
+
|
|
45
|
+
`RoomApi` wraps http REST api calls, while `Notifier` is responsible for receiving real-time updates from the server.
|
|
46
|
+
|
|
47
|
+
#### RoomApi
|
|
48
|
+
|
|
49
|
+
Create a `RoomApi` instance, providing the fishjam server address and api token
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from fishjam import RoomApi
|
|
53
|
+
|
|
54
|
+
room_api = RoomApi(server_address="localhost:5002", server_api_token="development")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You can use it to interact with Fishjam, manage rooms, peers and components
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# Create a room
|
|
61
|
+
fishjam_address, room = room_api.create_room(video_codec="h264", webhook_url="http://localhost:5000/webhook")
|
|
62
|
+
# '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=[])
|
|
63
|
+
|
|
64
|
+
# Add peer to the room
|
|
65
|
+
from fishjam import PeerOptionsWebRTC
|
|
66
|
+
|
|
67
|
+
peer_token, peer_webrtc = room_api.add_peer(room.id, options=PeerOptionsWebRTC())
|
|
68
|
+
# 'M8TUGhj-L11KpyG-2zBPIo', Peer(id='b1232c7e-c969-4450-acdf-ea24f3cdd7f6', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc')
|
|
69
|
+
|
|
70
|
+
# Add component to the room
|
|
71
|
+
from fishjam import ComponentOptionsHLS
|
|
72
|
+
|
|
73
|
+
component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS())
|
|
74
|
+
# 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')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
All methods in `RoomApi` may raise one of the exceptions deriving from `fishjam.errors.HTTPError`. They are defined in `fishjam.errors`.
|
|
78
|
+
|
|
79
|
+
#### Notifier
|
|
80
|
+
|
|
81
|
+
Notifier allows for receiving real-time updates from the Fishjam Server.
|
|
82
|
+
|
|
83
|
+
You can read more about notifications in the [Fishjam Docs](https://fishjam-dev.github.io/fishjam-docs/next/getting_started/notifications).
|
|
84
|
+
|
|
85
|
+
Create `Notifier` instance
|
|
86
|
+
```python
|
|
87
|
+
from fishjam import Notifier
|
|
88
|
+
|
|
89
|
+
notifier = Notifier(server_address='localhost:5002', server_api_token='development')
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then define handlers for incoming messages
|
|
93
|
+
```python
|
|
94
|
+
@notifier.on_server_notification
|
|
95
|
+
def handle_notification(server_notification):
|
|
96
|
+
print(f'Received a notification: {server_notification}')
|
|
97
|
+
|
|
98
|
+
@notifier.on_metrics
|
|
99
|
+
def handle_metrics(metrics_report):
|
|
100
|
+
print(f'Received WebRTC metrics: {metrics_report}')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
After that you can start the notifier
|
|
104
|
+
```python
|
|
105
|
+
async def test_notifier():
|
|
106
|
+
notifier_task = asyncio.create_task(notifier.connect())
|
|
107
|
+
|
|
108
|
+
# Wait for notifier to be ready to receive messages
|
|
109
|
+
await notifier.wait_ready()
|
|
110
|
+
|
|
111
|
+
# Create a room to trigger a server notification
|
|
112
|
+
room_api = RoomApi()
|
|
113
|
+
room_api.create_room()
|
|
114
|
+
|
|
115
|
+
await notifier_task
|
|
116
|
+
|
|
117
|
+
asyncio.run(test_notifier())
|
|
118
|
+
|
|
119
|
+
# Received a notification: ServerMessageRoomCreated(room_id='69a3fd1a-6a4d-47bc-ae54-0c72b0d05e29')
|
|
120
|
+
# Received WebRTC metrics: ServerMessageMetricsReport(metrics='{}')
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Cluster of Fishjams
|
|
124
|
+
|
|
125
|
+
The cluster of fishjams has got embedded load balancer, which means that a new room will be created on fishjam with the least usage. At the moment to modify this specific room you must communicate with the fishjam on which this room was created.
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
room_api = RoomApi(server_address='localhost:5002')
|
|
129
|
+
|
|
130
|
+
# Create a room to trigger a server notification with h264 as a codec,
|
|
131
|
+
# that allow to use HLS.
|
|
132
|
+
address, room = room_api.create_room(video_codec="h264")
|
|
133
|
+
|
|
134
|
+
# Create new room api with returned fishjam address as a room could be
|
|
135
|
+
# created on a different fishjam instance
|
|
136
|
+
# (if you communicate with a cluster of fishjams)
|
|
137
|
+
new_room_api = RoomApi(server_address=address)
|
|
138
|
+
|
|
139
|
+
# 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.
|
|
140
|
+
_hls_component = new_room_api.add_component(
|
|
141
|
+
room.id,
|
|
142
|
+
ComponentOptionsHLS(subscribe_mode=ComponentOptionsHLSSubscribeMode.MANUAL),
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Testing
|
|
147
|
+
|
|
148
|
+
You can test the SDK by running
|
|
149
|
+
```console
|
|
150
|
+
poetry run ci_test
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
In local development you can use
|
|
154
|
+
```console
|
|
155
|
+
poetry run local_test
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Format & Lint
|
|
159
|
+
You can format code by running
|
|
160
|
+
```console
|
|
161
|
+
poetry run format
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
You can check linter by running
|
|
165
|
+
```console
|
|
166
|
+
poetry run lint
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Copyright and License
|
|
170
|
+
|
|
171
|
+
Copyright 2023, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)
|
|
172
|
+
|
|
173
|
+
[](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)
|
|
174
|
+
|
|
175
|
+
Licensed under the [Apache License, Version 2.0](LICENSE)
|
|
176
|
+
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Fishjam Python Server SDK
|
|
2
|
+
|
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/fishjam-dev/python-server-sdk/tree/main)
|
|
4
|
+
|
|
5
|
+
Python server SDK for the [Fishjam Media Server](https://github.com/fishjam-dev/fishjam).
|
|
6
|
+
|
|
7
|
+
Read the docs [here](https://fishjam-dev.github.io/python-server-sdk)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pip install fishjam-server-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
The SDK exports two main classes for interacting with Fishjam server:
|
|
18
|
+
`RoomApi` and `Notifier`.
|
|
19
|
+
|
|
20
|
+
`RoomApi` wraps http REST api calls, while `Notifier` is responsible for receiving real-time updates from the server.
|
|
21
|
+
|
|
22
|
+
#### RoomApi
|
|
23
|
+
|
|
24
|
+
Create a `RoomApi` instance, providing the fishjam server address and api token
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from fishjam import RoomApi
|
|
28
|
+
|
|
29
|
+
room_api = RoomApi(server_address="localhost:5002", server_api_token="development")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You can use it to interact with Fishjam, manage rooms, peers and components
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# Create a room
|
|
36
|
+
fishjam_address, room = room_api.create_room(video_codec="h264", webhook_url="http://localhost:5000/webhook")
|
|
37
|
+
# '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=[])
|
|
38
|
+
|
|
39
|
+
# Add peer to the room
|
|
40
|
+
from fishjam import PeerOptionsWebRTC
|
|
41
|
+
|
|
42
|
+
peer_token, peer_webrtc = room_api.add_peer(room.id, options=PeerOptionsWebRTC())
|
|
43
|
+
# 'M8TUGhj-L11KpyG-2zBPIo', Peer(id='b1232c7e-c969-4450-acdf-ea24f3cdd7f6', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc')
|
|
44
|
+
|
|
45
|
+
# Add component to the room
|
|
46
|
+
from fishjam import ComponentOptionsHLS
|
|
47
|
+
|
|
48
|
+
component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS())
|
|
49
|
+
# 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')
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
All methods in `RoomApi` may raise one of the exceptions deriving from `fishjam.errors.HTTPError`. They are defined in `fishjam.errors`.
|
|
53
|
+
|
|
54
|
+
#### Notifier
|
|
55
|
+
|
|
56
|
+
Notifier allows for receiving real-time updates from the Fishjam Server.
|
|
57
|
+
|
|
58
|
+
You can read more about notifications in the [Fishjam Docs](https://fishjam-dev.github.io/fishjam-docs/next/getting_started/notifications).
|
|
59
|
+
|
|
60
|
+
Create `Notifier` instance
|
|
61
|
+
```python
|
|
62
|
+
from fishjam import Notifier
|
|
63
|
+
|
|
64
|
+
notifier = Notifier(server_address='localhost:5002', server_api_token='development')
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then define handlers for incoming messages
|
|
68
|
+
```python
|
|
69
|
+
@notifier.on_server_notification
|
|
70
|
+
def handle_notification(server_notification):
|
|
71
|
+
print(f'Received a notification: {server_notification}')
|
|
72
|
+
|
|
73
|
+
@notifier.on_metrics
|
|
74
|
+
def handle_metrics(metrics_report):
|
|
75
|
+
print(f'Received WebRTC metrics: {metrics_report}')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
After that you can start the notifier
|
|
79
|
+
```python
|
|
80
|
+
async def test_notifier():
|
|
81
|
+
notifier_task = asyncio.create_task(notifier.connect())
|
|
82
|
+
|
|
83
|
+
# Wait for notifier to be ready to receive messages
|
|
84
|
+
await notifier.wait_ready()
|
|
85
|
+
|
|
86
|
+
# Create a room to trigger a server notification
|
|
87
|
+
room_api = RoomApi()
|
|
88
|
+
room_api.create_room()
|
|
89
|
+
|
|
90
|
+
await notifier_task
|
|
91
|
+
|
|
92
|
+
asyncio.run(test_notifier())
|
|
93
|
+
|
|
94
|
+
# Received a notification: ServerMessageRoomCreated(room_id='69a3fd1a-6a4d-47bc-ae54-0c72b0d05e29')
|
|
95
|
+
# Received WebRTC metrics: ServerMessageMetricsReport(metrics='{}')
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Cluster of Fishjams
|
|
99
|
+
|
|
100
|
+
The cluster of fishjams has got embedded load balancer, which means that a new room will be created on fishjam with the least usage. At the moment to modify this specific room you must communicate with the fishjam on which this room was created.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
room_api = RoomApi(server_address='localhost:5002')
|
|
104
|
+
|
|
105
|
+
# Create a room to trigger a server notification with h264 as a codec,
|
|
106
|
+
# that allow to use HLS.
|
|
107
|
+
address, room = room_api.create_room(video_codec="h264")
|
|
108
|
+
|
|
109
|
+
# Create new room api with returned fishjam address as a room could be
|
|
110
|
+
# created on a different fishjam instance
|
|
111
|
+
# (if you communicate with a cluster of fishjams)
|
|
112
|
+
new_room_api = RoomApi(server_address=address)
|
|
113
|
+
|
|
114
|
+
# 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.
|
|
115
|
+
_hls_component = new_room_api.add_component(
|
|
116
|
+
room.id,
|
|
117
|
+
ComponentOptionsHLS(subscribe_mode=ComponentOptionsHLSSubscribeMode.MANUAL),
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Testing
|
|
122
|
+
|
|
123
|
+
You can test the SDK by running
|
|
124
|
+
```console
|
|
125
|
+
poetry run ci_test
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
In local development you can use
|
|
129
|
+
```console
|
|
130
|
+
poetry run local_test
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Format & Lint
|
|
134
|
+
You can format code by running
|
|
135
|
+
```console
|
|
136
|
+
poetry run format
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
You can check linter by running
|
|
140
|
+
```console
|
|
141
|
+
poetry run lint
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Copyright and License
|
|
145
|
+
|
|
146
|
+
Copyright 2023, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)
|
|
147
|
+
|
|
148
|
+
[](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)
|
|
149
|
+
|
|
150
|
+
Licensed under the [Apache License, Version 2.0](LICENSE)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. include:: ../README.md
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# pylint: disable=locally-disabled, no-name-in-module, import-error
|
|
6
|
+
|
|
7
|
+
# Exceptions and Server Messages
|
|
8
|
+
from fishjam import errors, events
|
|
9
|
+
|
|
10
|
+
# Models
|
|
11
|
+
from fishjam._openapi_client.models import (
|
|
12
|
+
ComponentFile,
|
|
13
|
+
ComponentHLS,
|
|
14
|
+
ComponentOptionsFile,
|
|
15
|
+
ComponentOptionsHLS,
|
|
16
|
+
ComponentOptionsHLSSubscribeMode,
|
|
17
|
+
ComponentOptionsRecording,
|
|
18
|
+
ComponentOptionsRecordingSubscribeMode,
|
|
19
|
+
ComponentOptionsRTSP,
|
|
20
|
+
ComponentOptionsSIP,
|
|
21
|
+
ComponentPropertiesFile,
|
|
22
|
+
ComponentPropertiesHLS,
|
|
23
|
+
ComponentPropertiesHLSSubscribeMode,
|
|
24
|
+
ComponentPropertiesRecording,
|
|
25
|
+
ComponentPropertiesRecordingSubscribeMode,
|
|
26
|
+
ComponentPropertiesRTSP,
|
|
27
|
+
ComponentPropertiesSIP,
|
|
28
|
+
ComponentPropertiesSIPSIPCredentials,
|
|
29
|
+
ComponentRecording,
|
|
30
|
+
ComponentRTSP,
|
|
31
|
+
ComponentSIP,
|
|
32
|
+
Peer,
|
|
33
|
+
PeerOptionsWebRTC,
|
|
34
|
+
PeerStatus,
|
|
35
|
+
Room,
|
|
36
|
+
RoomConfig,
|
|
37
|
+
RoomConfigVideoCodec,
|
|
38
|
+
S3Credentials,
|
|
39
|
+
SIPCredentials,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# API
|
|
43
|
+
from fishjam._webhook_notifier import receive_binary
|
|
44
|
+
from fishjam._ws_notifier import Notifier
|
|
45
|
+
from fishjam.api._recording_api import RecordingApi
|
|
46
|
+
from fishjam.api._room_api import RoomApi
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"RoomApi",
|
|
50
|
+
"RecordingApi",
|
|
51
|
+
"Notifier",
|
|
52
|
+
"receive_binary",
|
|
53
|
+
"Room",
|
|
54
|
+
"RoomConfig",
|
|
55
|
+
"RoomConfigVideoCodec",
|
|
56
|
+
"Peer",
|
|
57
|
+
"PeerOptionsWebRTC",
|
|
58
|
+
"PeerStatus",
|
|
59
|
+
"ComponentHLS",
|
|
60
|
+
"ComponentOptionsHLS",
|
|
61
|
+
"ComponentOptionsHLSSubscribeMode",
|
|
62
|
+
"ComponentPropertiesHLS",
|
|
63
|
+
"ComponentPropertiesHLSSubscribeMode",
|
|
64
|
+
"ComponentSIP",
|
|
65
|
+
"ComponentOptionsSIP",
|
|
66
|
+
"ComponentPropertiesSIP",
|
|
67
|
+
"ComponentPropertiesSIPSIPCredentials",
|
|
68
|
+
"ComponentFile",
|
|
69
|
+
"ComponentRTSP",
|
|
70
|
+
"ComponentOptionsRTSP",
|
|
71
|
+
"ComponentPropertiesRTSP",
|
|
72
|
+
"ComponentFile",
|
|
73
|
+
"ComponentOptionsFile",
|
|
74
|
+
"ComponentPropertiesFile",
|
|
75
|
+
"events",
|
|
76
|
+
"errors",
|
|
77
|
+
"SIPCredentials",
|
|
78
|
+
"ComponentRecording",
|
|
79
|
+
"ComponentOptionsRecording",
|
|
80
|
+
"ComponentOptionsRecordingSubscribeMode",
|
|
81
|
+
"ComponentPropertiesRecording",
|
|
82
|
+
"ComponentPropertiesRecordingSubscribeMode",
|
|
83
|
+
"S3Credentials",
|
|
84
|
+
]
|
|
85
|
+
__docformat__ = "restructuredtext"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
""" Contains methods for accessing the API """
|
|
File without changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Dict, Optional, Union
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from ... import errors
|
|
7
|
+
from ...client import AuthenticatedClient, Client
|
|
8
|
+
from ...models.error import Error
|
|
9
|
+
from ...models.healthcheck_response import HealthcheckResponse
|
|
10
|
+
from ...types import Response
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_kwargs() -> Dict[str, Any]:
|
|
14
|
+
return {
|
|
15
|
+
"method": "get",
|
|
16
|
+
"url": "/health",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _parse_response(
|
|
21
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
22
|
+
) -> Optional[Union[Error, HealthcheckResponse]]:
|
|
23
|
+
if response.status_code == HTTPStatus.OK:
|
|
24
|
+
response_200 = HealthcheckResponse.from_dict(response.json())
|
|
25
|
+
|
|
26
|
+
return response_200
|
|
27
|
+
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
|
28
|
+
response_401 = Error.from_dict(response.json())
|
|
29
|
+
|
|
30
|
+
return response_401
|
|
31
|
+
if client.raise_on_unexpected_status:
|
|
32
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
33
|
+
else:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _build_response(
|
|
38
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
39
|
+
) -> Response[Union[Error, HealthcheckResponse]]:
|
|
40
|
+
return Response(
|
|
41
|
+
status_code=HTTPStatus(response.status_code),
|
|
42
|
+
content=response.content,
|
|
43
|
+
headers=response.headers,
|
|
44
|
+
parsed=_parse_response(client=client, response=response),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def sync_detailed(
|
|
49
|
+
*,
|
|
50
|
+
client: AuthenticatedClient,
|
|
51
|
+
) -> Response[Union[Error, HealthcheckResponse]]:
|
|
52
|
+
"""Describes the health of Fishjam
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
56
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Response[Union[Error, HealthcheckResponse]]
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
kwargs = _get_kwargs()
|
|
63
|
+
|
|
64
|
+
response = client.get_httpx_client().request(
|
|
65
|
+
**kwargs,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return _build_response(client=client, response=response)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def sync(
|
|
72
|
+
*,
|
|
73
|
+
client: AuthenticatedClient,
|
|
74
|
+
) -> Optional[Union[Error, HealthcheckResponse]]:
|
|
75
|
+
"""Describes the health of Fishjam
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
79
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Union[Error, HealthcheckResponse]
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
return sync_detailed(
|
|
86
|
+
client=client,
|
|
87
|
+
).parsed
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
async def asyncio_detailed(
|
|
91
|
+
*,
|
|
92
|
+
client: AuthenticatedClient,
|
|
93
|
+
) -> Response[Union[Error, HealthcheckResponse]]:
|
|
94
|
+
"""Describes the health of Fishjam
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
98
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Response[Union[Error, HealthcheckResponse]]
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
kwargs = _get_kwargs()
|
|
105
|
+
|
|
106
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
107
|
+
|
|
108
|
+
return _build_response(client=client, response=response)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def asyncio(
|
|
112
|
+
*,
|
|
113
|
+
client: AuthenticatedClient,
|
|
114
|
+
) -> Optional[Union[Error, HealthcheckResponse]]:
|
|
115
|
+
"""Describes the health of Fishjam
|
|
116
|
+
|
|
117
|
+
Raises:
|
|
118
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
119
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Union[Error, HealthcheckResponse]
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
await asyncio_detailed(
|
|
127
|
+
client=client,
|
|
128
|
+
)
|
|
129
|
+
).parsed
|
|
File without changes
|