* feat(tracker): add support for multi tab sessions
* feat(backend): added support of multitabs
* fix(backend): added support of deprecated batch meta message to pre-decoder
* fix(backend): fixed nil meta issue for TabData messages in sink
* feat(player): add tabmanager
* feat(player): basic tabchange event support
* feat(player): pick tabstate for console panel and timeline
* fix(player): only display tabs that are created
* feat(player): connect performance, xray and events to tab state
* feat(player): merge all tabs data for overview
* feat(backend/tracker): extract tabdata into separate message from batchmeta
* fix(tracker): fix new session check
* fix(backend): remove batchmetadeprecated
* fix(backend): fix switch case
* fix(player): fix for tab message size
* feat(tracker): check for active tabs with broadcast channel
* feat(tracker): prevent multiple messages
* fix(tracker): ignore beacons from same tab, only ask if token isnt present yet, add small delay before start to wait for answer
* feat(player): support new msg struct in assist player
* fix(player): fix some livepl components for multi tab states
* feat(tracker): add option to disable multitab
* feat(tracker): add multitab to assist plugin
* feat(player): back compat for tab id
* fix(ui): fix missing list in controls
* fix(ui): optional list update
* feat(ui): fix visuals for multitab; use window focus event for tabs
* fix(tracker): fix for dying tests (added tabid to writer, refactored other tests)
* feat(ui): update LivePlayerSubHeader.tsx to support tabs
* feat(backend): added tabs support to devtools mob files
* feat(ui): connect state to current tab properly
* feat(backend): added multitab support to assits
* feat(backend): removed data check in agent message
* feat(backend): debug on
* fix(backend): fixed typo in message broadcast
* feat(backend): fixed issue in connect method
* fix(assist): fixed typo
* feat(assist): added more debug logs
* feat(assist): removed one log
* feat(assist): more logs
* feat(assist): use query.peerId
* feat(assist): more logs
* feat(assist): fixed session update
* fix(assist): fixed getSessions
* fix(assist): fixed request_control broadcast
* fix(assist): fixed typo
* fix(assist): added missed line
* fix(assist): fix typo
* feat(tracker): multitab support for assist sessions
* fix(tracker): fix dead tests (tabid prop)
* fix(tracker): fix yaml
* fix(tracker): timers issue
* fix(ui): fix ui E2E tests with magic?
* feat(assist): multitabs support for ee version
* fix(assist): added missed method import
* fix(tracker): fix fix events in assist
* feat(assist): added back compatibility for sessions without tabId
* fix(assist): apply message's top layer structure before broadcast call
* fix(assist): added random tabID for prev version
* fix(assist): added random tabID for prev version (ee)
* feat(assist): added debug logs
* fix(assist): fix typo in sessions_agents_count method
* fix(assist): fixed more typos in copy-pastes
* fix(tracker): fix restart timings
* feat(backend): added tabIDs for some events
* feat(ui): add tab change event to the user steps bar
* Revert "feat(backend): added tabIDs for some events"
This reverts commit 1467ad7f9f.
* feat(ui): revert timeline and xray to grab events from all tabs
* fix(ui): fix typo
---------
Co-authored-by: Alexander Zavorotynskiy <zavorotynskiy@pm.me>
175 lines
3.7 KiB
TypeScript
175 lines
3.7 KiB
TypeScript
import type { Timed } from './types';
|
|
|
|
export default class ListWalker<T extends Timed> {
|
|
private p = 0 /* Pointer to the "current" item */
|
|
constructor(private _list: Array<T> = []) {}
|
|
|
|
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.time, 'vs', this.last.time, m, this)
|
|
return
|
|
}
|
|
this.list.push(m);
|
|
}
|
|
|
|
insert(m: T): void {
|
|
let index = this.list.findIndex(om => om.time > m.time)
|
|
if (index === -1) {
|
|
index = this.length
|
|
}
|
|
const oldList = this.list
|
|
this._list = [...oldList.slice(0, index), m, ...oldList.slice(index)]
|
|
}
|
|
|
|
reset(): void {
|
|
this.p = 0
|
|
}
|
|
|
|
sort(comparator: (a: T, b: T) => number): void {
|
|
// @ts-ignore
|
|
this.list.sort((m1,m2) => comparator(m1,m2) || (m1._index - m2._index) ); // indexes for sort stability (TODO: fix types???)
|
|
}
|
|
|
|
forEach(f: (item: T) => void):void {
|
|
this.list.forEach(f);
|
|
}
|
|
|
|
get last(): T | null {
|
|
if (this.list.length === 0) {
|
|
return null;
|
|
}
|
|
return this.list.slice(-1)[0];
|
|
}
|
|
|
|
get current(): T | null {
|
|
if (this.p === 0) {
|
|
return null;
|
|
}
|
|
return this.list[ this.p - 1 ];
|
|
}
|
|
|
|
get timeNow(): number {
|
|
if (this.p === 0) {
|
|
return 0;
|
|
}
|
|
return this.list[ this.p - 1 ].time;
|
|
}
|
|
|
|
get length(): number {
|
|
return this.list.length;
|
|
}
|
|
|
|
get maxTime(): number {
|
|
if (this.length === 0) {
|
|
return 0;
|
|
}
|
|
return this.list[ this.length - 1 ].time;
|
|
}
|
|
get minTime(): number {
|
|
if (this.length === 0) {
|
|
return 0;
|
|
}
|
|
return this.list[ 0 ].time;
|
|
}
|
|
|
|
get listNow(): Array<T> {
|
|
return this.list.slice(0, this.p);
|
|
}
|
|
|
|
get list(): Array<T> {
|
|
return this._list;
|
|
}
|
|
|
|
get count(): number {
|
|
return this.length;
|
|
}
|
|
|
|
get countNow(): number {
|
|
return this.p;
|
|
}
|
|
|
|
private hasNext() {
|
|
return this.p < this.length
|
|
}
|
|
private hasPrev() {
|
|
return this.p > 0
|
|
}
|
|
protected moveNext(): T | null {
|
|
return this.hasNext()
|
|
? this.list[ this.p++ ]
|
|
: null
|
|
}
|
|
protected movePrev(): T | null {
|
|
return this.hasPrev()
|
|
? this.list[ --this.p ]
|
|
: null
|
|
}
|
|
|
|
/**
|
|
* @returns last message with the time <= t.
|
|
* Assumed that the current message is already handled so
|
|
* if pointer doesn't change <null> is returned.
|
|
*/
|
|
moveGetLast(t: number, index?: number): T | null {
|
|
let key: string = "time"; //TODO
|
|
let val = t;
|
|
if (index) {
|
|
key = "_index";
|
|
val = index;
|
|
}
|
|
|
|
let changed = false;
|
|
while (this.p < this.length && this.list[this.p][key] <= val) {
|
|
this.moveNext()
|
|
changed = true;
|
|
}
|
|
while (this.p > 0 && this.list[ this.p - 1 ][key] > val) {
|
|
this.movePrev()
|
|
changed = true;
|
|
}
|
|
return changed ? this.list[ this.p - 1 ] : null;
|
|
}
|
|
|
|
moveGetLastDebug(t: number, index?: number): T | null {
|
|
let key: string = "time"; //TODO
|
|
let val = t;
|
|
if (index) {
|
|
key = "_index";
|
|
val = index;
|
|
}
|
|
|
|
let changed = false;
|
|
while (this.p < this.length && this.list[this.p][key] <= val) {
|
|
this.moveNext()
|
|
changed = true;
|
|
}
|
|
while (this.p > 0 && this.list[ this.p - 1 ][key] > val) {
|
|
this.movePrev()
|
|
changed = true;
|
|
}
|
|
|
|
// console.log(this.list[this.p - 1])
|
|
return changed ? this.list[ this.p - 1 ] : null;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Moves over the messages starting from the current+1 to the last one with the time <= t
|
|
* applying callback on each of them
|
|
* @param t - max message time to move to; will move & apply callback while msg.time <= t
|
|
* @param callback - a callback to apply on each message passing by while moving
|
|
*/
|
|
moveApply(t: number, callback: (msg: T) => void): void {
|
|
// Applying only in increment order for now
|
|
if (t < this.timeNow) {
|
|
this.reset();
|
|
}
|
|
|
|
const list = this.list
|
|
while (list[this.p] && list[this.p].time <= t) {
|
|
callback(this.list[ this.p++ ])
|
|
}
|
|
}
|
|
|
|
}
|