Unverified Commit b96566f4 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Check VNC connection before redirect (#588)

parent 16c193df
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
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();