front_idill/extern/fajran-tuiojs/connector/stomp/index.html
author bastiena
Fri, 06 Apr 2012 18:32:13 +0200
changeset 25 a7b0e40bcab0
permissions -rw-r--r--
Front IDILL : Basic JS TUIO lib loaded
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     1
<html><head>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     2
<style type="text/css">
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     3
.box {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     4
	position: absolute;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     5
	top: 100px;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     6
	left: 100px;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     7
	width: 20px;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     8
	height: 20px;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
     9
	background: blue;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    10
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    11
</style>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    12
<script type="text/javascript" src="jquery.js"></script>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    13
<script type="text/javascript" src="/static/Orbited.js"></script>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    14
<script type="text/javascript">
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    15
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    16
TCPSocket = Orbited.TCPSocket;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    17
</script>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    18
<script type="text/javascript" src="/static/protocols/stomp/stomp.js"></script>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    19
<script type="text/javascript">
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    20
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    21
var sc;
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    22
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    23
function process(data) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    24
	var type = data[0];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    25
	var action = data[1];
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    26
	var id = parseInt(data[2]);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    27
	var x = parseInt(parseFloat(data[3]) * window.innerWidth);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    28
	var y = parseInt(parseFloat(data[4]) * window.innerHeight);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    29
	console.log(action);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    30
	if (action == "U") {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    31
		$('#b'+id).css({'top': y+"px", 'left': x+"px"});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    32
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    33
	else if (action == "N") {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    34
		console.log("new");
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    35
		$('#container').append('<div class="box" id="b' + id + '"></div>');
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    36
		$('#b'+id).css({'top': y+"px", 'left': x+"px"});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    37
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    38
	else if (action == "R") {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    39
		console.log("remove");
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    40
		$('#b'+id).remove();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    41
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    42
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    43
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    44
onload = function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    45
	console.log('onload');
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    46
	sc = new STOMPClient();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    47
	sc.onopen = function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    48
		console.log("[stomp] open");
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    49
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    50
	sc.onclose = function(code) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    51
		console.log("[stomp] close: code=" + code);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    52
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    53
	sc.onerror = function(err) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    54
		console.log("[stomp] error: " + err);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    55
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    56
	sc.onerrorframe = function(frame) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    57
		console.log("[stomp] frame error: " + frame.body);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    58
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    59
	sc.onconnectedframe = function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    60
		console.log("[stomp] connected");
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    61
		sc.subscribe('/topic/home', {exchange:''});
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    62
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    63
	sc.onmessageframe = function(frame) {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    64
		console.log(frame.body);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    65
		process(frame.body.split(" "));
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    66
	}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    67
	console.log('aa');
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    68
	setTimeout(function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    69
		sc.connect('localhost', 61613, 'guest', 'guest');
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    70
	}, 10);
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    71
};
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    72
onunload = function() {
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    73
	sc.reset();
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    74
}
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    75
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    76
</script>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    77
</head><body>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    78
<div id="container">
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    79
</div>
a7b0e40bcab0 Front IDILL :
bastiena
parents:
diff changeset
    80
</body></html>