Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created May 22, 2021 18:24
Show Gist options
  • Save smpnjn/69c3e7ae3bd81a64fff339377982fd16 to your computer and use it in GitHub Desktop.
Save smpnjn/69c3e7ae3bd81a64fff339377982fd16 to your computer and use it in GitHub Desktop.
// When the document has loaded
document.addEventListener('DOMContentLoaded', function() {
// Connect to the websocket
connect();
// And add our event listeners
document.getElementById('websocket-button').addEventListener('click', function(e) {
if(isOpen(socket)) {
socket.send(JSON.stringify({
"data" : "this is our data to send",
"other" : "this can be in any format"
}))
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment