diff --git a/src/app/main/monitor.ts b/src/app/main/monitor.ts index 05d5b86..4578722 100644 --- a/src/app/main/monitor.ts +++ b/src/app/main/monitor.ts @@ -374,6 +374,7 @@ export class EmbeddedPresenceMonitor extends ZncDiscordPresence { disable() { this._running = 0; + this.skipIntervalInCurrentLoop(); } get enabled() { @@ -432,6 +433,7 @@ export class EmbeddedProxyPresenceMonitor extends ZncProxyDiscordPresence { disable() { this._running = 0; + this.skipIntervalInCurrentLoop(); } get enabled() { diff --git a/src/common/presence.ts b/src/common/presence.ts index 2a852e6..383d826 100644 --- a/src/common/presence.ts +++ b/src/common/presence.ts @@ -604,7 +604,11 @@ export class ZncProxyDiscordPresence extends Loop { } } - async useEventStream() { + events: EventSource | null = null; + + useEventStream() { + if (this.events) this.events.close(); + const events = new EventSource(this.eventstream_url ?? this.presence_url, { headers: { 'User-Agent': getUserAgent(), @@ -635,6 +639,8 @@ export class ZncProxyDiscordPresence extends Loop { return a ? [...a, ..._listeners.call(events, type, ...args)] : _listeners.call(events, type, ...args); }; + this.events = events; + events.onopen = event => { debugEventStream('EventSource connected', event); }; diff --git a/src/util/loop.ts b/src/util/loop.ts index 93410a1..44acf27 100644 --- a/src/util/loop.ts +++ b/src/util/loop.ts @@ -80,6 +80,7 @@ export abstract class EmbeddedLoop extends Loop { disable() { this._running = 0; + this.skipIntervalInCurrentLoop(); } get enabled() {