mirror of
https://github.com/qemus/qemu-docker.git
synced 2025-10-06 07:47:04 +08:00
feat: Check VNC connection before redirect (#588)
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
var request;
|
||||
var interval = 1000;
|
||||
|
||||
var webSocketFactory = {
|
||||
connect: function(url) {
|
||||
|
||||
var ws = new WebSocket(url);
|
||||
|
||||
ws.addEventListener("open", e => {
|
||||
ws.close();
|
||||
document.location.reload();
|
||||
});
|
||||
|
||||
ws.addEventListener("error", e => {
|
||||
if (e.target.readyState === 3) {
|
||||
setTimeout(() => this.connect(url), 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function getInfo() {
|
||||
|
||||
var url = "/msg.html";
|
||||
|
||||
try {
|
||||
|
||||
if (window.XMLHttpRequest) {
|
||||
request = new XMLHttpRequest();
|
||||
} else {
|
||||
@@ -52,7 +69,7 @@ function processInfo() {
|
||||
|
||||
if (notFound) {
|
||||
setInfo("Connecting to VNC", true);
|
||||
reload();
|
||||
var webSocket = webSocketFactory.connect("ws://" + window.location.host + "/websockify");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -111,10 +128,4 @@ function schedule() {
|
||||
setTimeout(getInfo, interval);
|
||||
}
|
||||
|
||||
function reload() {
|
||||
setTimeout(() => {
|
||||
document.location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
schedule();
|
||||
|
Reference in New Issue
Block a user