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.
This commit is contained in:
Leonardo Crauss Daronco 2014-11-12 18:27:21 -02:00
parent 5e141d324c
commit 66bfbeb1bc

View File

@ -3,33 +3,36 @@ redis = require("redis")
config = require("./config") config = require("./config")
# The database of mappings. Format: # The database of mappings. Uses the externalID as key because it changes less than
# { internalMeetingID: externalMeetingID } # the internal ID (e.g. the internalID can change for different meetings in the same
# room). Format:
# { externalMeetingID: internalMeetingID }
db = {} db = {}
# A simple model to store mappings for meeting IDs. # A simple model to store mappings for meeting IDs.
module.exports = class MeetingIDMap module.exports = class MeetingIDMap
@addOrUpdateMapping = (internalMeetingID, externalMeetingID) -> @addOrUpdateMapping = (internalMeetingID, externalMeetingID) ->
db[internalMeetingID] = externalMeetingID db[externalMeetingID] = internalMeetingID
console.log "MeetingIDMap: added or changed meeting mapping to the list { #{internalMeetingID}: #{db[internalMeetingID]} }" console.log "MeetingIDMap: added or changed meeting mapping to the list { #{externalMeetingID}: #{db[externalMeetingID]} }"
MeetingIDMap.updateRedis() MeetingIDMap.updateRedis()
@removeMapping = (internalMeetingID) -> @removeMapping = (internalMeetingID) ->
if internalMeetingID in _.keys(db) for external, internal of db
console.log "MeetingIDMap: removing meeting mapping from the list { #{internalMeetingID}: #{db[internalMeetingID]} }" if internalMeetingID is internal
delete db[internalMeetingID] console.log "MeetingIDMap: removing meeting mapping from the list { #{external}: #{db[external]} }"
db[internalMeetingID] = null delete db[external]
MeetingIDMap.updateRedis() db[external] = null
MeetingIDMap.updateRedis()
@getInternalMeetingID = (externalMeetingID) -> @getInternalMeetingID = (externalMeetingID) ->
for internal, external of db db[externalMeetingID]
if external is externalMeetingID
return internal
null
@getExternalMeetingID = (internalMeetingID) -> @getExternalMeetingID = (internalMeetingID) ->
db[internalMeetingID] for external, internal of db
if internal is internalMeetingID
return external
null
@initialize = (callback) -> @initialize = (callback) ->
MeetingIDMap.resync(callback) MeetingIDMap.resync(callback)