diff options
author | Devaev Maxim <[email protected]> | 2020-06-09 21:43:40 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-06-09 21:43:40 +0300 |
commit | 8a18a4145973e5c3009c18217bd52cb2b6293d74 (patch) | |
tree | 8ebdb787daa94eba7b0334924d459c5a12b9af92 /web | |
parent | 91ecd2d3da109d344d1c84f30675407e83ca8b1e (diff) |
refactoring
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/kvm/mouse.js | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js index b4978dfe..dca2f4c5 100644 --- a/web/share/js/kvm/mouse.js +++ b/web/share/js/kvm/mouse.js @@ -145,12 +145,7 @@ export function Mouse() { var __sendButton = function(button, state) { tools.debug("Mouse: button", (state ? "pressed:" : "released:"), button); __sendMove(); - if (__ws) { - __ws.send(JSON.stringify({ - "event_type": "mouse_button", - "event": {"button": button, "state": state}, - })); - } + __sendEvent("mouse_button", {"button": button, "state": state}); }; var __sendMove = function() { @@ -163,12 +158,7 @@ export function Mouse() { }; tools.debug("Mouse: moved:", to); - if (__ws) { - __ws.send(JSON.stringify({ - "event_type": "mouse_move", - "event": {"to": to}, - })); - } + __sendEvent("mouse_move", {"to": to}); __sent_pos = pos; } }; @@ -199,12 +189,13 @@ export function Mouse() { if (delta.x || delta.y) { tools.debug("Mouse: scrolled:", delta); - if (__ws) { - __ws.send(JSON.stringify({ - "event_type": "mouse_wheel", - "event": {"delta": delta}, - })); - } + __sendEvent("mouse_wheel", {"delta": delta}); + } + }; + + var __sendEvent = function(event_type, event) { + if (__ws) { + __ws.send(JSON.stringify({"event_type": event_type, "event": event})); } }; |