fix(tracker): fix annotation call typo; fix control reset on page reload

This commit is contained in:
nick-delirium 2023-06-07 13:10:45 +02:00
parent 2ed4bba33e
commit 1a9cbe5ed1
5 changed files with 44 additions and 29 deletions

View file

@ -167,7 +167,6 @@ export default class AssistManager {
this.setStatus(ConnectionStatus.WaitingMessages) // TODO: reconnect happens frequently on bad network this.setStatus(ConnectionStatus.WaitingMessages) // TODO: reconnect happens frequently on bad network
}) })
let currentTab = ''
socket.on('messages', messages => { socket.on('messages', messages => {
jmr.append(messages.data) // as RawMessage[] jmr.append(messages.data) // as RawMessage[]
if (waitingForMessages) { if (waitingForMessages) {
@ -192,7 +191,7 @@ export default class AssistManager {
const { active } = data const { active } = data
this.clearDisconnectTimeout() this.clearDisconnectTimeout()
!this.inactiveTimeout && this.setStatus(ConnectionStatus.Connected) !this.inactiveTimeout && this.setStatus(ConnectionStatus.Connected)
if (tabId !== currentTab) { if (Boolean(tabId) && tabId !== this.store.get().currentTab) {
this.store.update({ currentTab: tabId }) this.store.update({ currentTab: tabId })
} }
if (typeof active === "boolean") { if (typeof active === "boolean") {

View file

@ -227,7 +227,12 @@ export default class Call {
private _callSessionPeer() { private _callSessionPeer() {
if (![CallingState.NoCall, CallingState.Reconnecting].includes(this.store.get().calling)) { return } if (![CallingState.NoCall, CallingState.Reconnecting].includes(this.store.get().calling)) { return }
this.store.update({ calling: CallingState.Connecting }) 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'])) this.emitData("_agent_name", appStore.getState().getIn([ 'user', 'account', 'name']))
} }

View file

@ -145,7 +145,7 @@ export default class RemoteControl {
const annot = this.annot = new AnnotationCanvas() const annot = this.annot = new AnnotationCanvas()
annot.mount(this.screen.overlay) annot.mount(this.screen.overlay)
annot.canvas.addEventListener("mousedown", e => { annot.canvas.addEventListener("mousedown", e => {
const data = this.screen.getInternalViewportCoordin1ates(e) const data = this.screen.getInternalViewportCoordinates(e)
annot.start([ data.x, data.y ]) annot.start([ data.x, data.y ])
this.emitData("startAnnotation", [ data.x, data.y ]) this.emitData("startAnnotation", [ data.x, data.y ])
}) })

View file

@ -188,9 +188,7 @@ export default class Assist {
app.debug.log('Socket:', ...args) app.debug.log('Socket:', ...args)
}) })
this.remoteControl = new RemoteControl( const onGrand = (id) => {
this.options,
id => {
if (!callUI) { if (!callUI) {
callUI = new CallWindow(app.debug.error, this.options.callUITemplate) callUI = new CallWindow(app.debug.error, this.options.callUITemplate)
} }
@ -202,10 +200,7 @@ export default class Assist {
annot = new AnnotationCanvas() annot = new AnnotationCanvas()
annot.mount() annot.mount()
return callingAgents.get(id) return callingAgents.get(id)
}, }
(id, isDenied) => onRelease(id, isDenied),
)
const onRelease = (id, isDenied) => { const onRelease = (id, isDenied) => {
{ {
if (id) { if (id) {
@ -230,6 +225,12 @@ export default class Assist {
} }
} }
this.remoteControl = new RemoteControl(
this.options,
onGrand,
(id, isDenied) => onRelease(id, isDenied),
)
const onAcceptRecording = () => { const onAcceptRecording = () => {
socket.emit('recording_accepted') socket.emit('recording_accepted')
} }
@ -280,7 +281,11 @@ export default class Assist {
this.assistDemandedRestart = true this.assistDemandedRestart = true
this.app.stop() this.app.stop()
setTimeout(() => { 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 // TODO: check if it's needed; basically allowing some time for the app to finish everything before starting again
}, 500) }, 500)
}) })
@ -295,11 +300,14 @@ export default class Assist {
this.assistDemandedRestart = true this.assistDemandedRestart = true
this.app.stop() this.app.stop()
setTimeout(() => { 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 // TODO: check if it's needed; basically allowing some time for the app to finish everything before starting again
}, 500) }, 500)
this.remoteControl?.reconnect(ids)
}) })
socket.on('AGENT_DISCONNECTED', (id) => { socket.on('AGENT_DISCONNECTED', (id) => {
@ -547,7 +555,8 @@ export default class Assist {
} }
private clean() { private clean() {
this.remoteControl?.releaseControl() // sometimes means new agent connected so we keep id for control
this.remoteControl?.releaseControl(false, true)
if (this.peer) { if (this.peer) {
this.peer.destroy() this.peer.destroy()
this.app.debug.log('Peer destroyed') this.app.debug.log('Peer destroyed')

View file

@ -67,14 +67,16 @@ export default class RemoteControl {
}) })
} }
releaseControl = (isDenied?: boolean) => { releaseControl = (isDenied?: boolean, keepId?: boolean) => {
if (this.confirm) { if (this.confirm) {
this.confirm.remove() this.confirm.remove()
this.confirm = null this.confirm = null
} }
this.resetMouse() this.resetMouse()
this.status = RCStatus.Disabled this.status = RCStatus.Disabled
if (!keepId) {
sessionStorage.removeItem(this.options.session_control_peer_key) sessionStorage.removeItem(this.options.session_control_peer_key)
}
this.onRelease(this.agentID, isDenied) this.onRelease(this.agentID, isDenied)
this.agentID = null this.agentID = null
} }
@ -90,7 +92,7 @@ export default class RemoteControl {
this.mouse = new Mouse(agentName) this.mouse = new Mouse(agentName)
this.mouse.mount() this.mouse.mount()
document.addEventListener('visibilitychange', () => { document.addEventListener('visibilitychange', () => {
if (document.hidden) this.releaseControl(false) if (document.hidden) this.releaseControl(false, false)
}) })
} }