add mapping between client_token and socket id (#3388)
This commit is contained in:
parent
6c6eaaa55f
commit
33f71c6eef
@ -1302,6 +1302,12 @@ class EventNamespace(AsyncNamespace):
|
|||||||
# The application object.
|
# The application object.
|
||||||
app: App
|
app: App
|
||||||
|
|
||||||
|
# Keep a mapping between socket ID and client token.
|
||||||
|
token_to_sid: dict[str, str] = {}
|
||||||
|
|
||||||
|
# Keep a mapping between client token and socket ID.
|
||||||
|
sid_to_token: dict[str, str] = {}
|
||||||
|
|
||||||
def __init__(self, namespace: str, app: App):
|
def __init__(self, namespace: str, app: App):
|
||||||
"""Initialize the event namespace.
|
"""Initialize the event namespace.
|
||||||
|
|
||||||
@ -1327,7 +1333,9 @@ class EventNamespace(AsyncNamespace):
|
|||||||
Args:
|
Args:
|
||||||
sid: The Socket.IO session id.
|
sid: The Socket.IO session id.
|
||||||
"""
|
"""
|
||||||
pass
|
disconnect_token = self.sid_to_token.pop(sid, None)
|
||||||
|
if disconnect_token:
|
||||||
|
self.token_to_sid.pop(disconnect_token, None)
|
||||||
|
|
||||||
async def emit_update(self, update: StateUpdate, sid: str) -> None:
|
async def emit_update(self, update: StateUpdate, sid: str) -> None:
|
||||||
"""Emit an update to the client.
|
"""Emit an update to the client.
|
||||||
@ -1351,6 +1359,9 @@ class EventNamespace(AsyncNamespace):
|
|||||||
# Get the event.
|
# Get the event.
|
||||||
event = Event.parse_raw(data)
|
event = Event.parse_raw(data)
|
||||||
|
|
||||||
|
self.token_to_sid[event.token] = sid
|
||||||
|
self.sid_to_token[sid] = event.token
|
||||||
|
|
||||||
# Get the event environment.
|
# Get the event environment.
|
||||||
assert self.app.sio is not None
|
assert self.app.sio is not None
|
||||||
environ = self.app.sio.get_environ(sid, self.namespace)
|
environ = self.app.sio.get_environ(sid, self.namespace)
|
||||||
|
Loading…
Reference in New Issue
Block a user