-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex1.html
More file actions
135 lines (127 loc) · 3.66 KB
/
index1.html
File metadata and controls
135 lines (127 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Sortable - Connect lists</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://js.leapmotion.com/leap-0.6.3.min.js"></script>
<script src="http://js.leapmotion.com/leap-plugins-0.1.10.js"></script>
<style>
#sortable1, #sortable2 {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#sortable1 li, #sortable2 li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
</style>
<script type="text/javascript">
var socket;
var stream;
var streams = [];
function init() {
var host = "ws://10.0.0.35:9000/echobot"; // SET THIS TO YOUR SERVER
try {
socket = new WebSocket(host);
console.log('WebSocket - status '+socket.readyState);
socket.onopen = function(msg) {
console.log("Welcome - status "+this.readyState);
};
socket.onmessage = function(msg) {
data = JSON.parse(msg.data);
if (data) {
if (data.cmd == 5) {
streams[data.usr] = data.data;
render();
}
}
// console.log("Received: "+msg.data);
};
socket.onclose = function(msg) {
console.log("Disconnected - status "+this.readyState);
};
}
catch(ex){
console.log(ex);
}
}
function render()
{
for(var id in streams) {
var ids = 'stream' + id;
if($('#'+ids).length) {
$('#'+ids).attr('src', 'data:image/jpg;base64,'+streams[id]);
} else {
var str = '<img id="'+ids+'" src="data:image/jpg;base64,'+streams[id]+'" />';
$('#result').append(str);
}
}
}
$( document ).ready(function() {
init();
});
// function initStream() {
// var host = "ws://10.0.0.35:9001/echobot"; // SET THIS TO YOUR SERVER
// try {
// stream = new WebSocket(host);
// log('WebSocket - status '+stream.readyState);
// stream.onopen = function(msg) {
// console.log("Welcome - status "+this.readyState);
// };
// stream.onmessage = function(msg) {
// $('#stream').attr('src', msg);
// console.log("Received: "+msg.data);
// };
// stream.onclose = function(msg) {
// console.log("Disconnected - status "+this.readyState);
// };
// }
// catch(ex){
// console.log(ex);
// }
// }
function send(){
var txt,msg;
txt = $("#msg");
msg = txt.val();
if(!msg) {
alert("Message can not be empty");
return;
}
try {
socket.send(msg);
console.log('Sent: '+msg);
} catch(ex) {
console.log(ex);
}
}
function quit(){
if (socket != null) {
console.log("Goodbye!");
socket.close();
socket=null;
}
}
function reconnect() {
quit();
init();
}
</script>
</head>
<body>
<div id="result"></div>
<input type="text" id="msg" name="msg"/>
<button onclick="send()">Send</button>
</body>
</html>