const listener = new EventSource("/app/listen"); listener.onmessage = (e) => { let data = JSON.parse(e.data); console.log(data); switch (data.type) { case "pong": console.log("pong!"); break; case "add_book": viewAddBook(data.book); break; case "update_book": viewUpdateBook(data.book); break; case "delete_book": viewDeleteBook(data.book); break; default: console.log("Unexpected response from SSE:", data); } };