websockets: implement notification masking
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
d5a55047ab
commit
1133c296b1
|
@ -20,6 +20,7 @@ from typing import (
|
||||||
Optional,
|
Optional,
|
||||||
Callable,
|
Callable,
|
||||||
Coroutine,
|
Coroutine,
|
||||||
|
Tuple,
|
||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
|
@ -323,7 +324,7 @@ class WebsocketManager(APITransport):
|
||||||
notify_name = event_name.split(':')[-1]
|
notify_name = event_name.split(':')[-1]
|
||||||
|
|
||||||
def notify_handler(*args):
|
def notify_handler(*args):
|
||||||
self.notify_websockets(notify_name, *args)
|
self.notify_websockets(notify_name, args)
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
event_name, notify_handler)
|
event_name, notify_handler)
|
||||||
|
|
||||||
|
@ -450,12 +451,15 @@ class WebsocketManager(APITransport):
|
||||||
|
|
||||||
def notify_websockets(self,
|
def notify_websockets(self,
|
||||||
name: str,
|
name: str,
|
||||||
data: Any = SENTINEL
|
data: Union[List, Tuple] = [],
|
||||||
|
mask: List[int] = []
|
||||||
) -> None:
|
) -> None:
|
||||||
msg: Dict[str, Any] = {'jsonrpc': "2.0", 'method': "notify_" + name}
|
msg: Dict[str, Any] = {'jsonrpc': "2.0", 'method': "notify_" + name}
|
||||||
if data != SENTINEL:
|
if data:
|
||||||
msg['params'] = [data]
|
msg['params'] = data
|
||||||
for ws in list(self.websockets.values()):
|
for ws in list(self.websockets.values()):
|
||||||
|
if ws.uid in mask:
|
||||||
|
continue
|
||||||
ws.queue_message(msg)
|
ws.queue_message(msg)
|
||||||
|
|
||||||
def get_count(self) -> int:
|
def get_count(self) -> int:
|
||||||
|
@ -598,6 +602,9 @@ class WebSocket(WebSocketHandler, Subscribable):
|
||||||
self.queue_message(msg)
|
self.queue_message(msg)
|
||||||
return fut
|
return fut
|
||||||
|
|
||||||
|
def send_notification(self, name: str, data: List) -> None:
|
||||||
|
self.wsm.notify_websockets(name, data, [self._uid])
|
||||||
|
|
||||||
def resolve_pending_response(
|
def resolve_pending_response(
|
||||||
self, response_id: int, result: Any
|
self, response_id: int, result: Any
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue