Skip to content

Commit 82510a8

Browse files
committed
added socket.io server registry
1 parent c85f0c9 commit 82510a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ellar/socket_io/decorators/subscribe_message.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typing as t
22

3+
from ellar.helper import get_name
34
from ellar.reflect import reflect
45
from ellar.socket_io.constants import MESSAGE_MAPPING_METADATA, MESSAGE_METADATA
56

@@ -10,4 +11,9 @@ def _decorator(func: t.Callable) -> t.Callable:
1011
reflect.define_metadata(MESSAGE_METADATA, message, func)
1112
return func
1213

14+
if callable(message):
15+
func = message
16+
message = get_name(func)
17+
return _decorator(t.cast(t.Callable, func))
18+
1319
return _decorator

ellar/socket_io/factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from ellar.socket_io.gateway import SocketMessageOperation, SocketOperationConnection
1919
from ellar.socket_io.model import GatewayBase, GatewayType
2020

21+
_socket_servers: t.Dict[str, socketio.AsyncServer] = {}
22+
2123

2224
class GatewayRouterFactory(RouterBuilder, controller_type=type(GatewayBase)):
2325
@classmethod
@@ -35,7 +37,11 @@ def build(cls, controller_type: t.Union[t.Type[GatewayBase], t.Any]) -> "Mount":
3537
reflect.get_metadata(GATEWAY_MESSAGE_HANDLER_KEY, controller_type) or []
3638
)
3739

38-
socket_server = socketio.AsyncServer(**options)
40+
socket_server = _socket_servers.get(path)
41+
42+
if not socket_server:
43+
socket_server = socketio.AsyncServer(**options)
44+
_socket_servers.update({path: socket_server})
3945

4046
for handler in message_handlers:
4147
is_connection_handler = reflect.get_metadata(CONNECTION_EVENT, handler)

0 commit comments

Comments
 (0)