Handle a connection from a spectator: watch an existing game.
(websocket, watch_key)
| 141 | |
| 142 | |
| 143 | async def watch(websocket, watch_key): |
| 144 | """ |
| 145 | Handle a connection from a spectator: watch an existing game. |
| 146 | |
| 147 | """ |
| 148 | # Find the Connect Four game. |
| 149 | try: |
| 150 | game, connected = WATCH[watch_key] |
| 151 | except KeyError: |
| 152 | await error(websocket, "Game not found.") |
| 153 | return |
| 154 | |
| 155 | # Register to receive moves from this game. |
| 156 | connected.add(websocket) |
| 157 | try: |
| 158 | # Send previous moves, in case the game already started. |
| 159 | await replay(websocket, game) |
| 160 | # Keep the connection open, but don't receive any messages. |
| 161 | await websocket.wait_closed() |
| 162 | finally: |
| 163 | connected.remove(websocket) |
| 164 | |
| 165 | |
| 166 | async def handler(websocket): |
no test coverage detected
searching dependent graphs…