()
| 230 | } |
| 231 | |
| 232 | private connectWebSocket() { |
| 233 | this.debugLog('Connecting to WebSocket server') |
| 234 | |
| 235 | const wsProtocol = this.#protocol === 'https' ? 'wss' : 'ws' |
| 236 | this.#socket = new WebSocket( |
| 237 | `${wsProtocol}://${this.#host}:${this.#port}/__devtools/ws`, |
| 238 | ) |
| 239 | this.#socket.onopen = () => { |
| 240 | this.debugLog('WebSocket connection opened') |
| 241 | this.flushPendingServerEvents() |
| 242 | } |
| 243 | this.#socket.onmessage = (e) => { |
| 244 | this.debugLog('Received message from server', e.data) |
| 245 | this.handleEventReceived(e.data) |
| 246 | } |
| 247 | this.#socket.onclose = () => { |
| 248 | this.debugLog('WebSocket connection closed') |
| 249 | this.#socket = null |
| 250 | // Drop any still-queued events — there is no open socket to deliver them. |
| 251 | this.#pendingServerEvents = [] |
| 252 | } |
| 253 | this.#socket.onerror = () => { |
| 254 | this.debugLog('WebSocket connection error') |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | private connect() { |
| 259 | try { |
no test coverage detected