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