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
})
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") {

View file

@ -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']))
}

View file

@ -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 ])
})

View file

@ -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')

View file

@ -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)
})
}