MCPcopy Create free account
hub / github.com/TanStack/devtools / emitToServer

Method emitToServer

packages/event-bus/src/client/client.ts:145–171  ·  view source on GitHub ↗
(event: TanStackDevtoolsEvent<string, any>)

Source from the content-addressed store, hash-verified

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') {

Callers 1

ClientEventBusClass · 0.95

Calls 2

debugLogMethod · 0.95
stringifyWithBigIntFunction · 0.90

Tested by

no test coverage detected