2016-05-05 02:29:43 +08:00
|
|
|
import { logger } from '/imports/startup/server/logger';
|
2016-05-05 01:00:57 +08:00
|
|
|
import { redisConfig } from '/config';
|
2016-05-17 03:12:49 +08:00
|
|
|
import { myQueue } from '/imports/startup/server';
|
2016-06-02 01:18:13 +08:00
|
|
|
import { indexOf, publish } from '/imports/api/common/server/helpers';
|
2016-05-05 01:00:57 +08:00
|
|
|
|
|
|
|
export class RedisPubSub {
|
|
|
|
constructor() {
|
|
|
|
logger.info('constructor RedisPubSub');
|
|
|
|
this.pubClient = redis.createClient();
|
|
|
|
this.subClient = redis.createClient();
|
|
|
|
logger.info(`Subscribing message on channel: ${redisConfig.channels.fromBBBApps}`);
|
|
|
|
this.subClient.on('psubscribe', Meteor.bindEnvironment(this._onSubscribe));
|
|
|
|
this.subClient.on('pmessage', Meteor.bindEnvironment(this._addToQueue));
|
|
|
|
this.subClient.psubscribe(redisConfig.channels.fromBBBApps);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSubscribe(channel, count) {
|
|
|
|
let message;
|
|
|
|
logger.info(`Subscribed to ${channel}`);
|
|
|
|
|
|
|
|
//grab data about all active meetings on the server
|
|
|
|
message = {
|
|
|
|
header: {
|
|
|
|
name: 'get_all_meetings_request',
|
|
|
|
},
|
2016-05-05 05:49:01 +08:00
|
|
|
payload: {}, // I need this, otherwise bbb-apps won't recognize the message
|
2016-05-05 01:00:57 +08:00
|
|
|
};
|
|
|
|
return publish(redisConfig.channels.toBBBApps.meeting, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
_addToQueue(pattern, channel, jsonMsg) {
|
|
|
|
let eventName, message, messagesWeIgnore;
|
|
|
|
message = JSON.parse(jsonMsg);
|
|
|
|
eventName = message.header.name;
|
|
|
|
messagesWeIgnore = [
|
|
|
|
'BbbPubSubPongMessage',
|
|
|
|
'bbb_apps_is_alive_message',
|
2016-05-05 04:25:34 +08:00
|
|
|
'broadcast_layout_message',
|
|
|
|
];
|
2016-05-05 01:00:57 +08:00
|
|
|
if (indexOf.call(messagesWeIgnore, eventName) < 0) {
|
|
|
|
|
|
|
|
// For DEVELOPMENT purposes only
|
|
|
|
// Dynamic shapes' updates will slow down significantly
|
2016-05-05 05:49:01 +08:00
|
|
|
if (Meteor.settings.public.mode == 'development') {
|
2016-05-05 01:00:57 +08:00
|
|
|
logger.info(`Q ${eventName} ${myQueue.total()}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return myQueue.add({
|
|
|
|
pattern: pattern,
|
|
|
|
channel: channel,
|
|
|
|
jsonMsg: jsonMsg,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|