@@ -93,3 +93,55 @@ async def disconnect(self, sid, namespace=None):
9393 """
9494 return await self .server .disconnect (
9595 sid , namespace = namespace or self .namespace )
96+
97+
98+ class AsyncClientNamespace (namespace .ClientNamespace ):
99+ """Base class for asyncio class-based namespaces.
100+
101+ A class-based namespace is a class that contains all the event handlers
102+ for a Socket.IO namespace. The event handlers are methods of the class
103+ with the prefix ``on_``, such as ``on_connect``, ``on_disconnect``,
104+ ``on_message``, ``on_json``, and so on. These can be regular functions or
105+ coroutines.
106+
107+ :param namespace: The Socket.IO namespace to be used with all the event
108+ handlers defined in this class. If this argument is
109+ omitted, the default namespace is used.
110+ """
111+ async def emit (self , event , data = None , namespace = None , callback = None ):
112+ """Emit a custom event to the server.
113+
114+ The only difference with the :func:`socketio.Client.emit` method is
115+ that when the ``namespace`` argument is not given the namespace
116+ associated with the class is used.
117+
118+ Note: this method is a coroutine.
119+ """
120+ return await self .server .emit (event , data = data ,
121+ namespace = namespace or self .namespace ,
122+ callback = callback )
123+
124+ async def send (self , data , namespace = None , callback = None ):
125+ """Send a message to the server.
126+
127+ The only difference with the :func:`socketio.Client.send` method is
128+ that when the ``namespace`` argument is not given the namespace
129+ associated with the class is used.
130+
131+ Note: this method is a coroutine.
132+ """
133+ return await self .server .send (data ,
134+ namespace = namespace or self .namespace ,
135+ callback = callback )
136+
137+ async def disconnect (self , namespace = None ):
138+ """Disconnect a client.
139+
140+ The only difference with the :func:`socketio.Client.disconnect` method
141+ is that when the ``namespace`` argument is not given the namespace
142+ associated with the class is used.
143+
144+ Note: this method is a coroutine.
145+ """
146+ return await self .server .disconnect (
147+ namespace = namespace or self .namespace )
0 commit comments