Created
February 5, 2024 22:04
-
-
Save ruzli/5dc12deb99dbf4c8c5dd8a2e96818154 to your computer and use it in GitHub Desktop.
wss.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wss = new WebSocket('ws://localhost:4041'); | |
wss.addEventListener('open', () => { | |
console.log(getCurrentTime() + 'Connected'); | |
}); | |
wss.addEventListener('close', () => { | |
console.log(getCurrentTime() + 'Disconnected'); | |
}); | |
function getCurrentTime() { | |
return "[" + String(new Date().toLocaleTimeString('en-US', { timeZone: 'Europe/Moscow' })) + "] "; | |
} | |
console.log('Started ' + getCurrentTime()); | |
document.addEventListener('keydown', (event) => { | |
const key = event.key; | |
wss.send(JSON.stringify({ hotkey: key })); | |
console.log(getCurrentTime() + `"${key.toUpperCase()}" was pressed.`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment