Skip to content

Commit

Permalink
A few tweaks looking at #26
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 17, 2022
1 parent e73b886 commit 61b5f09
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions client/reload-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,18 @@ class EleventyReload {
Util.log("Trying to connect…");

let { protocol, host } = new URL(document.location.href);

// works with http (ws) and https (wss)
let websocketProtocol = protocol.replace("http", "ws");

// TODO add a path here so that it doesn’t collide with any app websockets
let socket = new WebSocket(`${websocketProtocol}//${host}`);

// Related to #26
// socket.addEventListener("error", (e) => {
// Util.error(`Error connecting:`, e);
// });

// TODO add special handling for disconnect or document focus to retry
socket.addEventListener("message", async function (event) {
try {
Expand All @@ -175,7 +183,7 @@ class EleventyReload {
// Log Eleventy build errors
// Extra parsing for Node Error objects
let e = JSON.parse(data.error);
Util.error(`Build error: ${e.message}`, e);
Util.error(`Build error: ${e.message}`, e);
} else if (type === "eleventy.status") {
// Full page reload on initial reconnect
if (data.status === "connected" && options.mode === "reconnect") {
Expand All @@ -187,7 +195,7 @@ class EleventyReload {
Util.log("Unknown event type", data);
}
} catch (e) {
Util.log("Error", event.data, e.message);
Util.error(`Error parsing ${event.data}: ${e.message}`, e);
}
});

Expand Down

0 comments on commit 61b5f09

Please sign in to comment.