| 75 | this.#eventTarget.dispatchEvent(new CustomEvent('tanstack-connect-success')) |
| 76 | } |
| 77 | constructor({ |
| 78 | port = 4206, |
| 79 | host = 'localhost', |
| 80 | debug = false, |
| 81 | httpServer, |
| 82 | }: ServerEventBusConfig = {}) { |
| 83 | this.#port = port |
| 84 | this.#host = host |
| 85 | this.#eventTarget = |
| 86 | globalThis.__TANSTACK_EVENT_TARGET__ ?? new EventTarget() |
| 87 | // we want to set the global event target only once so that we can emit/listen to events on the server |
| 88 | if (!globalThis.__TANSTACK_EVENT_TARGET__) { |
| 89 | globalThis.__TANSTACK_EVENT_TARGET__ = this.#eventTarget |
| 90 | } |
| 91 | this.#server = globalThis.__TANSTACK_DEVTOOLS_SERVER__ ?? null |
| 92 | this.#wssServer = globalThis.__TANSTACK_DEVTOOLS_WSS_SERVER__ ?? null |
| 93 | this.#externalServer = httpServer ?? null |
| 94 | this.#debug = debug |
| 95 | this.debugLog('Initializing server event bus') |
| 96 | } |
| 97 | |
| 98 | private debugLog(...args: Array<any>) { |
| 99 | if (this.#debug) { |