Skip to content

Instantly share code, notes, and snippets.

@papercreatures
Created November 15, 2012 15:00
Show Gist options
  • Save papercreatures/4079041 to your computer and use it in GitHub Desktop.
Save papercreatures/4079041 to your computer and use it in GitHub Desktop.
config = require("netdev-share").config
log = require("netdev-share").logger.main()
util = require("util")
_ = require("underscore")
drumWrapper = require("drum-amqp-wrapper")
myDrumAppInfo = drumWrapper.drumConventions.getDrumAppInfo("conferenceapp")
brokerHosts = config.amqp.brokerHosts
switchDrumAppInfo = drumWrapper.drumConventions.getDrumAppInfo("switch")
drumWrapper.setLogLevel config.amqp.logLevel or "INFO"
module.exports = class Inject
constructor: (@csid) ->
@callers = []
connect: (cb = ->) =>
checkCb = (res) ->
if drumWrapper.resultCodes.CONNECTED_OK == res then cb() else cb(true, res)
drumWrapper.establishDrumConnection(
myDrumAppInfo, brokerHosts, @responses, @responses, checkCb)
handler: (id, event, headers) =>
log.info "Received message #{id}"
#add a caller to the conference
addCaller: (opts) =>
log.info "Adding caller", opts
@startConference() unless @callers.length
@send 'status',
from: opts.number
to: "conference #{@csid}:#{opts.suffix} chair"
calluid: "#{opts.number}-#{@callers.length}"
@callers.push opts
startConference: =>
removeCaller: (caller) =>
log.info "Removing caller", opts
send: (type, body) =>
topic = switchDrumAppInfo.topics.loadbalanced
message = drumWrapper.drumEvent.newEvent()
.extend(@templates[type])
.extend(body: body)
log.info "Sending message to #{topic}", message
drumWrapper.send topic, message, (res) ->
log.info res
templates:
status:
head:
type: "confStatus"
body:
trigger: "statusReport"
responses:
general:
template: { head: { }, body: { }}
handler: -> log.error('here')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment