diff --git a/packages/event-bus-client/src/plugin.ts b/packages/event-bus-client/src/plugin.ts index 6372ea1f..9530ba7a 100644 --- a/packages/event-bus-client/src/plugin.ts +++ b/packages/event-bus-client/src/plugin.ts @@ -44,6 +44,7 @@ export class EventClient< this.#onConnected, ) } + // fired off right away and then at intervals #retryConnection = () => { if (this.#retryCount < this.#maxRetries) { @@ -77,14 +78,19 @@ export class EventClient< debug = false, enabled = true, reconnectEveryMs = 300, + noServerEvents = false, }: { pluginId: TPluginId debug?: boolean reconnectEveryMs?: number enabled?: boolean + noServerEvents?: boolean }) { + const runningOnServer = typeof window === 'undefined' + this.#pluginId = pluginId - this.#enabled = enabled + // disables events on server if noServerEvents is active, defaults to #enabled outside this environment + this.#enabled = enabled && !(noServerEvents && runningOnServer) this.#eventTarget = this.getGlobalTarget this.#debug = debug this.debugLog(' Initializing event subscription for plugin', this.#pluginId) @@ -94,6 +100,11 @@ export class EventClient< this.#connectEveryMs = reconnectEveryMs } + // for debugging purposes + get isEnabled() { + return this.#enabled + } + private startConnectLoop() { // if connected, trying to connect, or the internalId is already set, do nothing if (this.#connectIntervalId !== null || this.#connected) return