Commit 81d17d9a authored by Johannes Barthel's avatar Johannes Barthel
Browse files

handle exceptions, fix edge case with duplicate caller number in different meetings

parent b8762ae4
......@@ -37,23 +37,39 @@ class ModeratedMic:
return fs_member_id
def _handle_dtmf_key(self, evt):
#print(evt.headers)
digit = int(evt.headers["DTMF-Digit"])
if digit != 0:
try:
self._handle_dtmf_key_inner(evt)
except Exception as e:
print("Uncaught Error while handling DTMF key event")
print(e)
def _handle_dtmf_key_inner(self, evt):
digit = evt.headers["DTMF-Digit"]
if digit != "0":
return
caller_num = evt.headers["Caller-Username"]
# SECURITY: this assumes there is only one voiceUser per call. What happens
# if there are multiple concurrent calls from the same number in
# different meetings?
voice_user = self.db.voiceUsers.find_one({"callerNum": caller_num, "joined": True})
meeting_num = evt.headers["Caller-Destination-Number"]
meeting = self.db.meetings.find_one({"voiceProp.telVoice": meeting_num})
if meeting is None:
print("meeting", meeting_num, "does not exist")
return
voice_user = self.db.voiceUsers.find_one({"callerNum": caller_num, "joined": True, "meetingId": meeting["meetingId"]})
if voice_user is None:
print("voice user", caller_num, "does not exist")
return
meeting_id = voice_user["meetingId"]
meeting = self.db.meetings.find_one({"meetingId": meeting_id})
locked = meeting["lockSettingsProps"]["disableMic"]
conference_id = meeting["voiceProp"]["voiceConf"]
fs_member_id = self._get_fs_member_id(caller_num, conference_id)
print("caller {} pressed {}, they are in a {} meeting.".format(caller_num, digit, "locked" if locked else "unlocked"))
try:
fs_member_id = self._get_fs_member_id(caller_num, conference_id)
except Exception as e:
print("could not look up fs_member_id")
print(e)
return
print("caller {} pressed 0, they are in a {} meeting.".format(caller_num, "locked" if locked else "unlocked"))
print("fs_member_id", fs_member_id)
try:
if not locked:
print(self.fs.send("api conference {} tmute {}".format(conference_id, fs_member_id)).data)
......@@ -79,46 +95,52 @@ class ModeratedMic:
l = ps.listen()
# main loop iterates over redis events
for msg in l:
if msg["type"] != 'message':
continue
msg = json.loads(msg["data"].decode("utf-8"))["core"]
if not msg["header"]["name"] in ["ChangeLockSettingsInMeetingCmdMsg", "UserJoinedVoiceConfToClientEvtMsg"]:
continue
print(msg)
meeting_id = msg["header"]["meetingId"]
meeting = self.db.meetings.find_one({"meetingId": meeting_id})
if msg["header"]["name"] == "ChangeLockSettingsInMeetingCmdMsg":
# if we change the lock settings, use the value from the message
# because state in mongo will not have been updated yet
mics_disabled = msg["body"]["disableMic"]
# but we need all existing users from mongo
users = self.db.voiceUsers.find({"joined":True, "meetingId": meeting["meetingId"]})
else:
# if we are handling a new user, so use the existing lock settings from mongo
mics_disabled = meeting["lockSettingsProps"]["disableMic"]
# but use the callerNum from the message, because the user isn't yet in mongo
users = [{"callerNum": msg["body"]["callerNum"]}]
try:
if msg["type"] != 'message':
continue
msg = json.loads(msg["data"].decode("utf-8"))["core"]
if not msg["header"]["name"] in ["ChangeLockSettingsInMeetingCmdMsg", "UserJoinedVoiceConfToClientEvtMsg"]:
continue
print(msg)
meeting_id = msg["header"]["meetingId"]
meeting = self.db.meetings.find_one({"meetingId": meeting_id})
if msg["header"]["name"] == "ChangeLockSettingsInMeetingCmdMsg":
# if we change the lock settings, use the value from the message
# because state in mongo will not have been updated yet
mics_disabled = msg["body"]["disableMic"]
# but we need all existing users from mongo
users = self.db.voiceUsers.find({"joined":True, "meetingId": meeting["meetingId"]})
else:
# if we are handling a new user, so use the existing lock settings from mongo
mics_disabled = meeting["lockSettingsProps"]["disableMic"]
# but use the callerNum from the message, because the user isn't yet in mongo
users = [{"callerNum": msg["body"]["callerNum"]}]
# note: this will mute mics "again" if they were already muted
# and some other permission change caused the event to fire.
print("meeting {} is {}".format(meeting_id, "locked" if mics_disabled else "unlocked"))
# note: this will mute mics "again" if they were already muted
# and some other permission change caused the event to fire.
print("meeting {} is {}".format(meeting_id, "locked" if mics_disabled else "unlocked"))
if not mics_disabled:
print("mics are open, not doing anything")
continue
print("muting users")
print(users)
if not mics_disabled:
print("mics are open, not doing anything")
conference_id = meeting["voiceProp"]["voiceConf"]
for user in users:
#print("user")
#print(user)
if user["callerNum"].startswith("w_"):
#print("is a web user")
continue # this is a web user, phone users have their number as callerNum
fs_member_id = self._get_fs_member_id(user["callerNum"], conference_id)
print("muting phone user {} in meeting \"{}\" due to meeting-wide mic permission restriction by moderator".format(user["callerNum"], meeting["meetingProp"]["name"]))
print(self.fs.send("api conference {} mute {}".format(conference_id, fs_member_id)).data)
except Exception as e:
print("Error handling redis event")
print(msg)
continue
print("muting users")
print(users)
conference_id = meeting["voiceProp"]["voiceConf"]
for user in users:
#print("user")
#print(user)
if user["callerNum"].startswith("w_"):
#print("is a web user")
continue # this is a web user, phone users have their number as callerNum
fs_member_id = self._get_fs_member_id(user["callerNum"], conference_id)
print("muting phone user {} in meeting \"{}\" due to meeting-wide mic permission restriction by moderator".format(user["callerNum"], meeting["meetingProp"]["name"]))
print(self.fs.send("api conference {} mute {}".format(conference_id, fs_member_id)).data)
if __name__ == "__main__":
if len(sys.argv) == 1:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment