Skip to content

Commit 281ee3c

Browse files
authored
Fix return types for server notifications (#13)
* Fix return types for server notifications * Requested changes
1 parent f56558a commit 281ee3c

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

fishjam/_webhook_notifier.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import betterproto
99

1010
from fishjam.events._protos.fishjam import ServerMessage
11-
from fishjam.events.allowed_notifications import ALLOWED_NOTIFICATIONS
11+
from fishjam.events.allowed_notifications import (
12+
ALLOWED_NOTIFICATIONS,
13+
AllowedNotification,
14+
)
1215

1316

14-
def receive_binary(binary: bytes) -> Union[betterproto.Message, None]:
17+
def receive_binary(binary: bytes) -> Union[AllowedNotification, None]:
1518
"""
1619
Transform received protobuf notification to adequate notification instance.
1720
The available notifications are listed in `fishjam.events` module.

fishjam/_ws_notifier.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import asyncio
6-
from typing import Any, Callable, Literal, cast
6+
from typing import Callable, Literal, cast
77

88
import betterproto
99
from websockets import client
@@ -17,7 +17,10 @@
1717
ServerMessageSubscribeRequest,
1818
ServerMessageSubscribeResponse,
1919
)
20-
from fishjam.events.allowed_notifications import ALLOWED_NOTIFICATIONS
20+
from fishjam.events.allowed_notifications import (
21+
ALLOWED_NOTIFICATIONS,
22+
AllowedNotification,
23+
)
2124

2225

2326
class FishjamNotifier:
@@ -41,7 +44,7 @@ def __init__(self, fishjam_url: str, management_token: str):
4144

4245
self._notification_handler: Callable | None = None
4346

44-
def on_server_notification(self, handler: Callable[[Any], None]):
47+
def on_server_notification(self, handler: Callable[[AllowedNotification], None]):
4548
"""
4649
Decorator used for defining handler for Fishjam Notifications
4750
"""

fishjam/events/allowed_notifications.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Union
2+
13
from fishjam.events import (
24
ServerMessagePeerAdded,
35
ServerMessagePeerConnected,
@@ -27,3 +29,18 @@
2729
ServerMessageTrackRemoved,
2830
ServerMessageTrackMetadataUpdated,
2931
)
32+
33+
AllowedNotification = Union[
34+
ServerMessageRoomCreated,
35+
ServerMessageRoomDeleted,
36+
ServerMessageRoomCrashed,
37+
ServerMessagePeerAdded,
38+
ServerMessagePeerDeleted,
39+
ServerMessagePeerConnected,
40+
ServerMessagePeerDisconnected,
41+
ServerMessagePeerMetadataUpdated,
42+
ServerMessagePeerCrashed,
43+
ServerMessageTrackAdded,
44+
ServerMessageTrackRemoved,
45+
ServerMessageTrackMetadataUpdated,
46+
]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fishjam-server-sdk"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "Python server SDK for the Fishjam Cloud"
55
authors = ["Fishjam Team"]
66
homepage = "https://github.com/fishjam-cloud/python-server-sdk"

0 commit comments

Comments
 (0)