-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.js
55 lines (45 loc) · 972 Bytes
/
notification.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
class Notification {
/**
* Construct the AMQPlib instance
*/
constructor(ch) {
this.ch = ch
this.queue = 'notifications'
this.admin = []
}
notify(type, driver, recipient, json, options = {}) {
return new Promise(async (resolve, reject) => {
if(!this.queue) {
var queue = options.queue
} else {
var queue = this.queue
}
await this.ch.assertQueue(queue)
this.ch.sendToQueue(queue, Buffer.from(JSON.stringify(json)), {
contentType: 'application/json',
headers: {
driver: driver,
type: type,
recipient: recipient,
options
}
})
resolve()
})
}
// admin
setAdmin(payload = []) {
for(let i = 0; i < payload.length; i++) {
this.admin[payload[i].driver] = payload[i].recipient
}
}
getAdmin(driver) {
return this.admin[driver]
}
}
function delay(ms) {
return new Promise(async function(resolve, reject) {
setTimeout(() => resolve(), ms);
})
}
module.exports = Notification;