-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurrent-visitors-server.js
59 lines (51 loc) · 1.27 KB
/
current-visitors-server.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
// Generated by CoffeeScript 1.9.1
(function() {
"use strict";
var connections, updateVisitors;
connections = {};
updateVisitors = function() {
var id, modifier, path, ref, set, unset;
set = {};
unset = (ref = CurrentVisitors.findOne()) != null ? ref : {};
delete unset._id;
for (id in connections) {
path = connections[id];
path = path.replace(/\./g, '%2E');
if (set[path] != null) {
set[path] += 1;
} else {
set[path] = 1;
}
delete unset[path];
}
modifier = {};
if (Object.keys(set).length > 0) {
modifier.$set = set;
}
if (Object.keys(unset).length > 0) {
modifier.$unset = unset;
}
CurrentVisitors.upsert({}, modifier);
};
Meteor.methods({
'current-visitors': function(path) {
if (this.connection == null) {
return;
}
check(path, String);
connections[this.connection.id] = path;
updateVisitors();
}
});
Meteor.publish('current-visitors', function() {
return CurrentVisitors.find();
});
Meteor.onConnection(function(handle) {
handle.onClose(function() {
delete connections[handle.id];
updateVisitors();
});
});
CurrentVisitors.remove({});
CurrentVisitors.insert({});
}).call(this);