From 66bfbeb1bce9ec5e6db824867a43b90d5deaa62f Mon Sep 17 00:00:00 2001 From: Leonardo Crauss Daronco Date: Wed, 12 Nov 2014 18:27:21 -0200 Subject: [PATCH] Webhooks: use external meeting ID as key in the mappings It changes less than the internal meeting ID. An application can subscribe to an external ID and use the hook for several different meetings that will have the same external ID but different internal IDs. --- labs/bbb-callback/meeting_id_map.coffee | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/labs/bbb-callback/meeting_id_map.coffee b/labs/bbb-callback/meeting_id_map.coffee index 4d1a41699e..adbc38d422 100644 --- a/labs/bbb-callback/meeting_id_map.coffee +++ b/labs/bbb-callback/meeting_id_map.coffee @@ -3,33 +3,36 @@ redis = require("redis") config = require("./config") -# The database of mappings. Format: -# { internalMeetingID: externalMeetingID } +# The database of mappings. Uses the externalID as key because it changes less than +# the internal ID (e.g. the internalID can change for different meetings in the same +# room). Format: +# { externalMeetingID: internalMeetingID } db = {} # A simple model to store mappings for meeting IDs. module.exports = class MeetingIDMap @addOrUpdateMapping = (internalMeetingID, externalMeetingID) -> - db[internalMeetingID] = externalMeetingID - console.log "MeetingIDMap: added or changed meeting mapping to the list { #{internalMeetingID}: #{db[internalMeetingID]} }" + db[externalMeetingID] = internalMeetingID + console.log "MeetingIDMap: added or changed meeting mapping to the list { #{externalMeetingID}: #{db[externalMeetingID]} }" MeetingIDMap.updateRedis() @removeMapping = (internalMeetingID) -> - if internalMeetingID in _.keys(db) - console.log "MeetingIDMap: removing meeting mapping from the list { #{internalMeetingID}: #{db[internalMeetingID]} }" - delete db[internalMeetingID] - db[internalMeetingID] = null - MeetingIDMap.updateRedis() + for external, internal of db + if internalMeetingID is internal + console.log "MeetingIDMap: removing meeting mapping from the list { #{external}: #{db[external]} }" + delete db[external] + db[external] = null + MeetingIDMap.updateRedis() @getInternalMeetingID = (externalMeetingID) -> - for internal, external of db - if external is externalMeetingID - return internal - null + db[externalMeetingID] @getExternalMeetingID = (internalMeetingID) -> - db[internalMeetingID] + for external, internal of db + if internal is internalMeetingID + return external + null @initialize = (callback) -> MeetingIDMap.resync(callback)