Connect, send a message, yield responses, and disconnect.
(message)
| 90 | |
| 91 | |
| 92 | def send_websocket_message(message): |
| 93 | """Connect, send a message, yield responses, and disconnect.""" |
| 94 | ws = connect_websocket() |
| 95 | if ws: |
| 96 | try: |
| 97 | ws.send(json.dumps({"message": message, "session_id": str(uuid.uuid4())})) |
| 98 | while True: |
| 99 | try: |
| 100 | response = ws.recv() |
| 101 | yield response |
| 102 | except websocket.WebSocketConnectionClosedException: |
| 103 | break |
| 104 | finally: |
| 105 | disconnect_websocket() |
| 106 | |
| 107 | |
| 108 | # Accept user input |
no test coverage detected