diff --git a/js/commands.js b/js/commands.js
index 5dcfc1d..4369916 100644
--- a/js/commands.js
+++ b/js/commands.js
@@ -67,7 +67,8 @@ function cmd_help() {
" -exec Execute arbitrary math and logic equations
" +
" -nick Choose your username. Do not use spaces in it
" +
" -msg Open a direct chat to the provided user by name
" +
- " -ls List all connected users by name and id";
+ " -ls List all connected users by name and id
" +
+ " -ping Ping the host to request two-way-delay";
}
// Display 'about' message
@@ -205,4 +206,10 @@ function cmd_ls() {
return "You are not connected! Use the 'nick' command to connect using your username.";
requestUsernames();
return null;
+}
+
+// Ping host for two-way-delay
+function cmd_ping() {
+ requestPing();
+ return null;
}
\ No newline at end of file
diff --git a/js/networking.js b/js/networking.js
index 3b8f4ff..6f89ac1 100644
--- a/js/networking.js
+++ b/js/networking.js
@@ -149,4 +149,16 @@ function requestUsernames() {
output += `${u.name}#${u.id} `;
outputText({ output });
});
+}
+
+// Ping host for two-way-delay
+function requestPing() {
+ const startTime = new Date();
+ fetch('/ping').then(res => {
+ if (res.status !== 200)
+ return;
+ const diff = new Date() - startTime;
+ const output = `Host responded after ${diff}ms.`;
+ outputText({output})
+ });
}
\ No newline at end of file