From 1a9cbe5ed170f219765b7118cd5f3f64314c8a31 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Wed, 7 Jun 2023 13:10:45 +0200 Subject: [PATCH] fix(tracker): fix annotation call typo; fix control reset on page reload --- .../app/player/web/assist/AssistManager.ts | 3 +- frontend/app/player/web/assist/Call.ts | 7 ++- .../app/player/web/assist/RemoteControl.ts | 2 +- tracker/tracker-assist/src/Assist.ts | 53 +++++++++++-------- tracker/tracker-assist/src/RemoteControl.ts | 8 +-- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/frontend/app/player/web/assist/AssistManager.ts b/frontend/app/player/web/assist/AssistManager.ts index 3c5436283..a921a889b 100644 --- a/frontend/app/player/web/assist/AssistManager.ts +++ b/frontend/app/player/web/assist/AssistManager.ts @@ -167,7 +167,6 @@ export default class AssistManager { this.setStatus(ConnectionStatus.WaitingMessages) // TODO: reconnect happens frequently on bad network }) - let currentTab = '' socket.on('messages', messages => { jmr.append(messages.data) // as RawMessage[] if (waitingForMessages) { @@ -192,7 +191,7 @@ export default class AssistManager { const { active } = data this.clearDisconnectTimeout() !this.inactiveTimeout && this.setStatus(ConnectionStatus.Connected) - if (tabId !== currentTab) { + if (Boolean(tabId) && tabId !== this.store.get().currentTab) { this.store.update({ currentTab: tabId }) } if (typeof active === "boolean") { diff --git a/frontend/app/player/web/assist/Call.ts b/frontend/app/player/web/assist/Call.ts index f58c85ea7..cf6d9afd2 100644 --- a/frontend/app/player/web/assist/Call.ts +++ b/frontend/app/player/web/assist/Call.ts @@ -227,7 +227,12 @@ export default class Call { private _callSessionPeer() { if (![CallingState.NoCall, CallingState.Reconnecting].includes(this.store.get().calling)) { return } this.store.update({ calling: CallingState.Connecting }) - this._peerConnection(this.peerID); + const tab = this.store.get().currentTab + if (!this.store.get().currentTab) { + console.warn('No tab data to connect to peer') + } + console.log(tab) + void this._peerConnection(`${this.peerID}-${tab || Object.keys(this.store.get().tabs)[0]}`); this.emitData("_agent_name", appStore.getState().getIn([ 'user', 'account', 'name'])) } diff --git a/frontend/app/player/web/assist/RemoteControl.ts b/frontend/app/player/web/assist/RemoteControl.ts index 12a11c19c..ecde14eb6 100644 --- a/frontend/app/player/web/assist/RemoteControl.ts +++ b/frontend/app/player/web/assist/RemoteControl.ts @@ -145,7 +145,7 @@ export default class RemoteControl { const annot = this.annot = new AnnotationCanvas() annot.mount(this.screen.overlay) annot.canvas.addEventListener("mousedown", e => { - const data = this.screen.getInternalViewportCoordin1ates(e) + const data = this.screen.getInternalViewportCoordinates(e) annot.start([ data.x, data.y ]) this.emitData("startAnnotation", [ data.x, data.y ]) }) diff --git a/tracker/tracker-assist/src/Assist.ts b/tracker/tracker-assist/src/Assist.ts index 5c288cae2..b50342d39 100644 --- a/tracker/tracker-assist/src/Assist.ts +++ b/tracker/tracker-assist/src/Assist.ts @@ -188,24 +188,19 @@ export default class Assist { app.debug.log('Socket:', ...args) }) - this.remoteControl = new RemoteControl( - this.options, - id => { - if (!callUI) { - callUI = new CallWindow(app.debug.error, this.options.callUITemplate) - } - if (this.remoteControl){ - callUI?.showRemoteControl(this.remoteControl.releaseControl) - } - this.agents[id].onControlReleased = this.options.onRemoteControlStart(this.agents[id]?.agentInfo) - this.emit('control_granted', id) - annot = new AnnotationCanvas() - annot.mount() - return callingAgents.get(id) - }, - (id, isDenied) => onRelease(id, isDenied), - ) - + const onGrand = (id) => { + if (!callUI) { + callUI = new CallWindow(app.debug.error, this.options.callUITemplate) + } + if (this.remoteControl){ + callUI?.showRemoteControl(this.remoteControl.releaseControl) + } + this.agents[id].onControlReleased = this.options.onRemoteControlStart(this.agents[id]?.agentInfo) + this.emit('control_granted', id) + annot = new AnnotationCanvas() + annot.mount() + return callingAgents.get(id) + } const onRelease = (id, isDenied) => { { if (id) { @@ -230,6 +225,12 @@ export default class Assist { } } + this.remoteControl = new RemoteControl( + this.options, + onGrand, + (id, isDenied) => onRelease(id, isDenied), + ) + const onAcceptRecording = () => { socket.emit('recording_accepted') } @@ -280,7 +281,11 @@ export default class Assist { this.assistDemandedRestart = true this.app.stop() setTimeout(() => { - this.app.start().then(() => { this.assistDemandedRestart = false }).catch(e => app.debug.error(e)) + this.app.start().then(() => { this.assistDemandedRestart = false }) + .then(() => { + this.remoteControl?.reconnect([id,]) + }) + .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 }, 500) }) @@ -295,11 +300,14 @@ export default class Assist { this.assistDemandedRestart = true this.app.stop() setTimeout(() => { - this.app.start().then(() => { this.assistDemandedRestart = false }).catch(e => app.debug.error(e)) + this.app.start().then(() => { this.assistDemandedRestart = false }) + .then(() => { + this.remoteControl?.reconnect(ids) + }) + .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 }, 500) - this.remoteControl?.reconnect(ids) }) socket.on('AGENT_DISCONNECTED', (id) => { @@ -547,7 +555,8 @@ export default class Assist { } private clean() { - this.remoteControl?.releaseControl() + // sometimes means new agent connected so we keep id for control + this.remoteControl?.releaseControl(false, true) if (this.peer) { this.peer.destroy() this.app.debug.log('Peer destroyed') diff --git a/tracker/tracker-assist/src/RemoteControl.ts b/tracker/tracker-assist/src/RemoteControl.ts index 2f139c68d..1533c2ebe 100644 --- a/tracker/tracker-assist/src/RemoteControl.ts +++ b/tracker/tracker-assist/src/RemoteControl.ts @@ -67,14 +67,16 @@ export default class RemoteControl { }) } - releaseControl = (isDenied?: boolean) => { + releaseControl = (isDenied?: boolean, keepId?: boolean) => { if (this.confirm) { this.confirm.remove() this.confirm = null } this.resetMouse() this.status = RCStatus.Disabled - sessionStorage.removeItem(this.options.session_control_peer_key) + if (!keepId) { + sessionStorage.removeItem(this.options.session_control_peer_key) + } this.onRelease(this.agentID, isDenied) this.agentID = null } @@ -90,7 +92,7 @@ export default class RemoteControl { this.mouse = new Mouse(agentName) this.mouse.mount() document.addEventListener('visibilitychange', () => { - if (document.hidden) this.releaseControl(false) + if (document.hidden) this.releaseControl(false, false) }) }