@@ -70,17 +70,13 @@ async def emit(self, event, data, namespace=None, room=None, skip_sid=None,
7070 'host_id' : self .host_id })
7171
7272 async def can_disconnect (self , sid , namespace ):
73- await self ._publish ({'method' : 'disconnect' , 'sid' : sid ,
74- 'namespace' : namespace or '/' })
75-
76- async def disconnect (self , sid , namespace = None ):
77- """Disconnect a client."""
78- # this is a bit weird, the can_disconnect call on pubsub managers just
79- # issues a disconnect request to the message queue and returns None,
80- # indicating that the client cannot disconnect immediately. The
81- # server(s) listening on the queue will get this request and carry out
82- # the disconnect appropriately.
83- await self .can_disconnect (sid , namespace )
73+ if self .is_connected (sid , namespace ):
74+ # client is in this server, so we can disconnect directly
75+ return super ().can_disconnect (sid , namespace )
76+ else :
77+ # client is in another server, so we post request to the queue
78+ await self ._publish ({'method' : 'disconnect' , 'sid' : sid ,
79+ 'namespace' : namespace or '/' })
8480
8581 async def close_room (self , room , namespace = None ):
8682 await self ._publish ({'method' : 'close_room' , 'room' : room ,
0 commit comments