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

19 lines
425 B

2 months ago
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();
};
}