fix: auto-connect ws server
This commit is contained in:
1 parent
78980b2dbf
commit
7aeddba427
2 files changed
+77
-74
No files matched your search
+19
-21
@@ -1,24 +1,22 @@
|
||||
(function () {
|
||||
var protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||
|
||||
var url = protocol + "//" + window.location.host + "/_dioxus/ws";
|
||||
|
||||
var poll_interval = 2000;
|
||||
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
var url = protocol + '//' + window.location.host + '/_dioxus/ws';
|
||||
var poll_interval = 8080;
|
||||
var reload_upon_connect = () => {
|
||||
window.setTimeout(
|
||||
() => {
|
||||
var ws = new WebSocket(url);
|
||||
ws.onopen = () => window.location.reload();
|
||||
ws.onclose = reload_upon_connect;
|
||||
},
|
||||
poll_interval);
|
||||
};
|
||||
|
||||
var ws = new WebSocket(url);
|
||||
|
||||
ws.addEventListener("message", (ev) => {
|
||||
if (ev.data == "reload") {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
ws.addEventListener("open", () => {
|
||||
ws.send("init");
|
||||
});
|
||||
|
||||
ws.addEventListener("close", () => {
|
||||
alert("Dev-Server Socket Closed.");
|
||||
});
|
||||
|
||||
})();
|
||||
ws.onmessage = (ev) => {
|
||||
if (ev.data == "reload") {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
ws.onclose = reload_upon_connect;
|
||||
})()
|
||||
Reference in new issue
Block a user