Event for receiving front-end websocket events. Args: sid: The Socket.IO session id. data: The event data.
(self, sid, data)
| 1088 | ) |
| 1089 | |
| 1090 | async def on_event(self, sid, data): |
| 1091 | """Event for receiving front-end websocket events. |
| 1092 | |
| 1093 | Args: |
| 1094 | sid: The Socket.IO session id. |
| 1095 | data: The event data. |
| 1096 | """ |
| 1097 | # Get the event. |
| 1098 | event = Event.parse_raw(data) |
| 1099 | |
| 1100 | # Get the event environment. |
| 1101 | assert self.app.sio is not None |
| 1102 | environ = self.app.sio.get_environ(sid, self.namespace) |
| 1103 | assert environ is not None |
| 1104 | |
| 1105 | # Get the client headers. |
| 1106 | headers = { |
| 1107 | k.decode("utf-8"): v.decode("utf-8") |
| 1108 | for (k, v) in environ["asgi.scope"]["headers"] |
| 1109 | } |
| 1110 | |
| 1111 | # Get the client IP |
| 1112 | client_ip = environ["REMOTE_ADDR"] |
| 1113 | |
| 1114 | # Process the events. |
| 1115 | async for update in process(self.app, event, sid, headers, client_ip): |
| 1116 | # Emit the update from processing the event. |
| 1117 | await self.emit_update(update=update, sid=sid) |
| 1118 | |
| 1119 | async def on_ping(self, sid): |
| 1120 | """Event for testing the API endpoint. |
nothing calls this directly
no test coverage detected