-
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.
* Extend docs * Add mini_tutorial example and run examples in CI * Fix lint * Run firstly examples * Fixes * Update examples/mini_tutorial.py Co-authored-by: Jakub Pisarek <[email protected]> * Update jellyfish/api/_room_api.py Co-authored-by: Jakub Pisarek <[email protected]> * Update jellyfish/api/_room_api.py Co-authored-by: Jakub Pisarek <[email protected]> * Improve README --------- Co-authored-by: Jakub Pisarek <[email protected]>
- Loading branch information
Showing
9 changed files
with
194 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import asyncio | ||
import os | ||
|
||
from jellyfish import ( | ||
ComponentOptionsFile, | ||
ComponentOptionsHLS, | ||
ComponentOptionsHLSSubscribeMode, | ||
Notifier, | ||
RoomApi, | ||
) | ||
from jellyfish.events import ( | ||
ServerMessageHlsPlayable, | ||
ServerMessageTrackAdded, | ||
ServerMessageTrackType, | ||
) | ||
|
||
HOST = "jellyfish" if os.getenv("DOCKER_TEST") == "TRUE" else "localhost" | ||
SERVER_ADDRESS = f"{HOST}:5002" | ||
|
||
|
||
notifier = Notifier(server_address=SERVER_ADDRESS, server_api_token="development") | ||
|
||
notifier_task = None | ||
|
||
|
||
@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") | ||
elif isinstance(server_notification, ServerMessageHlsPlayable): | ||
print("HLS stream is playable") | ||
notifier_task.cancel() | ||
|
||
|
||
@notifier.on_metrics | ||
def handle_metrics(metrics_report): | ||
pass | ||
|
||
|
||
async def test_notifier(): | ||
global notifier_task | ||
notifier_task = asyncio.create_task(notifier.connect()) | ||
|
||
# Wait for notifier to be ready to receive messages | ||
await notifier.wait_ready() | ||
|
||
room_api = RoomApi(server_address=SERVER_ADDRESS) | ||
|
||
# Create a room to trigger a server notification with h264 as a codec, | ||
# that allow to use HLS. | ||
address, room = room_api.create_room(video_codec="h264") | ||
|
||
# Create new room api with returned jellyfish address as a room could be | ||
# created on a different jellyfish instance | ||
# (if you communicate with a cluster of jellyfishes) | ||
room_api = RoomApi(server_address=address) | ||
|
||
# Add HLS component with manual subscribe mode | ||
_hls_component = room_api.add_component( | ||
room.id, | ||
ComponentOptionsHLS(subscribe_mode=ComponentOptionsHLSSubscribeMode.MANUAL), | ||
) | ||
|
||
# Add File Component | ||
file_component = room_api.add_component(room.id, ComponentOptionsFile("video.h264")) | ||
|
||
# Subscribe on specific component | ||
room_api.hls_subscribe(room.id, [file_component.id]) | ||
|
||
try: | ||
await notifier_task | ||
except asyncio.CancelledError: | ||
print("Notifier task canceled, exiting") | ||
|
||
|
||
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
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
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