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