make publish function private to RedisPubSub2x class

This commit is contained in:
KDSBrowne 2017-09-13 08:29:23 -07:00
parent 4b7d790a57
commit 41b629b232

View File

@ -5,12 +5,39 @@ import { EventEmitter2 } from 'eventemitter2';
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import Logger from './logger'; import Logger from './logger';
const RedisPubSub2xWrapper = ( () => {
this.pub = Redis.createClient();
// this publish function should only be called from either publishSystemMessage,
// publishMeetingMessage, publishVoiceMessage or publishUserMessage
const publish = (channel, eventName, header, body) => {
const envelope = {
envelope: {
name: eventName,
routing: {
sender: 'bbb-apps-akka',
// sender: 'html5-server', // TODO
}
},
core: {
header,
body,
}
};
Logger.warn(`<<<<<<Publishing 2.0 ${eventName} to ${channel} ${JSON.stringify(envelope)}`);
return this.pub.publish(channel, JSON.stringify(envelope), (err) => {
if (err) {
Logger.error('Tried to publish to %s', channel, envelope);
}
});
}
class RedisPubSub2x { class RedisPubSub2x {
constructor(config = {}) { constructor(config = {}) {
this.config = config; this.config = config;
this.didSendRequestEvent = false; this.didSendRequestEvent = false;
this.pub = Redis.createClient();
this.sub = Redis.createClient(); this.sub = Redis.createClient();
this.emitter = new EventEmitter2(); this.emitter = new EventEmitter2();
this.queue = new PowerQueue(); this.queue = new PowerQueue();
@ -46,7 +73,7 @@ class RedisPubSub2x {
voiceConf voiceConf
} }
this.publish(channel, eventName, header, payload); return publish(channel, eventName, header, payload);
} }
publishSystemMessage(channel, eventName, payload) { publishSystemMessage(channel, eventName, payload) {
@ -54,7 +81,7 @@ class RedisPubSub2x {
name: eventName name: eventName
} }
this.publish(channel, eventName, header, payload); return publish(channel, eventName, header, payload);
} }
publishMeetingMessage(channel, eventName, meetingId, payload) { publishMeetingMessage(channel, eventName, meetingId, payload) {
@ -63,7 +90,7 @@ class RedisPubSub2x {
meetingId meetingId
} }
this.publish(channel, eventName, header, payload); return publish(channel, eventName, header, payload);
} }
publishUserMessage(channel, eventName, meetingId, userId, payload) { publishUserMessage(channel, eventName, meetingId, userId, payload) {
@ -73,32 +100,7 @@ class RedisPubSub2x {
userId userId
} }
this.publish(channel, eventName, header, payload); return publish(channel, eventName, header, payload);
}
// this publish function should only be called from either publishSystemMessage,
// publishMeetingMessage or publishUserMessage
publish(channel, eventName, header, payload) {
const envelope = {
envelope: {
name: eventName,
routing: {
sender: 'bbb-apps-akka',
// sender: 'html5-server', // TODO
}
},
core: {
header,
body: payload,
}
};
Logger.warn(`<<<<<<Publishing 2.0 ${eventName} to ${channel} ${JSON.stringify(envelope)}`);
return this.pub.publish(channel, JSON.stringify(envelope), (err) => {
if (err) {
Logger.error('Tried to publish to %s', channel, envelope);
}
});
} }
handleSubscribe() { handleSubscribe() {
@ -178,8 +180,11 @@ class RedisPubSub2x {
} }
} }
} }
return RedisPubSub2x;
})();
const RedisPubSubSingleton = new RedisPubSub2x();
const RedisPubSubSingleton = new RedisPubSub2xWrapper;
Meteor.startup(() => { Meteor.startup(() => {
const REDIS_CONFIG = Meteor.settings.redis; const REDIS_CONFIG = Meteor.settings.redis;