forked from totaljs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.js
More file actions
48 lines (36 loc) · 956 Bytes
/
Copy pathdefault.js
File metadata and controls
48 lines (36 loc) · 956 Bytes
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
exports.install = function() {
F.route('/');
F.route('/one-way-messaging/', view_SSE, ['sse']);
};
function view_SSE() {
var self = this;
var indexer = 0;
var counter = parseInt(self.sseID || '0');
console.log('Last event ID:', self.sseID);
var interval = setInterval(function() {
if (!self.isConnected) {
clearInterval(interval);
return;
}
/*
Send data to client - One way messaging
@data {String or Object}
@eventname {String} :: default null
@id {String} :: default null (Last Event ID)
@retry {Number} :: in milliseconds, default config['default-request-timeout']
controller.sse(data, [eventname], [id], [retry])
*/
self.sse({ counter: counter++, message: utils.GUID(10) }, null, counter);
// reconnect by the @retry
indexer++;
if (indexer > 10) {
clearInterval(interval);
self.close();
}
}, 1000);
/*
self.res.on('close', function() {
console.log('CLIENT DISCONNECT');
});
*/
}