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
97Read 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
6053You 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
7567def 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
8371After that you can start the notifier
8472
8573``` python
8674async 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
9886asyncio.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
0 commit comments