From 25c6e5ad5419087df51b6f0590feadf9e04e4907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Szuma?= <56085570+Rados13@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:14:22 +0200 Subject: [PATCH] RTC-520 Add PeerAdded and PeerDeleted notifications (#37) * Add PeerAdded and PeerDeleted notifications * Update protos --- jellyfish/events/__init__.py | 4 ++++ .../events/_protos/jellyfish/__init__.py | 23 +++++++++++++++++++ protos | 2 +- tests/test_notifier.py | 8 +++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/jellyfish/events/__init__.py b/jellyfish/events/__init__.py index b3a519a..0498ff5 100644 --- a/jellyfish/events/__init__.py +++ b/jellyfish/events/__init__.py @@ -7,8 +7,10 @@ ServerMessageComponentCrashed, ServerMessageHlsPlayable, ServerMessageMetricsReport, + ServerMessagePeerAdded, ServerMessagePeerConnected, ServerMessagePeerCrashed, + ServerMessagePeerDeleted, ServerMessagePeerDisconnected, ServerMessageRoomCrashed, ServerMessageRoomCreated, @@ -24,7 +26,9 @@ "ServerMessageRoomCreated", "ServerMessageRoomDeleted", "ServerMessageRoomCrashed", + "ServerMessagePeerAdded", "ServerMessagePeerConnected", + "ServerMessagePeerDeleted", "ServerMessagePeerDisconnected", "ServerMessagePeerCrashed", "ServerMessageComponentCrashed", diff --git a/jellyfish/events/_protos/jellyfish/__init__.py b/jellyfish/events/_protos/jellyfish/__init__.py index e313909..59947ea 100644 --- a/jellyfish/events/_protos/jellyfish/__init__.py +++ b/jellyfish/events/_protos/jellyfish/__init__.py @@ -85,6 +85,12 @@ class ServerMessage(betterproto.Message): track_metadata_updated: "ServerMessageTrackMetadataUpdated" = ( betterproto.message_field(19, group="content") ) + peer_added: "ServerMessagePeerAdded" = betterproto.message_field( + 20, group="content" + ) + peer_deleted: "ServerMessagePeerDeleted" = betterproto.message_field( + 21, group="content" + ) @dataclass(eq=False, repr=False) @@ -94,6 +100,22 @@ class ServerMessageRoomCrashed(betterproto.Message): room_id: str = betterproto.string_field(1) +@dataclass(eq=False, repr=False) +class ServerMessagePeerAdded(betterproto.Message): + """Notification sent when a peer is added""" + + room_id: str = betterproto.string_field(1) + peer_id: str = betterproto.string_field(2) + + +@dataclass(eq=False, repr=False) +class ServerMessagePeerDeleted(betterproto.Message): + """Notification sent when a peer is removed""" + + room_id: str = betterproto.string_field(1) + peer_id: str = betterproto.string_field(2) + + @dataclass(eq=False, repr=False) class ServerMessagePeerConnected(betterproto.Message): """Notification sent when a peer connects""" @@ -116,6 +138,7 @@ class ServerMessagePeerCrashed(betterproto.Message): room_id: str = betterproto.string_field(1) peer_id: str = betterproto.string_field(2) + reason: str = betterproto.string_field(3) @dataclass(eq=False, repr=False) diff --git a/protos b/protos index b9683a3..7da5da1 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit b9683a3faec93b90b5f39e68cae387390fceba05 +Subproject commit 7da5da127c8e018ee0c845c921f598b10209271c diff --git a/tests/test_notifier.py b/tests/test_notifier.py index b996c17..64a87a7 100644 --- a/tests/test_notifier.py +++ b/tests/test_notifier.py @@ -12,7 +12,9 @@ from jellyfish import ComponentOptionsFile, Notifier, PeerOptionsWebRTC, RoomApi from jellyfish.events import ( ServerMessageMetricsReport, + ServerMessagePeerAdded, ServerMessagePeerConnected, + ServerMessagePeerDeleted, ServerMessagePeerDisconnected, ServerMessageRoomCreated, ServerMessageRoomDeleted, @@ -121,8 +123,10 @@ async def test_peer_connected_disconnected( ): event_checks = [ ServerMessageRoomCreated, + ServerMessagePeerAdded, ServerMessagePeerConnected, ServerMessagePeerDisconnected, + ServerMessagePeerDeleted, ServerMessageRoomDeleted, ] assert_task = asyncio.create_task(assert_events(notifier, event_checks.copy())) @@ -156,8 +160,10 @@ async def test_peer_connected_disconnected_deleted( ): event_checks = [ ServerMessageRoomCreated, + ServerMessagePeerAdded, ServerMessagePeerConnected, ServerMessagePeerDisconnected, + ServerMessagePeerDeleted, ServerMessageRoomDeleted, ] @@ -194,7 +200,9 @@ async def test_peer_connected_room_deleted( ): event_checks = [ ServerMessageRoomCreated, + ServerMessagePeerAdded, ServerMessagePeerConnected, + ServerMessagePeerDeleted, ServerMessageRoomDeleted, ] assert_task = asyncio.create_task(assert_events(notifier, event_checks.copy()))