bigbluebutton-Github/bigbluebutton-html5/imports/startup/server/RedisPubSub.js

57 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-05 02:29:43 +08:00
import { logger } from '/imports/startup/server/logger';
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';
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
};
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',
'broadcast_layout_message',
];
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') {
logger.info(`Q ${eventName} ${myQueue.total()}`);
}
return myQueue.add({
pattern: pattern,
channel: channel,
jsonMsg: jsonMsg,
});
}
}
}