ping command for two-way-delay
This commit is contained in:
parent
26bd3ddb6f
commit
6f1ce9fcad
@ -67,7 +67,8 @@ function cmd_help() {
|
||||
" -exec Execute arbitrary math and logic equations<br>" +
|
||||
" -nick Choose your username. Do not use spaces in it<br>" +
|
||||
" -msg Open a direct chat to the provided user by name<br>" +
|
||||
" -ls List all connected users by name and id";
|
||||
" -ls List all connected users by name and id<br>" +
|
||||
" -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;
|
||||
}
|
@ -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})
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user