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