@ -17,8 +17,8 @@
background-color: #fda;
width: 320px;
height: 480px;
opacity: 0.5 ;
border: 2 px solid black;
opacity: 0.1 ;
border: 1 px solid black;
}
.user {
-webkit-transition: left 0.5s linear, top 0.5s linear;
@ -39,37 +39,46 @@
padding: 2px;
background-color: #0af;
}
#svgscreen {
background-color: #adf;
position: absolute;
width: 320px;
height: 480px;
}
#svgscreen line {
stroke: rgb(255,0,0);
stroke-width: 2;
}
< / style >
< script type = "text/javascript" src = "drawing.js" > < / script >
< script type = "text/javascript" src = "connection.js" > < / script >
< script type = "text/javascript" src = "websocket.js" > < / script >
< script type = "text/javascript" src = "drawing.js" > < / script >
< script type = "text/javascript" src = "rendering.js" > < / script >
< script language = "javascript" type = "text/javascript" >
var myName = Math.random().toString(36).substring(7);
var websocket;
var circle;
var svgscreen;
var current_svgline;
function init() {
var statusbar = document.getElementById('status');
circle = document.getElementById("circle_of_people");
init_drawing();
document.getElementById("myName").innerHTML = myName;
svgscreen = document.getElementById("svgscreen");
if ("WebSocket" in window){
document.getElementById("myName").innerHTML = myName ;
testWebSocket( );
init_drawing(circle, drawStart, drawMove, drawEnd, drawRemove) ;
init_websocket(statusbar, onOpen, onMessage );
} else {
document.getElementById("status") .innerHTML = 'No websockets :(. This means that you either use < em > Internet Explorer< / em > or < em > Android< / em > . In both cases, I suggest that you use < a href = "http://www.google.com/chrome/" > Chrome< / a > or < a href = "http://www.getfirefox.net/" > Firefox< / a > !';
statusbar .innerHTML = 'No websockets :(. This means that you either use < em > Internet Explorer< / em > or < em > Android< / em > . In both cases, I suggest that you use < a href = "http://www.google.com/chrome/" > Chrome< / a > or < a href = "http://www.getfirefox.net/" > Firefox< / a > !';
}
}
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) {
document.getElementById("status").innerHTML = "CONNECTED";
doSend();
}
function onMessage(evt) {
var people = JSON.parse(evt.data);
for (var i = people.length - 1; i >= 0; i--) {
@ -112,6 +121,27 @@
doSend();
}, 500);
}
function drawStart(line){
current_svgline = addLine(line, svgscreen);
}
function drawMove(line){
updateLine(current_svgline, line);
}
function drawEnd(line){
console.log(JSON.stringify(line));
drawRemove(line);
}
function drawRemove(line){
if(current_svgline){
svgscreen.removeChild(current_svgline);
current_svgline = null;
}
}
function doSend(message) {
var myself = {
name: myName,
@ -120,12 +150,6 @@
websocket.send(JSON.stringify(myself));
}
function onError(evt) {
document.getElementById("status").innerHTML = 'ERROR: ' + evt.data;
}
function onClose(evt) {
document.getElementById("status").innerHTML = "DISCONNECTED";
}
window.addEventListener("load", init, false);
@ -136,9 +160,10 @@
< / head >
< body ontouchmove = "prevent_scrolling(event);" >
< p > My name is: < span id = "myName" > < / span >
< p > Status: < span id = "status" > unknown < / s pan >
< p > My name is: < span id = "myName" > < / span > < / p >
< p > Status: < span id = "status" > CONNECTING...< / span > < / p >
< svg id = "svgscreen" xmlns = "http://www.w3.org/2000/svg" version = "1.1" > < / svg >
< div id = "circle_of_people" > < / div >
< / body >