From 994254a1a5901c9f7950dba858edab0924caeb8c Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 25 Jun 2024 12:49:21 +0200 Subject: [PATCH] refactor(client): :recycle: improve `sendCommand` flexibility and type checking --- client/index.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/index.html b/client/index.html index b3fa63f..d6ee267 100644 --- a/client/index.html +++ b/client/index.html @@ -73,14 +73,18 @@ /** * Send command to the robot. * - * @param {string} endpoint Address IP of 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) { - const response = await fetch( - `http://${endpoint}/get?command=${command}&value=${value}` + const url = new URL( + `/get?command=${command}&value=${value}`, + endpoint ) + const response = await fetch(url) const text = await response.text() console.log(text) }