diff --git a/frontend/app/player/MessageDistributor/MessageDistributor.ts b/frontend/app/player/MessageDistributor/MessageDistributor.ts index 1c7da6485..d60ae1790 100644 --- a/frontend/app/player/MessageDistributor/MessageDistributor.ts +++ b/frontend/app/player/MessageDistributor/MessageDistributor.ts @@ -207,12 +207,12 @@ export default class MessageDistributor extends StatedScreen { move(t: number, index?: number): void { const stateToUpdate: Partial = {}; /* == REFACTOR_ME == */ - const lastLoadedLocationMsg = this.loadedLocationManager.moveToLast(t, index); + const lastLoadedLocationMsg = this.loadedLocationManager.moveGetLast(t, index); if (!!lastLoadedLocationMsg) { setListsStartTime(lastLoadedLocationMsg.time) this.navigationStartOffset = lastLoadedLocationMsg.navigationStart - this.sessionStart; } - const llEvent = this.locationEventManager.moveToLast(t, index); + const llEvent = this.locationEventManager.moveGetLast(t, index); if (!!llEvent) { if (llEvent.domContentLoadedTime != null) { stateToUpdate.domContentLoadedTime = { @@ -231,22 +231,22 @@ export default class MessageDistributor extends StatedScreen { } } /* === */ - const lastLocationMsg = this.locationManager.moveToLast(t, index); + const lastLocationMsg = this.locationManager.moveGetLast(t, index); if (!!lastLocationMsg) { stateToUpdate.location = lastLocationMsg.url; } - const lastConnectionInfoMsg = this.connectionInfoManger.moveToLast(t, index); + const lastConnectionInfoMsg = this.connectionInfoManger.moveGetLast(t, index); if (!!lastConnectionInfoMsg) { stateToUpdate.connType = lastConnectionInfoMsg.type; stateToUpdate.connBandwidth = lastConnectionInfoMsg.downlink; } - const lastPerformanceTrackMessage = this.performanceTrackManager.moveToLast(t, index); + const lastPerformanceTrackMessage = this.performanceTrackManager.moveGetLast(t, index); if (!!lastPerformanceTrackMessage) { stateToUpdate.performanceChartTime = lastPerformanceTrackMessage.time; } LIST_NAMES.forEach(key => { - const lastMsg = this.lists[key].moveToLast(t, key === 'exceptions' ? undefined : index); + const lastMsg = this.lists[key].moveGetLast(t, key === 'exceptions' ? undefined : index); if (lastMsg != null) { stateToUpdate[`${key}ListNow`] = this.lists[key].listNow; } @@ -256,19 +256,19 @@ export default class MessageDistributor extends StatedScreen { /* Sequence of the managers is important here */ // Preparing the size of "screen" - const lastResize = this.resizeManager.moveToLast(t, index); + const lastResize = this.resizeManager.moveGetLast(t, index); if (!!lastResize) { this.setSize(lastResize) } this.pagesManager.moveReady(t).then(() => { - const lastScroll = this.scrollManager.moveToLast(t, index); + const lastScroll = this.scrollManager.moveGetLast(t, index); if (!!lastScroll && this.window) { this.window.scrollTo(lastScroll.x, lastScroll.y); } // Moving mouse and setting :hover classes on ready view this.mouseMoveManager.move(t); - const lastClick = this.clickManager.moveToLast(t); + const lastClick = this.clickManager.moveGetLast(t); if (!!lastClick && t - lastClick.time < 600) { // happend during last 600ms this.cursor.click(); } diff --git a/frontend/app/player/MessageDistributor/managers/ActivityManager.ts b/frontend/app/player/MessageDistributor/managers/ActivityManager.ts index ba17d295e..b70e4aefd 100644 --- a/frontend/app/player/MessageDistributor/managers/ActivityManager.ts +++ b/frontend/app/player/MessageDistributor/managers/ActivityManager.ts @@ -27,14 +27,14 @@ export default class ActivityManager extends ListWalker { updateAcctivity(time: number) { if (time - this.lastActivity >= this.minInterval) { - this.add(new SkipIntervalCls(this.lastActivity, time)); + this.append(new SkipIntervalCls(this.lastActivity, time)); } this.lastActivity = time; } end() { if (this.endTime - this.lastActivity >= this.minInterval) { - this.add(new SkipIntervalCls(this.lastActivity, this.endTime)); + this.append(new SkipIntervalCls(this.lastActivity, this.endTime)); } } diff --git a/frontend/app/player/MessageDistributor/managers/DOMManager.ts b/frontend/app/player/MessageDistributor/managers/DOMManager.ts index 685a34f2c..187ebc8a0 100644 --- a/frontend/app/player/MessageDistributor/managers/DOMManager.ts +++ b/frontend/app/player/MessageDistributor/managers/DOMManager.ts @@ -40,12 +40,12 @@ export default class DOMManager extends ListWalker { if (!this.nodeScrollManagers[ m.id ]) { this.nodeScrollManagers[ m.id ] = new ListWalker(); } - this.nodeScrollManagers[ m.id ].add(m); + this.nodeScrollManagers[ m.id ].append(m); return; //case "css_insert_rule": // || //set_css_data ??? //case "css_delete_rule": // (m.tp === "set_node_attribute" && this.isLink[ m.id ] && m.key === "href")) { - // this.stylesManager.add(m); + // this.stylesManager.append(m); // return; default: if (m.tp === "create_element_node") { @@ -62,7 +62,7 @@ export default class DOMManager extends ListWalker { logger.log("Ignorring message: ", m) return; // Ignoring... } - super.add(m); + super.append(m); } } @@ -299,7 +299,7 @@ export default class DOMManager extends ListWalker { moveReady(t: number): Promise { this.moveApply(t, this.applyMessage); // This function autoresets pointer if necessary (better name?) this.nodeScrollManagers.forEach(manager => { - const msg = manager.moveToLast(t); // TODO: reset (?) + const msg = manager.moveGetLast(t); // TODO: reset (?) if (!!msg && !!this.nl[msg.id]) { const node = this.nl[msg.id] as HTMLElement; diff --git a/frontend/app/player/MessageDistributor/managers/ListWalker.ts b/frontend/app/player/MessageDistributor/managers/ListWalker.ts index dcfe5cd96..63f549338 100644 --- a/frontend/app/player/MessageDistributor/managers/ListWalker.ts +++ b/frontend/app/player/MessageDistributor/managers/ListWalker.ts @@ -1,26 +1,19 @@ import type { Timed } from '../messages/timed'; export default class ListWalker { - // Optimisation: #prop compiles to method that costs mor than strict property call. - _p = 0; - _list: Array; - constructor(list: Array = []) { - this._list = list; - } - - add(m: T): void { - return this.append(m); - } + private p = 0 + constructor(private _list: Array = []) {} append(m: T): void { if (this.length > 0 && this.last && m.time < this.last.time) { - console.error("Trying to append message with the less time then the list tail: ", m); + console.error("Trying to append message with the less time then the list tail: ", m) + return } this._list.push(m); } reset(): void { - this._p = 0; + this.p = 0 } sort(comparator): void { @@ -32,14 +25,6 @@ export default class ListWalker { this._list.forEach(f); } - // set pointer(p: number): void { - // if (p >= this.length || p < 0) { - // // console.error("Trying to set wrong pointer") - // return; - // } - // this._p = p; - // } - get last(): T | null { if (this._list.length === 0) { return null; @@ -48,17 +33,17 @@ export default class ListWalker { } get current(): T | null { - if (this._p === 0) { + if (this.p === 0) { return null; } - return this._list[ this._p - 1 ]; + return this._list[ this.p - 1 ]; } get timeNow(): number { - if (this._p === 0) { + if (this.p === 0) { return 0; } - return this._list[ this._p - 1 ].time; + return this._list[ this.p - 1 ].time; } get length(): number { @@ -79,7 +64,7 @@ export default class ListWalker { } get listNow(): Array { - return this._list.slice(0, this._p); + return this._list.slice(0, this.p); } get list(): Array { @@ -91,15 +76,15 @@ export default class ListWalker { } get countNow(): number { - return this._p; + return this.p; } /* Returns last message with the time <= t. Assumed that the current message is already handled so - if pointer doesn't cahnge is returned. + if pointer doesn't cahnge is returned. */ - moveToLast(t: number, index?: number): T | null { + moveGetLast(t: number, index?: number): T | null { let key: string = "time"; //TODO let val = t; if (index) { @@ -108,42 +93,29 @@ export default class ListWalker { } let changed = false; - while (this._p < this.length && this._list[this._p][key] <= val) { - this._p++; + while (this.p < this.length && this._list[this.p][key] <= val) { + this.p++; changed = true; } - while (this._p > 0 && this._list[ this._p - 1 ][key] > val) { - this._p--; + while (this.p > 0 && this._list[ this.p - 1 ][key] > val) { + this.p--; changed = true; } - return changed ? this._list[ this._p - 1 ] : null; + return changed ? this._list[ this.p - 1 ] : null; } - // moveToLastByIndex(i: number): ?T { - // let changed = false; - // while (!!this._list[this._p] && this._list[this._p]._index <= i) { - // this._p++; - // changed = true; - // } - // while (this._p > 0 && this._list[ this._p - 1 ]._index > i) { - // this._p--; - // changed = true; - // } - // return changed ? this._list[ this._p - 1 ] : undefined; - // } - - moveApply(t: number, fn: (T) => void): void { + moveApply(t: number, fn: (T) => void, fnBack?: (T) => void): void { // Applying only in increment order for now if (t < this.timeNow) { this.reset(); } - while (!!this._list[this._p] && this._list[this._p].time <= t) { - fn(this._list[ this._p++ ]); + while (!!this._list[this.p] && this._list[this.p].time <= t) { + fn(this._list[ this.p++ ]); + } + while (fnBack && this.p > 0 && this._list[ this.p - 1 ].time > t) { + fnBack(this._list[ --this.p ]); } - //while (this._p > 0 && this._list[ this._p - 1 ].time > t) { - // fnBack(this._list[ --this._p ]); - //} } } \ No newline at end of file diff --git a/frontend/app/player/MessageDistributor/managers/MouseMoveManager.ts b/frontend/app/player/MessageDistributor/managers/MouseMoveManager.ts index 9525a543d..f92d53ee9 100644 --- a/frontend/app/player/MessageDistributor/managers/MouseMoveManager.ts +++ b/frontend/app/player/MessageDistributor/managers/MouseMoveManager.ts @@ -32,7 +32,7 @@ export default class MouseMoveManager extends ListWalker { } move(t: number) { - const lastMouseMove = this.moveToLast(t); + const lastMouseMove = this.moveGetLast(t); if (!!lastMouseMove){ this.screen.cursor.move(lastMouseMove); //window.getComputedStyle(this.screen.getCursorTarget()).cursor === 'pointer' // might nfluence performance though diff --git a/frontend/app/player/MessageDistributor/managers/PagesManager.js b/frontend/app/player/MessageDistributor/managers/PagesManager.js index d5816c57c..01909e194 100644 --- a/frontend/app/player/MessageDistributor/managers/PagesManager.js +++ b/frontend/app/player/MessageDistributor/managers/PagesManager.js @@ -25,13 +25,13 @@ export default class PagesManager extends ListWalker { */ add(m: TimedMessage): void { if (m.tp === "create_document") { - super.add(new DOMManager(this.#screen, this.#isMobile, m.time)) + super.append(new DOMManager(this.#screen, this.#isMobile, m.time)) } if (this.last === null) { // Log wrong return; } - this.last.add(m); + this.last.append(m); } sort(comparator) { @@ -39,7 +39,7 @@ export default class PagesManager extends ListWalker { } moveReady(t: number): Promise { - const requiredPage = this.moveToLast(t); + const requiredPage = this.moveGetLast(t); if (!!requiredPage) { this.#currentPage = requiredPage; this.#currentPage.reset(); // Otherwise it won't apply create_document diff --git a/frontend/app/player/MessageDistributor/managers/PerformanceTrackManager.ts b/frontend/app/player/MessageDistributor/managers/PerformanceTrackManager.ts index 4c756616e..ceace6581 100644 --- a/frontend/app/player/MessageDistributor/managers/PerformanceTrackManager.ts +++ b/frontend/app/player/MessageDistributor/managers/PerformanceTrackManager.ts @@ -62,7 +62,7 @@ export default class PerformanceTrackManager extends ListWalker list.moveToLast(0)); // In case of negative values + Object.values(this.lists).forEach(list => list.moveGetLast(0)); // In case of negative values }) if (session.socket == null || typeof session.socket.jwt !== "string" || typeof session.socket.url !== "string") { @@ -190,8 +190,8 @@ export default class ImagePlayer { _setTime(ts) { ts = Math.max(Math.min(ts, this.state.endTime), 0); this.state.setTime(ts); - Object.values(this.lists).forEach(list => list.moveToLast(ts)); - const screen = this._screens.moveToLast(ts); + Object.values(this.lists).forEach(list => list.moveGetLast(ts)); + const screen = this._screens.moveGetLast(ts); if (screen != null) { const { dataURL, width, height } = screen; this.state.setSize(width, height); @@ -199,7 +199,7 @@ export default class ImagePlayer { //this._screen.style.backgroundImage = `url(${screen.dataURL})`; screen.loadImage.then(() => this._screen.style.backgroundImage = `url(${screen.dataURL})`); } - const lastClick = this._clicks.moveToLast(ts); + const lastClick = this._clicks.moveGetLast(ts); if (lastClick != null && lastClick.time > ts - 600) { this._animateClick(lastClick); } diff --git a/frontend/app/player/ios/PerformanceList.js b/frontend/app/player/ios/PerformanceList.js index 5da8272dc..47d7918f3 100644 --- a/frontend/app/player/ios/PerformanceList.js +++ b/frontend/app/player/ios/PerformanceList.js @@ -27,8 +27,8 @@ export default class PerformanceList { return this._list.count; } - moveToLast(t) { - this._list.moveToLast(t); + moveGetLast(t) { + this._list.moveGetLast(t); } append(m) { diff --git a/frontend/app/player/ios/ScreenList.js b/frontend/app/player/ios/ScreenList.js index a19b9bd2a..ef6d1e73f 100644 --- a/frontend/app/player/ios/ScreenList.js +++ b/frontend/app/player/ios/ScreenList.js @@ -34,8 +34,8 @@ export default class ScreenList { this._walker._list.splice(p, 0, m); } - moveToLast(time) { - return this._walker.moveToLast(time); + moveGetLast(time) { + return this._walker.moveGetLast(time); } insertScreen(time, width, height, arrayBuffer): void {