fix(tracker): fix fix events in assist

This commit is contained in:
nick-delirium 2023-06-06 09:53:36 +02:00
parent 3c906fa3fd
commit 5f8fed8b02
14 changed files with 64 additions and 26 deletions

View file

@ -2,7 +2,7 @@
import { Decoder } from "syncod";
import logger from 'App/logger';
import type { Store } from 'Player';
import type { Store, ILog } from 'Player';
import ListWalker from '../common/ListWalker';
import MouseMoveManager from './managers/MouseMoveManager';
@ -15,8 +15,6 @@ import type {
MouseClick,
} from './messages';
import Lists from './Lists';
import Screen, {
INITIAL_STATE as SCREEN_INITIAL_STATE,
State as ScreenState,
@ -27,6 +25,13 @@ import type { SkipInterval } from './managers/ActivityManager';
import TabSessionManager, { TabState } from "Player/web/TabManager";
import ActiveTabManager from "Player/web/managers/ActiveTabManager";
interface RawList {
event: Record<string, any>[] & { tabId: string | null }
frustrations: Record<string, any>[] & { tabId: string | null }
stack: Record<string, any>[] & { tabId: string | null }
exceptions: ILog[]
}
export interface State extends ScreenState {
skipIntervals: SkipInterval[],
connType?: string,
@ -103,14 +108,27 @@ export default class MessageManager {
}
public getListsFullState = () => {
// fullstate by tab
console.log(Object.values(this.tabs)[0].getListsFullState())
const fullState: Record<string, any> = {}
for (let tab in Object.keys(this.tabs)) {
fullState[tab] = this.tabs[tab].getListsFullState()
}
return Object.values(this.tabs)[0].getListsFullState()
}
public updateLists(lists: Partial<InitialLists>) {
// update each tab with tabid from events !!!
Object.values(this.tabs)[0]?.updateLists?.(lists)
public updateLists(lists: RawList) {
// update each tab with tabid from events
for (let tab in Object.keys(this.tabs)) {
const list = {
event: lists.event.filter((e) => e.tabId === tab),
frustrations: lists.frustrations.filter((e) => e.tabId === tab),
stack: lists.stack.filter((e) => e.tabId === tab),
exceptions: lists.exceptions.filter((e) => e.tabId === tab),
}
// saving some microseconds here probably
if (Object.values(list).some((l) => l.length > 0)) {
this.tabs[tab]!.updateLists(list)
}
}
}
public _sortMessagesHack = (msgs: Message[]) => {
@ -153,6 +171,8 @@ export default class MessageManager {
}
move(t: number): any {
// usually means waiting for messages from live session
if (Object.keys(this.tabs).length === 0) return;
this.activeTabManager.moveReady(t).then(tabId => {
// Moving mouse and setting :hover classes on ready view
this.mouseMoveManager.move(t);

View file

@ -83,7 +83,7 @@ export default class WebPlayer extends Player {
}
updateLists = (session: any) => {
let lists = {
const lists = {
event: session.events || [],
frustrations: session.frustrations || [],
stack: session.stackEvents || [],

View file

@ -187,7 +187,7 @@ export default class AssistManager {
})
socket.on('UPDATE_SESSION', (evData) => {
const { metadata, data } = evData
const { metadata = {}, data = {} } = evData
const { tabId } = metadata
const { active } = data
this.clearDisconnectTimeout()

View file

@ -55,7 +55,6 @@ export default class RemoteControl {
}
private emitData = (event: string, data?: any) => {
console.log('emit data', event, data, { meta: { tabId: this.store.get().currentTab }, data })
this.socket.emit(event, { meta: { tabId: this.store.get().currentTab }, data })
}

View file

@ -18,7 +18,10 @@ export default class MStreamReader {
if (msg === null) { return null }
if (msg.tp === MType.Timestamp) {
this.startTs = this.startTs || msg.timestamp
this.t = msg.timestamp - this.startTs
const newT = msg.timestamp - this.startTs
if (newT > this.t) {
this.t = newT
}
return this.readNext()
}
if (msg.tp === MType.TabData) {

View file

@ -13,6 +13,7 @@ export interface ILog {
time: number
index?: number
errorId?: string
tabId?: string
}
export const Log = (log: ILog) => ({

View file

@ -23,6 +23,7 @@ interface IEvent {
key: number;
label: string;
targetPath: string;
tabId?: string;
target: {
path: string;
label: string;
@ -69,12 +70,14 @@ class Event {
time: IEvent['time'];
label: IEvent['label'];
target: IEvent['target'];
tabId: IEvent['tabId'];
constructor(event: IEvent) {
Object.assign(this, {
time: event.time,
label: event.label,
key: event.key,
tabId: event.tabId,
target: {
path: event.target?.path || event.targetPath,
label: event.target?.label,

View file

@ -1,7 +1,7 @@
{
"name": "@openreplay/tracker-assist",
"description": "Tracker plugin for screen assistance through the WebRTC",
"version": "6.0.0",
"version": "6.0.1-4",
"keywords": [
"WebRTC",
"assistance",
@ -13,6 +13,7 @@
"type": "module",
"main": "./lib/index.js",
"scripts": {
"tsrun": "tsc",
"lint": "eslint src --ext .ts,.js --fix --quiet",
"build": "npm run build-es && npm run build-cjs",
"build-es": "rm -Rf lib && tsc && npm run replace-versions",
@ -25,7 +26,8 @@
"prepare": "cd ../../ && husky install tracker/.husky/",
"lint-front": "lint-staged",
"test": "jest --coverage=false",
"test:ci": "jest --coverage=true"
"test:ci": "jest --coverage=true",
"postversion": "npm run build"
},
"dependencies": {
"csstype": "^3.0.10",
@ -43,13 +45,13 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"replace-in-files-cli": "^1.0.0",
"typescript": "^4.6.0-dev.20211126",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"ts-jest": "^29.0.3"
"ts-jest": "^29.0.3",
"typescript": "^4.6.0-dev.20211126"
},
"husky": {
"hooks": {

View file

@ -279,7 +279,10 @@ export default class Assist {
}
this.assistDemandedRestart = true
this.app.stop()
this.app.start().then(() => { this.assistDemandedRestart = false }).catch(e => app.debug.error(e))
setTimeout(() => {
this.app.start().then(() => { this.assistDemandedRestart = false }).catch(e => app.debug.error(e))
// TODO: check if it's needed; basically allowing some time for the app to finish everything before starting again
}, 350)
})
socket.on('AGENTS_CONNECTED', (ids: string[]) => {
ids.forEach(id =>{

View file

@ -2,6 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "./cjs"
"outDir": "./cjs",
"rootDir": "src"
},
"exclude": ["**/*.test.ts"]
}

View file

@ -8,6 +8,8 @@
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"declaration": true,
"outDir": "./lib"
}
"outDir": "./lib",
"rootDir": "src"
},
"exclude": ["**/*.test.ts"]
}

View file

@ -23,7 +23,8 @@
"prepare": "cd ../../ && husky install tracker/.husky/",
"lint-front": "lint-staged",
"test": "jest --coverage=false",
"test:ci": "jest --coverage=true"
"test:ci": "jest --coverage=true",
"postversion": "npm run build"
},
"devDependencies": {
"@babel/core": "^7.10.2",

View file

@ -135,6 +135,6 @@ export default class QueueSender {
setTimeout(() => {
this.token = null
this.queue.length = 0
}, 100)
}, 10)
}
}

View file

@ -45,7 +45,7 @@ function resetSender(): void {
// allowing some time to send last batch
setTimeout(() => {
sender = null
}, 500)
}, 20)
}
}
@ -57,7 +57,9 @@ function reset(): void {
}
resetWriter()
resetSender()
workerStatus = WorkerStatus.NotActive
setTimeout(() => {
workerStatus = WorkerStatus.NotActive
}, 100)
}
function initiateRestart(): void {