80 lines
2.2 KiB
HTML
80 lines
2.2 KiB
HTML
<html>
|
|
<head>
|
|
<title>ActivePush Demo Page</title>
|
|
</head>
|
|
<body>
|
|
|
|
<div>
|
|
<label for="push-id">push id:</label>
|
|
<input type="text" name="push-id" id="push-id" value="">
|
|
<label for="message">message:</label>
|
|
<input type="text" name="message" id="message" value="hello world">
|
|
<input type="submit" id="send" value="Send">
|
|
</div>
|
|
<hr>
|
|
<pre id="log"></pre>
|
|
<hr>
|
|
<pre id="health"></pre>
|
|
|
|
<script src="/socket.io/socket.io.js"></script>
|
|
<script>
|
|
var push_id = window.location.hash.slice(1) || "demo"
|
|
window.location.hash = "#" + push_id;
|
|
|
|
// Sample client
|
|
var socket = io.connect("http://localhost");
|
|
socket.on("connect", function () {
|
|
console.log("connected");
|
|
socket.emit("subscribe", push_id);
|
|
console.log("subscribed to push_id:", push_id);
|
|
|
|
// Used in integration tests:
|
|
window.messages = [];
|
|
});
|
|
socket.on("disconnect", function () {
|
|
console.log("disconnected");
|
|
});
|
|
socket.on("error", function (error) {
|
|
console.log("error", error);
|
|
});
|
|
socket.on("message", function (data) {
|
|
messages.push(data)
|
|
console.log("message:", JSON.stringify(data, null, 2));
|
|
});
|
|
|
|
// Demo form
|
|
document.getElementById("push-id").value = push_id;
|
|
document.getElementById("send").onclick = function() {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "send");
|
|
xhr.setRequestHeader("Content-Type", "application/json");
|
|
xhr.send(JSON.stringify({
|
|
push_id: document.getElementById("push-id").value,
|
|
message: document.getElementById("message").value
|
|
}));
|
|
}
|
|
|
|
// Auto-refresh /health
|
|
health = document.getElementById("health");
|
|
setInterval(function() {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("GET", "/health");
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState === 4) {
|
|
health.innerText = xhr.responseText;
|
|
}
|
|
}
|
|
xhr.send();
|
|
}, 1000)
|
|
|
|
// Also pipe log to page for demo purposes
|
|
console._log = console.log;
|
|
console.log = function() {
|
|
console._log.apply(console, arguments);
|
|
document.getElementById("log").textContent += new Date() + ": " + Array.prototype.join.call(arguments, " ") + "\n";
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|