control pos interface.

This commit is contained in:
Miroslav Šedivý 2022-07-23 14:17:03 +02:00
parent 56b7c8087d
commit f4b22e82a9
2 changed files with 26 additions and 21 deletions

View File

@ -12,6 +12,11 @@ export interface NekoControlEvents {
['overlay.contextmenu']: (e: MouseEvent) => void
}
export interface ControlPos {
x: number
y: number
}
export class NekoControl extends EventEmitter<NekoControlEvents> {
// eslint-disable-next-line
constructor(
@ -37,36 +42,36 @@ export class NekoControl extends EventEmitter<NekoControlEvents> {
this._connection.websocket.send(EVENT.CONTROL_RELEASE)
}
public move(x: number, y: number) {
this._connection.websocket.send(EVENT.CONTROL_MOVE, { x, y } as message.ControlPos)
public move(pos: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_MOVE, pos as message.ControlPos)
}
public scroll(x: number, y: number) {
this._connection.websocket.send(EVENT.CONTROL_SCROLL, { x, y } as message.ControlPos)
public scroll(pos: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_SCROLL, pos as message.ControlPos)
}
public buttonPress(code: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONPRESS, { code, x, y } as message.ControlButton)
public buttonPress(code: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONPRESS, { code, ...pos } as message.ControlButton)
}
public buttonDown(code: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONDOWN, { code, x, y } as message.ControlButton)
public buttonDown(code: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONDOWN, { code, ...pos } as message.ControlButton)
}
public buttonUp(code: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONUP, { code, x, y } as message.ControlButton)
public buttonUp(code: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_BUTTONUP, { code, ...pos } as message.ControlButton)
}
public keyPress(keysym: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_KEYPRESS, { keysym, x, y } as message.ControlKey)
public keyPress(keysym: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_KEYPRESS, { keysym, ...pos } as message.ControlKey)
}
public keyDown(keysym: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_KEYDOWN, { keysym, x, y } as message.ControlKey)
public keyDown(keysym: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_KEYDOWN, { keysym, ...pos } as message.ControlKey)
}
public keyUp(keysym: number, x?: number, y?: number) {
this._connection.websocket.send(EVENT.CONTROL_KEYUP, { keysym, x, y } as message.ControlKey)
public keyUp(keysym: number, pos?: ControlPos) {
this._connection.websocket.send(EVENT.CONTROL_KEYUP, { keysym, ...pos } as message.ControlKey)
}
public cut() {

View File

@ -306,7 +306,7 @@
this.sendMousePos(e)
this.webrtc.send('wheel', { x, y })
} else {
this.wsControl.scroll(x, y)
this.wsControl.scroll({ x, y })
}
}
@ -331,8 +331,8 @@
this.sendMousePos(e)
this.webrtc.send('mousedown', { key })
} else {
const { x, y } = this.getMousePos(e.clientX, e.clientY)
this.wsControl.buttonDown(key, x, y)
const pos = this.getMousePos(e.clientX, e.clientY)
this.wsControl.buttonDown(key, pos)
}
}
@ -347,8 +347,8 @@
this.sendMousePos(e)
this.webrtc.send('mouseup', { key })
} else {
const { x, y } = this.getMousePos(e.clientX, e.clientY)
this.wsControl.buttonUp(key, x, y)
const pos = this.getMousePos(e.clientX, e.clientY)
this.wsControl.buttonUp(key, pos)
}
}