1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Update spice-html5

This commit is contained in:
catborise 2020-01-23 15:49:43 +03:00
parent 34394c2b5e
commit 562fe5c3dc
36 changed files with 59278 additions and 1325 deletions
static/js/spice-html5

View file

@ -18,6 +18,12 @@
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
*/
import * as Messages from './spicemsg.js';
import { Constants } from './enums.js';
import { KeyNames } from './atKeynames.js';
import { SpiceConn } from './spiceconn.js';
import { DEBUG } from './utils.js';
/*----------------------------------------------------------------------------
** Modifier Keystates
** These need to be tracked because focus in and out can get the keyboard
@ -45,26 +51,26 @@ function SpiceInputsConn()
SpiceInputsConn.prototype = Object.create(SpiceConn.prototype);
SpiceInputsConn.prototype.process_channel_message = function(msg)
{
if (msg.type == SPICE_MSG_INPUTS_INIT)
if (msg.type == Constants.SPICE_MSG_INPUTS_INIT)
{
var inputs_init = new SpiceMsgInputsInit(msg.data);
var inputs_init = new Messages.SpiceMsgInputsInit(msg.data);
this.keyboard_modifiers = inputs_init.keyboard_modifiers;
DEBUG > 1 && console.log("MsgInputsInit - modifier " + this.keyboard_modifiers);
// FIXME - We don't do anything with the keyboard modifiers...
return true;
}
if (msg.type == SPICE_MSG_INPUTS_KEY_MODIFIERS)
if (msg.type == Constants.SPICE_MSG_INPUTS_KEY_MODIFIERS)
{
var key = new SpiceMsgInputsKeyModifiers(msg.data);
var key = new Messages.SpiceMsgInputsKeyModifiers(msg.data);
this.keyboard_modifiers = key.keyboard_modifiers;
DEBUG > 1 && console.log("MsgInputsKeyModifiers - modifier " + this.keyboard_modifiers);
// FIXME - We don't do anything with the keyboard modifiers...
return true;
}
if (msg.type == SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)
if (msg.type == Constants.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)
{
DEBUG > 1 && console.log("mouse motion ack");
this.waiting_for_ack -= SPICE_INPUT_MOTION_ACK_BUNCH;
this.waiting_for_ack -= Constants.SPICE_INPUT_MOTION_ACK_BUNCH;
return true;
}
return false;
@ -74,21 +80,21 @@ SpiceInputsConn.prototype.process_channel_message = function(msg)
function handle_mousemove(e)
{
var msg = new SpiceMiniData();
var msg = new Messages.SpiceMiniData();
var move;
if (this.sc.mouse_mode == SPICE_MOUSE_MODE_CLIENT)
if (this.sc.mouse_mode == Constants.SPICE_MOUSE_MODE_CLIENT)
{
move = new SpiceMsgcMousePosition(this.sc, e)
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_POSITION, move);
move = new Messages.SpiceMsgcMousePosition(this.sc, e)
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_POSITION, move);
}
else
{
move = new SpiceMsgcMouseMotion(this.sc, e)
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_MOTION, move);
move = new Messages.SpiceMsgcMouseMotion(this.sc, e)
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_MOTION, move);
}
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
{
if (this.sc.inputs.waiting_for_ack < (2 * SPICE_INPUT_MOTION_ACK_BUNCH))
if (this.sc.inputs.waiting_for_ack < (2 * Constants.SPICE_INPUT_MOTION_ACK_BUNCH))
{
this.sc.inputs.send_msg(msg);
this.sc.inputs.waiting_for_ack++;
@ -111,9 +117,9 @@ function handle_mousemove(e)
function handle_mousedown(e)
{
var press = new SpiceMsgcMousePress(this.sc, e)
var msg = new SpiceMiniData();
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
var press = new Messages.SpiceMsgcMousePress(this.sc, e)
var msg = new Messages.SpiceMiniData();
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
@ -128,9 +134,9 @@ function handle_contextmenu(e)
function handle_mouseup(e)
{
var release = new SpiceMsgcMouseRelease(this.sc, e)
var msg = new SpiceMiniData();
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
var release = new Messages.SpiceMsgcMouseRelease(this.sc, e)
var msg = new Messages.SpiceMiniData();
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
@ -139,21 +145,21 @@ function handle_mouseup(e)
function handle_mousewheel(e)
{
var press = new SpiceMsgcMousePress;
var release = new SpiceMsgcMouseRelease;
var press = new Messages.SpiceMsgcMousePress;
var release = new Messages.SpiceMsgcMouseRelease;
if (e.deltaY < 0)
press.button = release.button = SPICE_MOUSE_BUTTON_UP;
press.button = release.button = Constants.SPICE_MOUSE_BUTTON_UP;
else
press.button = release.button = SPICE_MOUSE_BUTTON_DOWN;
press.button = release.button = Constants.SPICE_MOUSE_BUTTON_DOWN;
press.buttons_state = 0;
release.buttons_state = 0;
var msg = new SpiceMiniData();
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
var msg = new Messages.SpiceMiniData();
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
@ -162,10 +168,10 @@ function handle_mousewheel(e)
function handle_keydown(e)
{
var key = new SpiceMsgcKeyDown(e)
var msg = new SpiceMiniData();
var key = new Messages.SpiceMsgcKeyDown(e)
var msg = new Messages.SpiceMiniData();
check_and_update_modifiers(e, key.code, this.sc);
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_DOWN, key);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
@ -174,74 +180,50 @@ function handle_keydown(e)
function handle_keyup(e)
{
var key = new SpiceMsgcKeyUp(e)
var msg = new SpiceMiniData();
var key = new Messages.SpiceMsgcKeyUp(e)
var msg = new Messages.SpiceMiniData();
check_and_update_modifiers(e, key.code, this.sc);
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_UP, key);
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
this.sc.inputs.send_msg(msg);
e.preventDefault();
}
function sendCtrlAltDel()
function sendCtrlAltDel(sc)
{
if (sc && sc.inputs && sc.inputs.state === "ready"){
var key = new SpiceMsgcKeyDown();
var msg = new SpiceMiniData();
var key = new Messages.SpiceMsgcKeyDown();
var msg = new Messages.SpiceMiniData();
update_modifier(true, KEY_LCtrl, sc);
update_modifier(true, KEY_Alt, sc);
update_modifier(true, KeyNames.KEY_LCtrl, sc);
update_modifier(true, KeyNames.KEY_Alt, sc);
key.code = KEY_KP_Decimal;
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
key.code = KeyNames.KEY_KP_Decimal;
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_DOWN, key);
sc.inputs.send_msg(msg);
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_UP, key);
sc.inputs.send_msg(msg);
if(Ctrl_state == false) update_modifier(false, KEY_LCtrl, sc);
if(Alt_state == false) update_modifier(false, KEY_Alt, sc);
}
}
function sendCtrlAltFN(f) {
if (sc && sc.inputs && sc.inputs.state === "ready"){
var keys_code=[KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_F11,KEY_F12];
if (keys_code[f]==undefined) {
return;
}
var key = new SpiceMsgcKeyDown();
var msg = new SpiceMiniData();
update_modifier(true, KEY_LCtrl, sc);
update_modifier(true, KEY_Alt, sc);
key.code = keys_code[f];
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
sc.inputs.send_msg(msg);
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
sc.inputs.send_msg(msg);
if(Ctrl_state == false) update_modifier(false, KEY_LCtrl, sc);
if(Alt_state == false) update_modifier(false, KEY_Alt, sc);
if(Ctrl_state == false) update_modifier(false, KeyNames.KEY_LCtrl, sc);
if(Alt_state == false) update_modifier(false, KeyNames.KEY_Alt, sc);
}
}
function update_modifier(state, code, sc)
{
var msg = new SpiceMiniData();
var msg = new Messages.SpiceMiniData();
if (!state)
{
var key = new SpiceMsgcKeyUp()
var key = new Messages.SpiceMsgcKeyUp()
key.code =(0x80|code);
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_UP, key);
}
else
{
var key = new SpiceMsgcKeyDown()
var key = new Messages.SpiceMsgcKeyDown()
key.code = code;
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_DOWN, key);
}
sc.inputs.send_msg(msg);
@ -257,19 +239,19 @@ function check_and_update_modifiers(e, code, sc)
Meta_state = e.metaKey;
}
if (code === KEY_ShiftL)
if (code === KeyNames.KEY_ShiftL)
Shift_state = true;
else if (code === KEY_Alt)
else if (code === KeyNames.KEY_Alt)
Alt_state = true;
else if (code === KEY_LCtrl)
else if (code === KeyNames.KEY_LCtrl)
Ctrl_state = true;
else if (code === 0xE0B5)
Meta_state = true;
else if (code === (0x80|KEY_ShiftL))
else if (code === (0x80|KeyNames.KEY_ShiftL))
Shift_state = false;
else if (code === (0x80|KEY_Alt))
else if (code === (0x80|KeyNames.KEY_Alt))
Alt_state = false;
else if (code === (0x80|KEY_LCtrl))
else if (code === (0x80|KeyNames.KEY_LCtrl))
Ctrl_state = false;
else if (code === (0x80|0xE0B5))
Meta_state = false;
@ -279,19 +261,19 @@ function check_and_update_modifiers(e, code, sc)
if (Shift_state != e.shiftKey)
{
console.log("Shift state out of sync");
update_modifier(e.shiftKey, KEY_ShiftL, sc);
update_modifier(e.shiftKey, KeyNames.KEY_ShiftL, sc);
Shift_state = e.shiftKey;
}
if (Alt_state != e.altKey)
{
console.log("Alt state out of sync");
update_modifier(e.altKey, KEY_Alt, sc);
update_modifier(e.altKey, KeyNames.KEY_Alt, sc);
Alt_state = e.altKey;
}
if (Ctrl_state != e.ctrlKey)
{
console.log("Ctrl state out of sync");
update_modifier(e.ctrlKey, KEY_LCtrl, sc);
update_modifier(e.ctrlKey, KeyNames.KEY_LCtrl, sc);
Ctrl_state = e.ctrlKey;
}
if (Meta_state != e.metaKey)
@ -302,3 +284,15 @@ function check_and_update_modifiers(e, code, sc)
}
}
}
export {
SpiceInputsConn,
handle_mousemove,
handle_mousedown,
handle_contextmenu,
handle_mouseup,
handle_mousewheel,
handle_keydown,
handle_keyup,
sendCtrlAltDel,
};