Better redis channels for the html5 client

This commit is contained in:
Leonardo Crauss Daronco 2014-04-23 17:37:19 -04:00
parent 8202cebfea
commit e551679685
3 changed files with 19 additions and 12 deletions

View File

@ -25,6 +25,13 @@ config.app.sessionSecret = "J7XSu96KC/B/UPyeGub3J6w6QFXWoUNABVgi9Q1LskE="
config.redis = {}
config.redis.host = "127.0.0.1"
config.redis.post = "6379"
config.redis.channels = {}
config.redis.channels.fromBBBApps = "from-bbb-apps"
config.redis.channels.toBBBApps = "to-bbb-apps"
config.redis.internalChannels = {}
config.redis.internalChannels.receive = "html5-receive"
config.redis.internalChannels.reply = "html5-reply"
config.redis.internalChannels.publish = "html5-publish"
# Logging
config.log = {}

View File

@ -13,25 +13,25 @@ module.exports = class MessageBus
receiveMessages: (callback) ->
postal.subscribe
channel: "receiveChannel"
channel: config.redis.internalChannels.receive
topic: "broadcast"
callback: (msg, envelope) ->
callback( msg )
callback(msg.err, msg.data)
sendAndWaitForReply: (data, callback) ->
replyTo =
channel: 'replyChannel'
channel: config.redis.internalChannels.reply
topic: 'get.' + crypto.randomBytes(16).toString('hex')
postal.subscribe(
channel: replyTo.channel
topic: replyTo.topic
callback: (msg, envelope) ->
callback( msg.err, msg.data )
callback(msg.err, msg.data)
).once()
postal.publish
channel: 'publishChannel'
channel: config.redis.internalChannels.publish
topic: 'broadcast'
replyTo: replyTo
data: data

View File

@ -2,6 +2,7 @@ redis = require 'redis'
crypto = require 'crypto'
postal = require 'postal'
config = require '../config'
log = require './bbblogger'
# default timeout to wait for response
@ -17,7 +18,7 @@ module.exports = class RedisPubSub
@pendingRequests = {}
postal.subscribe
channel: 'publishChannel'
channel: config.redis.internalChannels.publish
topic: 'broadcast'
callback: (msg, envelope) ->
if envelope.replyTo?
@ -49,8 +50,8 @@ module.exports = class RedisPubSub
else
sendToController message
log.info("RPC: Subscribing message on channel [responseChannel]")
@subClient.subscribe("responseChannel")
log.info("RPC: Subscribing message on channel [#{config.redis.channels.fromBBBApps}]")
@subClient.subscribe(config.redis.channels.fromBBBApps)
sendAndWaitForReply: (message, envelope) ->
# generate a unique correlation id for this call
@ -79,14 +80,13 @@ module.exports = class RedisPubSub
# put the entry in the hash so we can match the response later
@pendingRequests[correlationId] = entry
console.log("Publishing #{message}")
message.header.correlationId = correlationId
@pubClient.publish("bigbluebuttonAppChannel", JSON.stringify(message))
log.info("Publishing #{message}")
@pubClient.publish(config.redis.channels.toBBBApps, JSON.stringify(message))
sendToController = (message) ->
postal.publish
channel: "receiveChannel"
channel: config.redis.internalChannels.receive
topic: "broadcast"
data: message