Diff of /test.html [c2b811] .. [1fa7c0]  Maximize  Restore

Switch to unified view

a/test.html b/test.html
...
...
678
<!DOCTYPE html>
678
<!DOCTYPE html>
679
<html lang="en">
679
<html lang="en">
680
<head>
680
<head>
681
    <meta charset="UTF-8">
681
    <meta charset="UTF-8">
682
    <title>Title</title>
682
    <title>Title</title>
683
    <script src="wvdetection.js"></script>
683
</head>
684
</head>
684
<body onload="onBodyLoad()">
685
<body onload="onBodyLoad()">
685
<script>
686
<script>
686
    window.addEventListener("message", receiveMessage, false);
687
687
688
    function onBodyLoad() {
688
    let url0, url1, activeUrl, urlSet = false, timer = -1;
689
        const wvDetection = new WVDetection("frame");
689
690
        wvDetection.setWebvisuUrls(["http://localhost:8080/webvisu.htm", "http://localhost:8080/webvisu.htm"]);
690
    function onBodyLoad() {
691
        wvDetection.start();
691
        url0 = document.getElementById("url0");
692
    }
692
        url1 = document.getElementById("url1");
693
</script>
693
    }
694
<iframe id="frame"></iframe>
694
695
<br><br>
695
    function receiveMessage(event) {
696
        if (activeUrl.startsWith(event.origin)) {
697
            if (timer !== -1) {
698
                clearTimeout(timer);
699
                timer = -1;
700
                console.log("Received messages. Killing timer!");
701
            }
702
            var message = event.data;
703
            console.log(message);
704
            if (message === "--INFO--\"Still polling the registration of the visualization. Is the visu stopped?\"") {
705
                console.log("Webvisu stopped? Switching to different url");
706
                setTimeout(switchToDifferentWebvisu, 1000);
707
            }
708
            if (message === "Error while processing the visualization: Sending service aborted") {
709
                console.log("Download? Switching to different url");
710
                setTimeout(switchToDifferentWebvisu, 1000);
711
            }
712
            if (message === "--INFO--\"Triing to reconnect after error\"") {
713
                console.log("Error? Switching to different url");
714
                setTimeout(switchToDifferentWebvisu, 1000);
715
            }
716
        }
717
    }
718
719
    function setURL() {
720
        document.getElementById('frame').src = url0.value;
721
        url0.disabled = true;
722
        url1.disabled = true;
723
        document.getElementById("button").disabled = true;
724
        activeUrl = url0.value;
725
        urlSet = true;
726
    }
727
728
    function onLoad() {
729
        if (urlSet) {
730
            timer = setTimeout(function () {
731
                console.log("No message received after 5 seconds, switching to different webvisu.");
732
                switchToDifferentWebvisu();
733
            }, 5000);
734
        }
735
    }
736
737
    function switchToDifferentWebvisu() {
738
        if (activeUrl === url0.value) {
739
            activeUrl = url1.value;
740
        } else if (activeUrl === url1.value) {
741
            activeUrl = url0.value;
742
        } else {
743
            console.error("Unexpected settings! Abort!");
744
            return;
745
        }
746
        document.getElementById('frame').src = activeUrl;
747
    }
748
749
    function onError() {
750
        console.log("onError");
751
    }
752
</script>
753
<iframe id="frame" onload="onLoad()" onerror="onError()"></iframe>
754
<br><br>
755
<label for="url0">Url0:</label>
756
<input type="text" id="url0" name="url0" value="http://localhost:8080/webvisu.htm"><br><br>
757
<label for="url1">Url1:</label>
758
<input type="text" id="url1" name="url1" value="http://localhost:8080/webvisu.htm"><br><br>
759
<button type="button" id="button" onclick="setURL()">Change</button>
760
761
762
</body>
696
</body>
763
</html>
697
</html>