-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTC-435] Add track, peer metadata and track metadata (#27)
* Add tracks * WIP update api * Lint * Add examples * Improve docs of server notifications * endlines * Format * Update proto * Update client
- Loading branch information
Showing
30 changed files
with
820 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
# Server Notifications | ||
|
||
The Jellyfish can send one of the following notifications: | ||
|
||
`ServerMessageRoomCreated`, | ||
`ServerMessageRoomDeleted`, | ||
`ServerMessageRoomCrashed`, | ||
`ServerMessagePeerConnected`, | ||
`ServerMessagePeerDisconnected`, | ||
`ServerMessagePeerCrashed`, | ||
`ServerMessageComponentCrashed`, | ||
`ServerMessageTrackAdded`, | ||
`ServerMessageTrackMetadataUpdated`, | ||
`ServerMessageTrackRemoved`, | ||
`ServerMessageHlsPlayable`, | ||
`ServerMessageMetricsReport` |
This file contains 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,17 @@ | ||
from jellyfish import ComponentOptionsHLS, PeerOptionsWebRTC, RoomApi | ||
|
||
# Create a room | ||
room_api = RoomApi(server_address="localhost:5002", server_api_token="development") | ||
|
||
jellyfish_address, room = room_api.create_room( | ||
video_codec="h264", webhook_url="http://localhost:5000/webhook" | ||
) | ||
print((jellyfish_address, room)) | ||
|
||
# Add peer to the room | ||
peer_token, peer_webrtc = room_api.add_peer(room.id, options=PeerOptionsWebRTC()) | ||
print((peer_token, peer_webrtc)) | ||
|
||
# Add component to the room | ||
component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS()) | ||
print(component_hls) |
This file contains 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,38 @@ | ||
import asyncio | ||
|
||
from jellyfish import Notifier, RoomApi | ||
from jellyfish.events import ServerMessageTrackAdded, ServerMessageTrackType | ||
|
||
notifier = Notifier(server_address="localhost:5002", server_api_token="development") | ||
|
||
|
||
@notifier.on_server_notification | ||
def handle_notification(server_notification): | ||
print(f"Received a notification: {server_notification}") | ||
|
||
if isinstance(server_notification, ServerMessageTrackAdded): | ||
if server_notification.track.type == ServerMessageTrackType.TRACK_TYPE_AUDIO: | ||
print("New audio track has been added") | ||
elif server_notification.track.type == ServerMessageTrackType.TRACK_TYPE_VIDEO: | ||
print("New video track has been added") | ||
|
||
|
||
@notifier.on_metrics | ||
def handle_metrics(metrics_report): | ||
print(f"Received WebRTC metrics: {metrics_report}") | ||
|
||
|
||
async def test_notifier(): | ||
notifier_task = asyncio.create_task(notifier.connect()) | ||
|
||
# Wait for notifier to be ready to receive messages | ||
await notifier.wait_ready() | ||
|
||
# Create a room to trigger a server notification | ||
room_api = RoomApi() | ||
room_api.create_room() | ||
|
||
await notifier_task | ||
|
||
|
||
asyncio.run(test_notifier()) |
This file contains 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
Empty file.
This file contains 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,128 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Dict, Optional, Union | ||
|
||
import httpx | ||
|
||
from ... import errors | ||
from ...client import AuthenticatedClient, Client | ||
from ...models.healthcheck_response import HealthcheckResponse | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs() -> Dict[str, Any]: | ||
return { | ||
"method": "get", | ||
"url": "/health", | ||
} | ||
|
||
|
||
def _parse_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Optional[HealthcheckResponse]: | ||
if response.status_code == HTTPStatus.OK: | ||
response_200 = HealthcheckResponse.from_dict(response.json()) | ||
|
||
return response_200 | ||
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: | ||
response_500 = HealthcheckResponse.from_dict(response.json()) | ||
|
||
return response_500 | ||
if client.raise_on_unexpected_status: | ||
raise errors.UnexpectedStatus(response.status_code, response.content) | ||
else: | ||
return None | ||
|
||
|
||
def _build_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Response[HealthcheckResponse]: | ||
return Response( | ||
status_code=HTTPStatus(response.status_code), | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(client=client, response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[HealthcheckResponse]: | ||
"""Describes the health of Jellyfish | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[HealthcheckResponse] | ||
""" | ||
|
||
kwargs = _get_kwargs() | ||
|
||
response = client.get_httpx_client().request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
def sync( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Optional[HealthcheckResponse]: | ||
"""Describes the health of Jellyfish | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
HealthcheckResponse | ||
""" | ||
|
||
return sync_detailed( | ||
client=client, | ||
).parsed | ||
|
||
|
||
async def asyncio_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[HealthcheckResponse]: | ||
"""Describes the health of Jellyfish | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[HealthcheckResponse] | ||
""" | ||
|
||
kwargs = _get_kwargs() | ||
|
||
response = await client.get_async_httpx_client().request(**kwargs) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
async def asyncio( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Optional[HealthcheckResponse]: | ||
"""Describes the health of Jellyfish | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
HealthcheckResponse | ||
""" | ||
|
||
return ( | ||
await asyncio_detailed( | ||
client=client, | ||
) | ||
).parsed |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.