* 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>
182 lines
No EOL
5.6 KiB
TypeScript
182 lines
No EOL
5.6 KiB
TypeScript
import AnnotationCanvas from './AnnotationCanvas';
|
|
import type { Socket } from './types'
|
|
import type Screen from '../Screen/Screen'
|
|
import type { Store } from '../../common/types'
|
|
|
|
export enum RemoteControlStatus {
|
|
Disabled = 0,
|
|
Requesting,
|
|
Enabled,
|
|
}
|
|
|
|
export interface State {
|
|
annotating: boolean
|
|
remoteControl: RemoteControlStatus
|
|
currentTab?: string
|
|
}
|
|
|
|
export default class RemoteControl {
|
|
static readonly INITIAL_STATE: Readonly<State> = {
|
|
remoteControl: RemoteControlStatus.Disabled,
|
|
annotating: false,
|
|
}
|
|
onReject: () => void = () => {}
|
|
|
|
constructor(
|
|
private store: Store<State>,
|
|
private socket: Socket,
|
|
private screen: Screen,
|
|
private agentInfo: Object,
|
|
private onToggle: (active: boolean) => void,
|
|
){
|
|
socket.on("control_granted", ({ meta, data }) => {
|
|
this.toggleRemoteControl(data === socket.id)
|
|
})
|
|
socket.on("control_rejected", ({ meta, data }) => {
|
|
data === socket.id && this.toggleRemoteControl(false)
|
|
this.onReject()
|
|
})
|
|
socket.on('SESSION_DISCONNECTED', () => {
|
|
if (this.store.get().remoteControl === RemoteControlStatus.Requesting) {
|
|
this.toggleRemoteControl(false) // else its remaining
|
|
}
|
|
})
|
|
socket.on("disconnect", () => {
|
|
this.toggleRemoteControl(false)
|
|
})
|
|
socket.on("error", () => {
|
|
this.toggleRemoteControl(false)
|
|
})
|
|
}
|
|
|
|
private onMouseMove = (e: MouseEvent): void => {
|
|
const data = this.screen.getInternalCoordinates(e)
|
|
this.emitData("move", [ data.x, data.y ])
|
|
}
|
|
|
|
private emitData = (event: string, data?: any) => {
|
|
this.socket.emit(event, { meta: { tabId: this.store.get().currentTab }, data })
|
|
}
|
|
|
|
private onWheel = (e: WheelEvent): void => {
|
|
e.preventDefault()
|
|
//throttling makes movements less smooth, so it is omitted
|
|
//this.onMouseMove(e)
|
|
this.emitData("scroll", [ e.deltaX, e.deltaY ])
|
|
}
|
|
|
|
public setCallbacks = ({ onReject }: { onReject: () => void }) => {
|
|
this.onReject = onReject
|
|
}
|
|
|
|
private onMouseClick = (e: MouseEvent): void => {
|
|
if (this.store.get().annotating) { return; } // ignore clicks while annotating
|
|
|
|
const data = this.screen.getInternalViewportCoordinates(e)
|
|
// const el = this.screen.getElementFromPoint(e); // requires requestiong node_id from domManager
|
|
const el = this.screen.getElementFromInternalPoint(data)
|
|
if (el instanceof HTMLElement) {
|
|
el.focus()
|
|
el.oninput = e => {
|
|
if (el instanceof HTMLTextAreaElement
|
|
|| el instanceof HTMLInputElement
|
|
) {
|
|
this.socket && this.emitData("input", el.value)
|
|
} else if (el.isContentEditable) {
|
|
this.socket && this.emitData("input", el.innerText)
|
|
}
|
|
}
|
|
// TODO: send "focus" event to assist with the nodeID
|
|
el.onkeydown = e => {
|
|
if (e.key == "Tab") {
|
|
e.preventDefault()
|
|
}
|
|
}
|
|
el.onblur = () => {
|
|
el.oninput = null
|
|
el.onblur = null
|
|
}
|
|
}
|
|
this.emitData("click", [ data.x, data.y ]);
|
|
}
|
|
|
|
private toggleRemoteControl(enable: boolean){
|
|
if (enable) {
|
|
this.screen.overlay.addEventListener("mousemove", this.onMouseMove)
|
|
this.screen.overlay.addEventListener("click", this.onMouseClick)
|
|
this.screen.overlay.addEventListener("wheel", this.onWheel)
|
|
this.store.update({ remoteControl: RemoteControlStatus.Enabled })
|
|
} else {
|
|
this.screen.overlay.removeEventListener("mousemove", this.onMouseMove)
|
|
this.screen.overlay.removeEventListener("click", this.onMouseClick)
|
|
this.screen.overlay.removeEventListener("wheel", this.onWheel)
|
|
this.store.update({ remoteControl: RemoteControlStatus.Disabled })
|
|
this.toggleAnnotation(false)
|
|
}
|
|
this.onToggle(enable)
|
|
}
|
|
|
|
requestReleaseRemoteControl = () => {
|
|
const remoteControl = this.store.get().remoteControl
|
|
if (remoteControl === RemoteControlStatus.Requesting) { return }
|
|
if (remoteControl === RemoteControlStatus.Disabled) {
|
|
this.store.update({ remoteControl: RemoteControlStatus.Requesting })
|
|
this.emitData("request_control", JSON.stringify({
|
|
...this.agentInfo,
|
|
query: document.location.search
|
|
}))
|
|
} else {
|
|
this.releaseRemoteControl()
|
|
}
|
|
}
|
|
|
|
releaseRemoteControl = () => {
|
|
this.emitData("release_control",)
|
|
this.toggleRemoteControl(false)
|
|
}
|
|
|
|
private annot: AnnotationCanvas | null = null
|
|
|
|
toggleAnnotation(enable?: boolean) {
|
|
if (typeof enable !== "boolean") {
|
|
enable = this.store.get().annotating
|
|
}
|
|
if (enable && !this.annot) {
|
|
const annot = this.annot = new AnnotationCanvas()
|
|
annot.mount(this.screen.overlay)
|
|
annot.canvas.addEventListener("mousedown", e => {
|
|
const data = this.screen.getInternalViewportCoordin1ates(e)
|
|
annot.start([ data.x, data.y ])
|
|
this.emitData("startAnnotation", [ data.x, data.y ])
|
|
})
|
|
annot.canvas.addEventListener("mouseleave", () => {
|
|
annot.stop()
|
|
this.emitData("stopAnnotation")
|
|
})
|
|
annot.canvas.addEventListener("mouseup", () => {
|
|
annot.stop()
|
|
this.emitData("stopAnnotation")
|
|
})
|
|
annot.canvas.addEventListener("mousemove", e => {
|
|
if (!annot.isPainting()) { return }
|
|
|
|
const data = this.screen.getInternalViewportCoordinates(e)
|
|
annot.move([ data.x, data.y ])
|
|
this.emitData("moveAnnotation", [ data.x, data.y ])
|
|
})
|
|
this.store.update({ annotating: true })
|
|
} else if (!enable && !!this.annot) {
|
|
this.annot.remove()
|
|
this.annot = null
|
|
this.store.update({ annotating: false })
|
|
}
|
|
}
|
|
|
|
clean() {
|
|
this.toggleRemoteControl(false)
|
|
if (this.annot) {
|
|
this.annot.remove()
|
|
this.annot = null
|
|
}
|
|
}
|
|
} |