| 128 | return cast(bytes, message["bytes"]) |
| 129 | |
| 130 | async def receive_json(self, mode: str = "text") -> Any: |
| 131 | if mode not in {"text", "binary"}: |
| 132 | raise RuntimeError('The "mode" argument should be "text" or "binary".') |
| 133 | if self.application_state != WebSocketState.CONNECTED: |
| 134 | raise RuntimeError('WebSocket is not connected. Need to call "accept" first.') |
| 135 | message = await self.receive() |
| 136 | self._raise_on_disconnect(message) |
| 137 | |
| 138 | if mode == "text": |
| 139 | text = message["text"] |
| 140 | else: |
| 141 | text = message["bytes"].decode("utf-8") |
| 142 | return json.loads(text) |
| 143 | |
| 144 | async def iter_text(self) -> AsyncIterator[str]: |
| 145 | try: |