(event: TanStackDevtoolsEvent<string, any>)
| 143 | } |
| 144 | |
| 145 | private emitToServer(event: TanStackDevtoolsEvent<string, any>) { |
| 146 | const json = stringifyWithBigInt(event) |
| 147 | // try to emit it to the event bus first |
| 148 | if (this.#socket) { |
| 149 | if (this.#socket.readyState === WebSocket.OPEN) { |
| 150 | this.debugLog('Emitting event to server via WS', event) |
| 151 | this.#socket.send(json) |
| 152 | } else if (this.#socket.readyState === WebSocket.CONNECTING) { |
| 153 | // The socket handshake is still in flight. Buffer the event instead of |
| 154 | // dropping it; it will be sent once the connection opens. |
| 155 | this.debugLog('WebSocket still connecting, queueing event', event) |
| 156 | this.#pendingServerEvents.push(json) |
| 157 | } |
| 158 | // CLOSING/CLOSED sockets cannot deliver; the event is dropped. |
| 159 | return |
| 160 | } |
| 161 | // try to emit to SSE if WebSocket is not available (this will only happen on the client side) |
| 162 | if (this.#eventSource) { |
| 163 | this.debugLog('Emitting event to server via SSE', event) |
| 164 | |
| 165 | fetch(`${this.#protocol}://${this.#host}:${this.#port}/__devtools/send`, { |
| 166 | method: 'POST', |
| 167 | headers: { 'Content-Type': 'application/json' }, |
| 168 | body: json, |
| 169 | }).catch(() => {}) |
| 170 | } |
| 171 | } |
| 172 | start() { |
| 173 | this.debugLog('Starting client event bus') |
| 174 | if (typeof window === 'undefined') { |
no test coverage detected