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

View File

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