-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscriber.js
62 lines (53 loc) · 1.74 KB
/
subscriber.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
60
61
62
const IOSocket = require('./io.js');
const mailer = require('./mailer.js');
const EventEmitter = require('events');
const shared = require('./sharable.js');
const DBOperation = require('./database.js');
class Subscriber extends EventEmitter
{
constructor() {
super();
this.eventResponse = "something went wrong";
}
//Create an event handler:
summerCall() {
console.log('Temp - 42c!');
this.eventResponse = "summer";
};
winterCall() {
console.log('Temp - 2c!');
this.eventResponse = "winter";
};
async sendMail() {
const sendMail = mailer.sendMail;
const mailerResponse = sendMail();
if(mailerResponse && mailerResponse.then) {
let promise = shared.withErrorHandler(mailerResponse);
promise.then((msg) => {
this.eventResponse = msg;
});
}
};
async dbOperation(queryObject) {
const dbOperation = new DBOperation();
await dbOperation.dbOperation(queryObject);
this.eventResponse = dbOperation.response;
console.log(dbOperation.response);
}
async homePage(queryObject, httpServer) {
const io = new IOSocket(httpServer);
await io.render().then((file_data) => {
res.write(file_data);
res.end();
})
}
}
subscriber = new Subscriber();
subscriber.on('', subscriber.homePage);
subscriber.on('summer', subscriber.summerCall);
subscriber.on('winter', subscriber.winterCall);
subscriber.on('sendmail', subscriber.sendMail);
subscriber.on('database', subscriber.dbOperation);
module.exports = subscriber;
watch_out = "https://www.youtube.com/watch?v=9ErAONqE6HE";
"https://www.youtube.com/watch?v=1e4ltxBZZCA";