2014-11-14 21:07:16 +08:00
|
|
|
// Lists all the events that happen in a meeting. Run with 'node events.js'.
|
|
|
|
// Uses the first meeting started after the application runs and will list all
|
|
|
|
// events, but only the first time they happen.
|
|
|
|
|
2017-09-14 02:51:21 +08:00
|
|
|
const redis = require("redis");
|
|
|
|
const config = require('../config.js');
|
2014-11-14 21:07:16 +08:00
|
|
|
var target_meeting = null;
|
|
|
|
var events_printed = [];
|
2018-07-26 02:14:55 +08:00
|
|
|
var subscriber = redis.createClient(process.env.REDIS_PORT || config.redis.port, process.env.REDIS_HOST || config.redis.host);
|
2014-11-14 21:07:16 +08:00
|
|
|
|
|
|
|
subscriber.on("psubscribe", function(channel, count) {
|
|
|
|
console.log("subscribed to " + channel);
|
|
|
|
});
|
|
|
|
|
|
|
|
subscriber.on("pmessage", function(pattern, channel, message) {
|
|
|
|
try {
|
|
|
|
message = JSON.parse(message);
|
2017-11-02 03:10:41 +08:00
|
|
|
if (message.hasOwnProperty('envelope')) {
|
2014-11-14 21:07:16 +08:00
|
|
|
|
2017-09-14 02:51:21 +08:00
|
|
|
var message_name = message.envelope.name;
|
2014-11-14 21:07:16 +08:00
|
|
|
|
2017-09-14 02:51:21 +08:00
|
|
|
if (!containsOrAdd(events_printed, message_name)) {
|
|
|
|
console.log("\n###", message_name, "\n");
|
|
|
|
console.log(message);
|
|
|
|
console.log("\n");
|
2014-11-14 21:07:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
console.log("error processing the message", message, ":", e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-14 02:51:21 +08:00
|
|
|
for (let k in config.hooks.channels) {
|
|
|
|
const channel = config.hooks.channels[k];
|
|
|
|
subscriber.psubscribe(channel);
|
|
|
|
}
|
2014-11-14 21:07:16 +08:00
|
|
|
|
|
|
|
var containsOrAdd = function(list, value) {
|
|
|
|
for (i = 0; i <= list.length-1; i++) {
|
|
|
|
if (list[i] === value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list.push(value);
|
|
|
|
return false;
|
|
|
|
}
|