Multi-user gravity beats for Sound of Science 2013 (website)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

47 lines
1.2 KiB

12 years ago
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script language="javascript" type="text/javascript">
var wsUri = "ws://127.0.0.1:7681";
var people;
var myName = Math.random().toString(36).substring(7);
12 years ago
function init() {
people = document.getElementById("people");
document.getElementById("myName").innerHTML = myName;
12 years ago
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function (evt) {onOpen(evt)};
websocket.onclose = function (evt) {onClose(evt)};
websocket.onmessage = function (evt) {onMessage(evt)};
websocket.onerror = function (evt) {onError(evt)};
}
function onOpen(evt) {
doSend(myName);
12 years ago
}
function onClose(evt) {
writeToScreen("DISCONNECTED");
}
function onMessage(evt) {
writeToScreen(evt.data);
setTimeout(function(){doSend(myName);}, 1000);
12 years ago
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message) {
websocket.send(message);
}
function writeToScreen(message) {
people.innerHTML = message;
12 years ago
}
window.addEventListener("load", init, false);
</script>
<p>My name is: <span id="myName"></span>
<p>Response of server: <span id="people"></span>
12 years ago
</html>