Fix stopping presence monitors with event streams

This commit is contained in:
Samuel Elliott 2022-11-16 16:49:31 +00:00
parent fa877d5bd7
commit b916e719bf
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 10 additions and 1 deletions

View File

@ -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() {

View File

@ -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);
};

View File

@ -80,6 +80,7 @@ export abstract class EmbeddedLoop extends Loop {
disable() {
this._running = 0;
this.skipIntervalInCurrentLoop();
}
get enabled() {