mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 19:21:03 +01:00
9f85b74fc9
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
34 lines
872 B
HTML
34 lines
872 B
HTML
<input id="input" type="text" />
|
|
<button onclick="send()">Send</button>
|
|
<pre id="output"></pre>
|
|
<script src="/iris-ws.js"></script>
|
|
<script>
|
|
var input = document.getElementById("input");
|
|
var output = document.getElementById("output");
|
|
|
|
// Ws comes from the auto-served '/iris-ws.js'
|
|
var socket = new Ws("ws://localhost:8080/echo");
|
|
socket.OnConnect(function () {
|
|
output.innerHTML += "Status: Connected\n";
|
|
});
|
|
|
|
socket.OnDisconnect(function () {
|
|
output.innerHTML += "Status: Disconnected\n";
|
|
});
|
|
|
|
// read events from the server
|
|
socket.On("chat", function (msg) {
|
|
addMessage(msg)
|
|
});
|
|
|
|
function send() {
|
|
addMessage("Me: "+input.value) // write ourselves
|
|
socket.Emit("chat", input.value);// send chat event data to the websocket server
|
|
input.value = ""; // clear the input
|
|
}
|
|
|
|
function addMessage(msg) {
|
|
output.innerHTML += msg + "\n";
|
|
}
|
|
</script>
|