Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Add handling for mouse double click
Browse files Browse the repository at this point in the history
  • Loading branch information
Belchy06 committed Aug 11, 2022
1 parent bf97adf commit 9802082
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions SignallingWebServer/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ function populateDefaultProtocol() {
// delta x y
"structure": ["int16", "uint16", "uint16"]
});
toStreamerMessages.add("MouseDouble", {
"id": 76,
"byteLength": 5,
// button x y
"structure": ["uint8", "uint16", "uint16"]
});
// Touch Input Messages. Range = 80..89.
toStreamerMessages.add("TouchStart", {
"id": 80,
Expand Down Expand Up @@ -332,6 +338,7 @@ function registerMessageHandlers() {
registerMessageHandler(MessageDirection.ToStreamer, "MouseUp", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "MouseMove", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "MouseWheel", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "MouseDouble", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "TouchStart", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "TouchEnd", sendMessageToStreamer);
registerMessageHandler(MessageDirection.ToStreamer, "TouchMove", sendMessageToStreamer);
Expand Down Expand Up @@ -455,11 +462,11 @@ function onProtocolMessage(data) {
try {
let protocolString = new TextDecoder("utf-16").decode(data.slice(1));
let protocolJSON = JSON.parse(protocolString);
if (!protocolJSON.hasOwnProperty("direction")) {
if (!protocolJSON.hasOwnProperty("Direction")) {
throw new Error('Malformed protocol received. Ensure the protocol message contains a direction');
}
let direction = protocolJSON.direction;
delete protocolJSON.direction;
let direction = protocolJSON.Direction;
delete protocolJSON.Direction;
console.log(`Received new ${ direction == MessageDirection.FromStreamer ? "FromStreamer" : "ToStreamer" } protocol. Updating existing protocol...`);
Object.keys(protocolJSON).forEach((messageType) => {
let message = protocolJSON[messageType];
Expand Down Expand Up @@ -2200,10 +2207,13 @@ function registerLockedMouseEvents(playerElement) {
};

playerElement.onwheel = function (e) {
let coord = normalizeAndQuantizeUnsigned(x, y);
toStreamerHandlers.MouseWheel("MouseWheel", [e.wheelDelta, coord.x, coord.y]);
};

playerElement.ondblclick = function (e) {
toStreamerHandlers.MouseDown("MouseDouble", [e.button, coord.x, coord.y]);
};

playerElement.pressMouseButtons = function(e) {
pressMouseButtons(e.buttons, x, y);
};
Expand Down Expand Up @@ -2255,6 +2265,11 @@ function registerHoveringMouseEvents(playerElement) {
e.preventDefault();
};

playerElement.ondblclick = function (e) {
let coord = normalizeAndQuantizeUnsigned(e.offsetX, e.offsetY);
toStreamerHandlers.MouseDown("MouseDouble", [e.button, coord.x, coord.y]);
};

playerElement.pressMouseButtons = function(e) {
pressMouseButtons(e.buttons, e.offsetX, e.offsetY);
};
Expand Down

0 comments on commit 9802082

Please sign in to comment.