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