mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-05-10 02:26:45 -07:00
Add development server
This commit is contained in:
parent
04bddee78c
commit
2032d86daa
11 changed files with 1497 additions and 42 deletions
36
src/refresh_websocket.js
Normal file
36
src/refresh_websocket.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
(function () {
|
||||
"use strict";
|
||||
|
||||
console.log("Connecting...");
|
||||
|
||||
let socket;
|
||||
|
||||
function start(reload) {
|
||||
socket = new WebSocket("ws://127.0.0.1:8080");
|
||||
let reloading = false;
|
||||
socket.onmessage = function (ev) {
|
||||
if (ev.data === "reload") {
|
||||
reloading = true;
|
||||
console.log("Reloading...");
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
socket.onclose = function () {
|
||||
if (!reloading) {
|
||||
console.error("Connection closed.");
|
||||
setTimeout(() => {
|
||||
console.log("Retrying connection...");
|
||||
start(true);
|
||||
}, 2000);
|
||||
}
|
||||
};
|
||||
socket.onopen = function () {
|
||||
console.log("Connected!");
|
||||
if (reload) {
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
start(false);
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue