/
example.js
50 lines (38 loc) · 1.61 KB
/
example.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
var client = require('./index'),
mailEndpoint, mailRequest, pushClient, otherRequest, otherEndpoint;
pushClient = client.SimplePushClient({
simplePushServerURL: 'ws://localhost:7777/simplepush/websocket',
onConnect: function () {
console.log('connected');
mailRequest = pushClient.push.register();
otherRequest = pushClient.push.register();
mailRequest.onsuccess = function (event) {
mailEndpoint = event;
console.log(mailEndpoint);
if (mailEndpoint.pushEndpoint) {
console.log('push endpoint url for mail', mailEndpoint.pushEndpoint);
} else {
console.log('mail be registered');
}
console.log('subscribed to mail messages on' + mailEndpoint.channelID);
};
otherRequest.onsuccess = function (event) {
otherEndpoint = event;
if (otherEndpoint.pushEndpoint) {
console.log('push endpoint url for otherEndpoint', otherEndpoint.pushEndpoint);
} else {
console.log('otherEndpoint be registered');
}
console.log('subscribed to otherEndpoint messages on' + otherEndpoint.channelID);
};
pushClient.on('push', function (message) {
if (message.channelID === mailEndpoint.channelID) {
// let's react on that mail....
console.log('Mail Notification - ' + message.version);
} else {
console.log('Other Notification - ' + message.version);
}
});
},
onClose: function () {}
});