Decorator to register a SocketIO event handler. This decorator must be applied to SocketIO event handlers. Example:: @socketio.on('my event', namespace='/chat') def handle_my_custom_event(json): print('received json: ' + str(json)) :param me
(self, message, namespace=None)
| 270 | app.wsgi_app = self.sockio_mw |
| 271 | |
| 272 | def on(self, message, namespace=None): |
| 273 | """Decorator to register a SocketIO event handler. |
| 274 | |
| 275 | This decorator must be applied to SocketIO event handlers. Example:: |
| 276 | |
| 277 | @socketio.on('my event', namespace='/chat') |
| 278 | def handle_my_custom_event(json): |
| 279 | print('received json: ' + str(json)) |
| 280 | |
| 281 | :param message: The name of the event. This is normally a user defined |
| 282 | string, but a few event names are already defined. Use |
| 283 | ``'message'`` to define a handler that takes a string |
| 284 | payload, ``'json'`` to define a handler that takes a |
| 285 | JSON blob payload, ``'connect'`` or ``'disconnect'`` |
| 286 | to create handlers for connection and disconnection |
| 287 | events. |
| 288 | :param namespace: The namespace on which the handler is to be |
| 289 | registered. Defaults to the global namespace. |
| 290 | """ |
| 291 | namespace = namespace or '/' |
| 292 | |
| 293 | def decorator(handler): |
| 294 | @wraps(handler) |
| 295 | def _handler(sid, *args): |
| 296 | real_ns = namespace |
| 297 | if namespace == '*': |
| 298 | real_ns = sid |
| 299 | sid = args[0] |
| 300 | args = args[1:] |
| 301 | real_msg = message |
| 302 | if message == '*': |
| 303 | real_msg = sid |
| 304 | sid = args[0] |
| 305 | args = [real_msg] + list(args[1:]) |
| 306 | return self._handle_event(handler, message, real_ns, sid, |
| 307 | *args) |
| 308 | |
| 309 | if self.server: |
| 310 | self.server.on(message, _handler, namespace=namespace) |
| 311 | else: |
| 312 | self.handlers.append((message, _handler, namespace)) |
| 313 | return handler |
| 314 | return decorator |
| 315 | |
| 316 | def on_error(self, namespace=None): |
| 317 | """Decorator to define a custom error handler for SocketIO events. |
no outgoing calls
no test coverage detected