Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/event-bus-client/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class EventClient<
this.#onConnected,
)
}

// fired off right away and then at intervals
#retryConnection = () => {
if (this.#retryCount < this.#maxRetries) {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading