refactoring

This commit is contained in:
Devaev Maxim 2021-05-09 07:59:00 +03:00
parent 8aa0162ba2
commit 42601dae58
4 changed files with 24 additions and 15 deletions

View File

@ -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;

View File

@ -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),
};
};

View File

@ -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();

View File

@ -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);