bigbluebutton-Github/client/bbb-html5-client/lib/messagebus.coffee

32 lines
720 B
CoffeeScript
Raw Normal View History

2014-04-14 07:39:18 +08:00
postal = require('postal')
redisrpc = require './redispubsub'
crypto = require 'crypto'
2014-04-14 22:58:20 +08:00
exports.receiveMessage = (callback) ->
2014-04-14 08:16:37 +08:00
postal.subscribe({
2014-04-14 22:58:20 +08:00
channel: "receiveChannel"
topic: "broadcast",
2014-04-14 08:16:37 +08:00
callback: (msg, envelope) ->
2014-04-14 22:58:20 +08:00
callback( msg )
2014-04-14 08:16:37 +08:00
})
2014-04-14 07:39:18 +08:00
2014-04-14 08:16:37 +08:00
exports.sendMessage = (data, callback) ->
2014-04-14 07:39:18 +08:00
replyTo = {
channel: 'model.data',
topic: 'get.' + crypto.randomBytes(16).toString('hex')
};
postal.subscribe({
channel: replyTo.channel,
topic: replyTo.topic,
callback: (msg, envelope) ->
callback( msg.err, msg.data )
}).once()
postal.publish({
channel: 'publishChannel',
topic: 'broadcast',
replyTo: replyTo,
data: data
})