events-observe-lockmic.py 2.08 KB
Newer Older
Johannes Barthel's avatar
intial  
Johannes Barthel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3

import greenswitch
from xml.dom.minidom import parse
import pymongo
import json
import logging
logging.basicConfig(level=logging.DEBUG)

# find out password for esl socket
dom = parse("/opt/freeswitch/etc/freeswitch/autoload_configs/event_socket.conf.xml")

password = None
for param in dom.getElementsByTagName("param"):
	if param.attributes.get("name").nodeValue == "password":
		password = param.attributes.get("value").nodeValue

if password is None:
	raise ValueError("no password found in config")

# connect to mongo
mongo = pymongo.MongoClient("127.0.1.1")
db = mongo.meteor

# connect to freeswitch
fs = greenswitch.InboundESL(host='127.0.0.1', port=8021, password=password)
fs.connect()

def get_fs_member_id(caller_num, conference_id):
        fs_conference = json.loads(fs.send("api conference {} json_list".format(conference_id)).data)[0]
        fs_member_id = [m["id"] for m in fs_conference["members"] if m["caller_id_number"] == caller_num][0]
        return fs_member_id

# wait until participant's right to use the mic gets restricted
for change in db.meetings.watch([{ "$match" : {"operationType" : "update" }}]):
	print("meeting is now disableMic?")
	mics_disabled = change['updateDescription']['updatedFields']['lockSettingsProps']['disableMic']
	if not mics_disabled:
		print("no")
		continue
	print("yes")
	meeting_mongo_id = change['documentKey']['_id']
	meeting = db.meetings.find_one({"_id": meeting_mongo_id})
	#print("meeting",meeting)
	conference_id = meeting["voiceProp"]["voiceConf"]
	for user in db.voiceUsers.find({"joined":True, "meetingId": meeting["meetingId"]}):
		#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 = 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(fs.send("api conference {} mute {}".format(conference_id, fs_member_id)).data)