forked from tmkasun/geo_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.jag
88 lines (73 loc) · 1.99 KB
/
server.jag
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
<%
var log = new Log();
log.info("Start");
webSocket.ontext = function (data) {
log.info("Receive data "+data);
//var ws = this;
var list = application.get('list');
if(list ==null){
log.debug('adding list');
streamList.push(this);
application.put('list', streamList);
log.debug(streamList.length);
}
else{
var storedList = application.get('list');
storedList.push(this);
application.put('list', storedList);
log.debug(storedList.length);
}
//broadcasting
for(var i = list.length - 1; i >= 0; i--) {
list[i].send(data);
}
};
webSocket.onbinary = function (stream) {
//log.debug('Client Streamed : ' + stream.toString());
};
webSocket.onopen = function () {
log.info("Web socket onopen");
var streamList=[];
var list = application.get('list');
if(list ==null){
log.debug('adding list');
streamList.push(this);
application.put('list', streamList);
log.debug(streamList.length);
}
else{
var storedList = application.get('list');
storedList.push(this);
application.put('list', storedList);
log.debug(storedList.length);
}
};
webSocket.onclose = function (status) {
log.debug('Client Streamed close');
log.debug(this.outbound);
var list = application.get('list');
log.debug(list.length);
for(var i = list.length - 1; i >= 0; i--) {
if(list[i] === this) {
list.splice(i, 1);
log.debug("removing element");
}
}
log.debug(list.length);
};
function logToFile(message){
var currentdate = new Date();
var datetime = "[Info]: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds()+"\t";
message = datetime + message + "\n";
var path = "log/server.log";
var file = new File(path);
file.open("a+");
message = file.write(message);
file.close();
}
%>