-
Notifications
You must be signed in to change notification settings - Fork 13
/
generic.js
61 lines (51 loc) · 1.18 KB
/
generic.js
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
var websocket;
var output;
var c;
var logdiv;
window.onload =
function() {
//console.log('<p>started');
}
function loadScript(File) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = File;
s.onload = function(){send('loaded')};
document.body.appendChild(s);
}
function onClose(evt) {
console.log('<p><b>closed</b>');
document.body.style.backgroundColor='#aabbcc';
}
function onMessage(evt) {
try
{
eval(evt.data);
}
catch(e)
{
alert("oops:"+evt.data);
}
}
function onError(evt) {
document.body.style.backgroundColor='orange';
}
function send(msg) {
websocket.send(msg);
}
function log(x) {
logdiv.innerHTML += x;
}
function start_session(wsUri){
console.log("<br>try to connect");
document.body.style.backgroundColor='#ccaabb';
websocket = new WebSocket(wsUri);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage;
websocket.onerror = onError;
return(false);
}
function onOpen(evt) {
console.log("connected");
}