Compatibility with extensions

This commit is contained in:
Cohee 2024-04-02 20:25:37 +03:00
parent 534612db87
commit f13e718dc7
3 changed files with 9 additions and 0 deletions

View File

@ -29,6 +29,12 @@ var EventEmitter = function () {
};
EventEmitter.prototype.on = function (event, listener) {
// Unknown event used by external libraries?
if (event === undefined) {
console.trace('EventEmitter: Cannot listen to undefined event');
return;
}
if (typeof this.events[event] !== 'object') {
this.events[event] = [];
}

View File

@ -416,6 +416,7 @@ export const event_types = {
// TODO: Naming convention is inconsistent with other events
CHARACTER_DELETED: 'characterDeleted',
CHARACTER_DUPLICATED: 'character_duplicated',
SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received',
};
export const eventSource = new EventEmitter();

View File

@ -1,3 +1,4 @@
import { eventSource, event_types } from '../script.js';
import { power_user } from './power-user.js';
import { delay } from './utils.js';
@ -257,6 +258,7 @@ export class SmoothEventSourceStream extends EventSourceStream {
hasFocus && await delay(getDelay(lastStr));
controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));
lastStr = parsed.chunk;
hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
}
} catch {
controller.enqueue(event);