<!DOCTYPE html>
|
<html lang="en">
|
<head>
|
<meta charset="UTF-8">
|
<title>pending</title>
|
</head>
|
<body style="background-color: #585858;">
|
<script>
|
const PORT = new URL(document.location.href).searchParams.get("port");
|
|
// ===== DhPostMessageDll In-Process Ping-Pong (kein localhost-Webserver noetig) =====
|
// Antwort von C++ kommt hier an (erwartet "pong:ping").
|
window.dhOnMessage = function (msg) {
|
if (msg == "pong:ping");
|
document.title = "#success#CefSharp.PostMessage.Ping#";
|
};
|
function dhSendPing() {
|
try {
|
if (window.CefSharp && window.CefSharp.PostMessage) {
|
CefSharp.PostMessage("ping");
|
} else {
|
document.title = "#failure#CefSharp.PostMessage nicht verfuegbar#";
|
}
|
} catch (e) {
|
document.title = "#failure#CefSharp.PostMessage " + e.message + "#";
|
}
|
}
|
window.addEventListener("load", dhSendPing);
|
|
function pingTestLocal(callback) {
|
try {
|
var xhr = new XMLHttpRequest();
|
xhr.open("GET", "http://127.0.0.1:" + PORT + "/api/ping", true);
|
xhr.timeout = 5000;
|
|
var called = false;
|
function done(result) {
|
if (!called) {
|
called = true;
|
callback(result);
|
}
|
}
|
|
xhr.ontimeout = function () {
|
done({ status: 0, statusText: "timeout" });
|
};
|
xhr.onreadystatechange = function () {
|
if (xhr.readyState === 4) {
|
if (xhr.responseText === "ping") {
|
callback({ status: xhr.status, statusText: "ok" });
|
} else {
|
callback({ status: xhr.status, statusText: xhr.statusText });
|
}
|
}
|
};
|
xhr.send(null);
|
} catch (err) {
|
callback({ status: 0, statusText: err.message });
|
}
|
}
|
|
function pingWithRetry(attemptsLeft, delays, callback) {
|
pingTestLocal(function (result) {
|
if (result.status === 200 || attemptsLeft <= 1) {
|
callback(result, delays.length - attemptsLeft + 1);
|
} else {
|
var delay = delays[delays.length - attemptsLeft + 1] || 5000;
|
setTimeout(function () {
|
pingWithRetry(attemptsLeft - 1, delays, callback);
|
}, delay);
|
}
|
});
|
}
|
|
function onPingResult(result, attempts) {
|
if(result.status === 200) {
|
document.title = "#success#" + attempts + "#";
|
} else {
|
document.title = "#failure#" + result.status + "#" + result.statusText + "#";
|
}
|
}
|
|
function closeWindow() {
|
document.title = "#close#";
|
}
|
|
setTimeout(function () {
|
pingWithRetry(3, [0, 2000, 5000], onPingResult);
|
setTimeout(function () {
|
closeWindow();
|
}, 15000);
|
}, 30000);
|
</script>
|
</body>
|
</html>
|