Last active
August 29, 2015 14:27
-
-
Save elvio/80fe2ed9fa656f22fb05 to your computer and use it in GitHub Desktop.
User events sample for Foxplan (http://www.github.com/elvio/foxplan)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
var ws = new WebSocket("ws://localhost:8080/ws/mobile"); | |
function formatMessage(m) { | |
return JSON.stringify(m); | |
} | |
function joinRoom(code) { | |
var m = { | |
"event": "join_room", | |
"user_code": code | |
} | |
ws.send(formatMessage(m)); | |
}; | |
function userEstimate() { | |
var m = { | |
"event": "user_estimate", | |
"user_estimate": "kafka" | |
} | |
ws.send(formatMessage(m)); | |
}; | |
ws.onopen = function(event) { | |
console.log("Connected"); | |
joinRoom("ABCD"); | |
}; | |
ws.onclose = function(event) { | |
console.log("onclose", event); | |
}; | |
ws.onmessage = function(event) { | |
console.log("onmessage", event); | |
document.getElementById("updates").innerHTML += "<hr>" + event.data + "<br>"; | |
}; | |
ws.onerror = function(event) { | |
console.log("onerror", event); | |
document.getElementById("updates").innerHTML += "Error <br>"; | |
}; | |
</script> | |
</head> | |
<body> | |
<h1>Mobile</h1> | |
<p> | |
<button onclick="userEstimate()">User Estimate</button> | |
</p> | |
<div id="updates"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment