From a269f45f2337ff56cfa9d6d52a7002624e97028e Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 25 Jun 2024 13:41:17 +0200 Subject: [PATCH] refactor(client): :recycle: resolve endpoint inside `sendCommand` instead of redundant argument --- client/index.html | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/client/index.html b/client/index.html index 99e1e3f..4ac9200 100644 --- a/client/index.html +++ b/client/index.html @@ -80,19 +80,19 @@ // Keyboard handler document.addEventListener('keydown', ({ code }) => { if (code === 'ArrowUp') { - return sendCommand(getEndpoint(), 'forward', 2) + return sendCommand('forward', 2) } if (code === 'ArrowDown') { - return sendCommand(getEndpoint(), 'backward', 2) + return sendCommand('backward', 2) } if (code === 'ArrowLeft') { - return sendCommand(getEndpoint(), 'left', 5) + return sendCommand('left', 5) } if (code === 'ArrowRight') { - return sendCommand(getEndpoint(), 'right', 5) + return sendCommand('right', 5) } if (code === 'Space') { - return sendCommand(getEndpoint(), 'stop', 0) + return sendCommand('stop', 0) } }) @@ -124,13 +124,13 @@ /** * Send command to the robot. * - * @param {string} endpoint Address IP of the robot. * @param {Command} command Command to send. * @param {number} value Value of the command if needed. * * @returns {Promise} */ - async function sendCommand(endpoint, command, value) { + async function sendCommand(command, value) { + const endpoint = getEndpoint() const url = new URL( `/get?command=${command}&value=${value}`, endpoint @@ -202,11 +202,10 @@ const target = event.target const value = target.valueAsNumber - const endpoint = getEndpoint() if (value < 0) { - return sendCommand(endpoint, negativeCommand, Math.abs(value)) + return sendCommand(negativeCommand, Math.abs(value)) } - return sendCommand(endpoint, positiveCommand, value) + return sendCommand(positiveCommand, value) }