()
| 47 | } |
| 48 | |
| 49 | connectWebSocket() { |
| 50 | const wsUrl = `ws://${window.location.host}/ws/visualizer`; |
| 51 | this.ws = new WebSocket(wsUrl); |
| 52 | |
| 53 | this.ws.onmessage = (event) => { |
| 54 | try { |
| 55 | this.data = JSON.parse(event.data); |
| 56 | this.render(); |
| 57 | } catch (e) { |
| 58 | console.error('Failed to parse visualization data:', e); |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | this.ws.onclose = () => { |
| 63 | setTimeout(() => this.connectWebSocket(), 1000); |
| 64 | }; |
| 65 | } |
| 66 | |
| 67 | render() { |
| 68 | const ctx = this.ctx; |