diff --git a/bbb-webhooks/config.coffee b/bbb-webhooks/config.coffee index 2160d1fdb24c6bd7ba8625f4ec61b2acc5b646b8..569966e5294126abb94e8e05f0992d12f10e204f 100644 --- a/bbb-webhooks/config.coffee +++ b/bbb-webhooks/config.coffee @@ -19,6 +19,7 @@ config.hooks.meetingsChannel or= "bigbluebutton:from-bbb-apps:meeting" # IP where aggr will be hosted config.hooks.aggr or= [] config.hooks.queueSize or= 10000 +config.hooks.getRaw or= false # Retry intervals for failed attempts for perform callback calls. # In ms. Totals to around 5min. diff --git a/bbb-webhooks/hook.coffee b/bbb-webhooks/hook.coffee index 74cdee1209233e4ba62fd1343c70dcd35bd3e7b6..df187d64eb8f432a86d59bea4776ade0adc8620c 100644 --- a/bbb-webhooks/hook.coffee +++ b/bbb-webhooks/hook.coffee @@ -39,6 +39,7 @@ module.exports = class Hook @redisClient = redis.createClient() @permanent = false @backupURL = [] + @getRaw = false save: (callback) -> @redisClient.hmset config.redis.keys.hook(@id), @toRedis(), (error, reply) => @@ -89,7 +90,8 @@ module.exports = class Hook "hookID": @id, "callbackURL": @callbackURL, "permanent": @permanent, - "backupURL": @backupURL + "backupURL": @backupURL, + "getRaw": @getRaw r.externalMeetingID = @externalMeetingID if @externalMeetingID? r @@ -98,6 +100,7 @@ module.exports = class Hook @callbackURL = redisData.callbackURL @permanent = redisData.permanent @backupURL = redisData.backupURL + @getRaw = redisData.getRaw if redisData.externalMeetingID? @externalMeetingID = redisData.externalMeetingID else @@ -132,7 +135,7 @@ module.exports = class Hook Logger.warn "Hook: too many failed attempts to perform a callback call, removing the hook for", @callbackURL @destroy() - @addSubscription = (callbackURL, meetingID=null, callback) -> + @addSubscription = (callbackURL, meetingID=null, getRaw, callback) -> #Since we can pass a list of URLs to serve as backup for the permanent hook, we need to check that firstURL = if callbackURL instanceof Array then callbackURL[0] else callbackURL @@ -147,6 +150,7 @@ module.exports = class Hook hook = new Hook() hook.callbackURL = firstURL hook.externalMeetingID = meetingID + hook.getRaw = getRaw hook.permanent = if firstURL in config.hooks.aggr then true else false if hook.permanent then hook.id = 1;nextID++ else hook.id = nextID++ # Create backup URLs list diff --git a/bbb-webhooks/web_hooks.coffee b/bbb-webhooks/web_hooks.coffee index 8027e7d47ce530855d3837fb14229696d1058824..28f0ecd593573d951dfa7b291b954c0338024927 100644 --- a/bbb-webhooks/web_hooks.coffee +++ b/bbb-webhooks/web_hooks.coffee @@ -31,7 +31,7 @@ module.exports = class WebHooks @_processEvent(message) try - error = message + raw = JSON.parse(message) messageMapped = new MessageMapping() messageMapped.mapMessage(JSON.parse(message)) message = messageMapped.mappedObject @@ -56,12 +56,29 @@ module.exports = class WebHooks else processMessage() - + else + @_processRaw(raw) catch e - Logger.error "WebHooks: error processing the message", error, ":", e + Logger.error "WebHooks: error processing the message", raw, ":", e @subscriberEvents.psubscribe config.hooks.pchannel + # Send raw data to hooks that are not expecting mapped messages + _processRaw: (message) -> + hooks = Hook.allGlobalSync() + + # Add hooks for the specific meeting that expect raw data + idFromMessage = message.payload?.meeting_id + if idFromMessage? + eMeetingID = IDMapping.getExternalMeetingID(idFromMessage) + hook = Hook.findByExternalMeetingIDSync(eMeetingID) + hooks = hooks.concat(hook) if hook.getRaw + + # Notify the hooks that expect raw data + async.forEach hooks, (hook) -> + Logger.info "WebHooks: enqueueing a message in the hook:", hook.callbackURL if hook.getRaw + hook.enqueue message if hook.getRaw + # Processes an event received from redis. Will get all hook URLs that # should receive this event and start the process to perform the callback. _processEvent: (message) -> @@ -74,7 +91,7 @@ module.exports = class WebHooks if idFromMessage? eMeetingID = IDMapping.getExternalMeetingID(idFromMessage) hooks = hooks.concat(Hook.findByExternalMeetingIDSync(eMeetingID)) - + # Notify every hook asynchronously, if hook N fails, it won't block hook N+k from receiving its message async.forEach hooks, (hook) -> Logger.info "WebHooks: enqueueing a message in the hook:", hook.callbackURL