From cd0d285a2b2ccbdb05284699de8edbf16a6ece28 Mon Sep 17 00:00:00 2001 From: flolep2607 <24566964+flolep2607@users.noreply.github.com> Date: Wed, 16 Apr 2025 23:25:36 +1200 Subject: [PATCH] feat: can add callback to any event --- src/chart/session.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/chart/session.js b/src/chart/session.js index 1d2ee20..c700e28 100644 --- a/src/chart/session.js +++ b/src/chart/session.js @@ -171,7 +171,7 @@ module.exports = (client) => class ChartSession { * @param {...{}} data Packet data */ #handleEvent(ev, ...data) { - this.#callbacks[ev].forEach((e) => e(...data)); + this.#callbacks[ev]?.forEach((e) => e(...data)); this.#callbacks.event.forEach((e) => e(ev, ...data)); } @@ -531,6 +531,20 @@ module.exports = (client) => class ChartSession { onError(cb) { this.#callbacks.error.push(cb); } + + /** + * When the replay session cursor has moved + * @param {string} event_name + * @param {(index: number) => void} cb + * @event + */ + on(event_name,cb) { + if (!this.#callbacks[event_name]) { + this.#callbacks[event_name] = []; + } + this.#callbacks[event_name].push(cb); + } + /** @type {ChartSessionBridge} */ #chartSession = {