You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
ygdc/assets/js/websocket.js

18 lines
425 B

export function connect(endpoint, callback){
const socket = new WebSocket("ws://localhost:4040/subscribe");
// Connection opened
socket.addEventListener("open", (event) => {
socket.send(JSON.stringify({
"action": "subscribe",
"value": endpoint
}));
});
// Listen for messages
socket.addEventListener("message", callback);
window.onbeforeunload = function() {
socket.close();
};
}