From d9546e581f7f05e29d9d4910458a8a3aa3893e9a Mon Sep 17 00:00:00 2001 From: ShiKhu Date: Thu, 21 Apr 2022 16:46:11 +0200 Subject: [PATCH] feat(frontend):annotation toggle api in player --- .../managers/AssistManager.ts | 64 +++++++++++-------- frontend/app/player/singletone.js | 1 + 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/frontend/app/player/MessageDistributor/managers/AssistManager.ts b/frontend/app/player/MessageDistributor/managers/AssistManager.ts index e888e18a4..49b011634 100644 --- a/frontend/app/player/MessageDistributor/managers/AssistManager.ts +++ b/frontend/app/player/MessageDistributor/managers/AssistManager.ts @@ -370,6 +370,42 @@ export default class AssistManager { } } + toggleAnnotation(enable?: boolean) { + if (typeof enable !== "boolean") { + enable = !!this.annot + } + if (enable && !this.annot) { + const annot = this.annot = new AnnotationCanvas() + annot.mount(this.md.overlay) + annot.canvas.addEventListener("mousedown", e => { + if (!this.socket) { return } + const data = this.md.getInternalViewportCoordinates(e) + annot.start([ data.x, data.y ]) + this.socket.emit("startAnnotation", [ data.x, data.y ]) + }) + annot.canvas.addEventListener("mouseleave", () => { + if (!this.socket) { return } + annot.stop() + this.socket.emit("stopAnnotation") + }) + annot.canvas.addEventListener("mouseup", () => { + if (!this.socket) { return } + annot.stop() + this.socket.emit("stopAnnotation") + }) + annot.canvas.addEventListener("mousemove", e => { + if (!this.socket || !annot.isPainting()) { return } + + const data = this.md.getInternalViewportCoordinates(e) + annot.move([ data.x, data.y ]) + this.socket.emit("moveAnnotation", [ data.x, data.y ]) + }) + } else if (!enable && !!this.annot) { + this.annot.remove() + this.annot = null + } + } + private annot: AnnotationCanvas | null = null private _call() { @@ -396,34 +432,6 @@ export default class AssistManager { call.on('stream', stream => { update({ calling: CallingState.OnCall }) this.callArgs && this.callArgs.onStream(stream) - - if (!this.annot) { - const annot = this.annot = new AnnotationCanvas() - annot.mount(this.md.overlay) - annot.canvas.addEventListener("mousedown", e => { - if (!this.socket) { return } - const data = this.md.getInternalViewportCoordinates(e) - annot.start([ data.x, data.y ]) - this.socket.emit("startAnnotation", [ data.x, data.y ]) - }) - annot.canvas.addEventListener("mouseleave", () => { - if (!this.socket) { return } - annot.stop() - this.socket.emit("stopAnnotation") - }) - annot.canvas.addEventListener("mouseup", () => { - if (!this.socket) { return } - annot.stop() - this.socket.emit("stopAnnotation") - }) - annot.canvas.addEventListener("mousemove", e => { - if (!this.socket || !annot.isPainting()) { return } - - const data = this.md.getInternalViewportCoordinates(e) - annot.move([ data.x, data.y ]) - this.socket.emit("moveAnnotation", [ data.x, data.y ]) - }) - } }); //call.peerConnection.addEventListener("track", e => console.log('newtrack',e.track)) diff --git a/frontend/app/player/singletone.js b/frontend/app/player/singletone.js index 177bb0388..60b8cf8ce 100644 --- a/frontend/app/player/singletone.js +++ b/frontend/app/player/singletone.js @@ -72,6 +72,7 @@ export const callPeer = initCheck((...args) => instance.assistManager.call(...ar export const requestReleaseRemoteControl = initCheck((...args) => instance.assistManager.requestReleaseRemoteControl(...args)) export const markTargets = initCheck((...args) => instance.markTargets(...args)) export const activeTarget = initCheck((...args) => instance.activeTarget(...args)) +export const toggleAnnotation = initCheck((...args) => instance.assistManager.toggleAnnotation(...args)) export const Controls = { jump,