forked from Reportr/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.js
41 lines (37 loc) · 1.06 KB
/
notifications.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
define([
"underscore",
"hr/hr",
"vendors/socket.io"
], function(_, hr, io) {
var NotificationsManager = hr.Class.extend({
/*
* Initialize
*/
initialize: function() {
var that = this;
NotificationsManager.__super__.initialize.apply(this, arguments);
this.socket = io.connect([window.location.protocol, '//', window.location.host].join('')+"/", {
'resource': 'socket.io'
});
this.socket.on('notification', function (data) {
that.trigger("io:"+data.event, data);
});
return this;
},
/*
* Subscribe to a channel
*/
subscribe: function(channel) {
this.socket.emit('subscribe', channel);
return this;
},
/*
* Unsubscribe from a channel
*/
unsubscribe: function(channel) {
this.socket.emit('unsubscribe', channel);
return this;
},
});
return new NotificationsManager();
});