-
Notifications
You must be signed in to change notification settings - Fork 4
/
ddp-inspector.js
48 lines (45 loc) · 1.38 KB
/
ddp-inspector.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
var ddpThrottleUpdate = _.throttle(function () {
UpdatePanelTracker.changed();
}, 300);
var _send = Meteor.connection._send;
var counter = 0;
Meteor.connection._send = function (obj) {
if (obj.msg !== 'ping' && obj.msg !== 'pong') {
ddpThrottleUpdate();
}
DDPMessages.insert({
out: true,
message: obj,
messageStr: JSON.stringify(obj, null, ' '),
__order: counter++
}, function () {});
if (Session.equals(DDP_INSPECTOR_CONSOLE_ENABLED, true)) {
console.log("Sent:\n", obj);
}
_send.call(this, obj);
};
Meteor.connection._stream.on('message', function (message) {
var obj = JSON.parse(message);
if (obj.msg !== 'ping' && obj.msg !== 'pong') {
ddpThrottleUpdate();
}
DDPMessages.insert({
message: obj,
messageStr: JSON.stringify(obj, null, ' '),
__order: counter++
}, function () {});
if (Session.equals(DDP_INSPECTOR_CONSOLE_ENABLED, true)) {
console.log("Received:\n", obj);
}
});
Meteor.startup(function () {
Session.setDefaultPersistent(DDP_INSPECTOR_SESSION_ACTIVE, true);
Session.setDefaultPersistent(DDP_INSPECTOR_SUPPRESS_PING, true);
Session.setDefaultPersistent(DDP_INSPECTOR_CONSOLE_ENABLED, false);
Blaze.render(Template[DDP_INSPECTOR_PREFIX], document.body);
// Initialize hot-key
Mousetrap.bind(['command+d', 'ctrl+d', 'shift+d'], function () {
$(DDP_INSPECTOR_PANEL_ID).toggle();
return false;
});
});