summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/share/js/kvm/hid.js6
-rw-r--r--web/share/js/kvm/mouse.js19
-rw-r--r--web/share/js/kvm/session.js4
-rw-r--r--web/share/js/kvm/stream.js10
4 files changed, 24 insertions, 15 deletions
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js
index f4f2b589..bfda9ae1 100644
--- a/web/share/js/kvm/hid.js
+++ b/web/share/js/kvm/hid.js
@@ -31,11 +31,13 @@ import {Keyboard} from "./keyboard.js";
import {Mouse} from "./mouse.js";
-export function Hid() {
+export function Hid(get_resolution_callback) {
var self = this;
/************************************************************************/
+ var __get_resolution_callback = get_resolution_callback;
+
var __recorder = null;
var __keyboard = null;
var __mouse = null;
@@ -43,7 +45,7 @@ export function Hid() {
var __init__ = function() {
__recorder = new Recorder();
__keyboard = new Keyboard(__recorder.recordWsEvent);
- __mouse = new Mouse(__recorder.recordWsEvent);
+ __mouse = new Mouse(__get_resolution_callback, __recorder.recordWsEvent);
let hidden_attr = null;
let visibility_change_attr = null;
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index bae2f15b..dbdbdc44 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -27,11 +27,12 @@ import {tools, $} from "../tools.js";
import {Keypad} from "../keypad.js";
-export function Mouse(record_callback) {
+export function Mouse(get_resolution_callback, record_callback) {
var self = this;
/************************************************************************/
+ var __get_resolution_callback = get_resolution_callback;
var __record_callback = record_callback;
var __ws = null;
@@ -236,17 +237,13 @@ export function Mouse(record_callback) {
// - Видим нарушение пропорций
// Так что теперь используются быстре рассчеты через offset*
// вместо getBoundingClientRect().
- let el_image = $("stream-image");
- let real_width = el_image.naturalWidth;
- let real_height = el_image.naturalHeight;
- let view_width = el_image.offsetWidth;
- let view_height = el_image.offsetHeight;
- let ratio = Math.min(view_width / real_width, view_height / real_height);
+ let res = __get_resolution_callback();
+ let ratio = Math.min(res.view_width / res.real_width, res.view_height / res.real_height);
return {
- "x": Math.round((view_width - ratio * real_width) / 2),
- "y": Math.round((view_height - ratio * real_height) / 2),
- "width": Math.round(ratio * real_width),
- "height": Math.round(ratio * real_height),
+ "x": Math.round((res.view_width - ratio * res.real_width) / 2),
+ "y": Math.round((res.view_height - ratio * res.real_height) / 2),
+ "width": Math.round(ratio * res.real_width),
+ "height": Math.round(ratio * res.real_height),
};
};
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index de1df249..894dc6f1 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -44,10 +44,10 @@ export function Session() {
var __ping_timer = null;
var __missed_heartbeats = 0;
- var __hid = new Hid();
+ var __streamer = new Streamer();
+ var __hid = new Hid(__streamer.getResolution);
var __atx = new Atx();
var __msd = new Msd();
- var __streamer = new Streamer(__hid);
var __wol = new WakeOnLan();
var __gpio = new Gpio();
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index 970ac6ef..19ffbedf 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -176,6 +176,16 @@ export function Streamer() {
/************************************************************************/
+ self.getResolution = function() {
+ let el_image = $("stream-image");
+ return {
+ real_width: el_image.naturalWidth,
+ real_height: el_image.naturalHeight,
+ view_width: el_image.offsetWidth,
+ view_height: el_image.offsetHeight,
+ };
+ };
+
self.setJanusEnabled = function(enabled) {
__janus_enabled = (!!window.RTCPeerConnection && enabled);
tools.info("Stream: Janus WebRTC Gateway state:", __janus_enabled);