addedd api endpoint logic

This commit is contained in:
Maxim Stewart 2020-11-12 19:44:49 -06:00
parent c379396235
commit 280c94274e
1 changed files with 47 additions and 16 deletions

View File

@ -1,4 +1,11 @@
let useSocket = true;
const socket = io();
socket.on('connect', function() {
console.log("Websocket connected...");
});
let mouseHoldToggle = document.getElementById("mouseHoldToggle");
let scrollTggl = document.getElementById("scrollToggle");
let clickSound = document.getElementById("clickSound");
@ -14,9 +21,6 @@ let px = 0;
let py = 0;
socket.on('connect', function() {
console.log("Websocket connected...");
});
$(function () {
@ -53,14 +57,25 @@ $(function () {
mod += stepBump;
if (isScrolling) {
if (useSocket) {
if (e.direction == "up") {
socket.emit('scroll_up', "");
} else if (e.direction == "down") {
socket.emit('scroll_down', "");
}
} else {
if (e.direction == "up") {
doAjax("/scroll-up" , "scroll-up", "GET");
} else if (e.direction == "down") {
doAjax("/scroll-down" , "scroll-down", "GET");
}
}
} else {
if (useSocket) {
socket.emit('update_coords', px + "," + py);
// doAjax("/update-coords/xy/" + px + "/" + py, "" , "update-coords", "GET");
} else {
doAjax("/update-coords/xy/" + px + "/" + py, "" , "update-coords", "GET");
}
}
});
});
@ -124,13 +139,21 @@ function resetClickCheckAndModBump(e) {
}
function leftClick() {
if (useSocket) {
playClickSound();
socket.emit('left_click', "");
} else {
doAjax("/left-click" , "left-click", "GET");
}
}
function rightClick() {
if (useSocket) {
playClickSound();
socket.emit('right_click', "");
} else {
doAjax("/right-click", "right-click", "GET");
}
}
function sendKeys() {
@ -139,11 +162,19 @@ function sendKeys() {
}
function pressEnter() {
if (useSocket) {
socket.emit('press_enter', "");
} else {
doAjax("/press-enter", "press-enter", "GET");
}
}
function pressBack() {
if (useSocket) {
socket.emit('press_back', "");
} else {
doAjax("/press-back", "" , "back-press", "GET");
}
}