Created
August 10, 2015 08:54
-
-
Save elvio/93f6be34929941adac94 to your computer and use it in GitHub Desktop.
Room events sample for Foxplan (http://www.github.com/elvio/foxplan)
This file contains 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/web"); | |
function formatMessage(m) { | |
return JSON.stringify(m); | |
} | |
function roomCreate() { | |
var m = { | |
"event": "room_create", | |
"room_name": "Test" | |
} | |
ws.send(formatMessage(m)); | |
}; | |
function inviteUser(name, email) { | |
var m = { | |
"event": "user_invite", | |
"user_name": name, | |
"user_email": email | |
} | |
ws.send(formatMessage(m)); | |
}; | |
function openEstimation() { | |
var m = { | |
"event": "open_estimation" | |
} | |
ws.send(formatMessage(m)); | |
}; | |
function finishEstimation() { | |
var m = { | |
"event": "finish_estimation" | |
} | |
ws.send(formatMessage(m)); | |
}; | |
function cancelEstimation() { | |
var m = { | |
"event": "cancel_estimation" | |
} | |
ws.send(formatMessage(m)); | |
}; | |
ws.onopen = function(event) { | |
console.log("Connected"); | |
roomCreate(); | |
inviteUser("User1", "user1@test.com"); | |
inviteUser("User2", "user2@test.com"); | |
}; | |
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>Web</h1> | |
<p> | |
<button onclick="openEstimation()">Open Estimation</button> | |
</p> | |
<p> | |
<button onclick="cancelEstimation()">Cancel Estimation</button> | |
</p> | |
<p> | |
<button onclick="finishEstimation()">Finish Estimation</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