Skip to content

Commit

Permalink
Twisted server from kuku ready for start after starting FreeSWITCH. Now
Browse files Browse the repository at this point in the history
it ask for untracked UUIDs
  • Loading branch information
krivushinme committed Aug 14, 2009
1 parent bf5168c commit 0d48c7a
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions eventsocket/kuku.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ class InboundProxy(EventProtocol):
def __init__(self):
self.job_uuid = {}
self.conf_msgs = Queue()
self.api_type = Queue()
EventProtocol.__init__(self)

def queue_api(self,command,type):
print "Queue ",type
self.api_type.put(type)
self.api(command)

def authSuccess(self, ev):
self.queue_api("show channels",{"name":"show","subtype":"channels"})
self.eventplain('CHANNEL_CREATE CHANNEL_DESTROY CUSTOM conference::maintenance conference::dtmf')

def authFailure(self, failure):
Expand All @@ -42,55 +49,46 @@ def onChannelCreate(self,data):
pprint.pprint(data)
channels[data.Unique_ID] = data
print channels
self.api("uuid_dump %s"%data.Unique_ID)
self.queue_api("uuid_dump %s"%data.Unique_ID,{"name":"uuid_dump"})

def onChannelDestroy(self,data):
pprint.pprint(data)
del channels[data.Unique_ID]
print channels

def apiFailure(self, ev):
print "Error!", ev
def apiSuccess(self, ev):
# Update channel data with uuid_dump result
type = self.api_type.get()
raw = ev['data']['rawresponse']
if '-ERR' == raw[:4]:
print 'ERROR!'
return
temp = [line.strip().split(': ',1) for line in raw.strip().split('\n') if line]
apidata = superdict([(line[0].replace('-','_'),line[1]) for line in temp])
channels[apidata.Unique_ID].update(apidata)
channel = channels[apidata.Unique_ID]
kuku = channel.get('variable_kuku',None)
print "Channel ",channel.Unique_ID,kuku

def zaglushka(self):
if context == 'conference':
data = temp['data']
if 1==1:
self.conf_msgs.put(data)
self.apiFailure(self,None)
return
#pprint.pprint(apidata)
print "done, %s"%data.Unique_ID

p = Participant.objects.filter(phone__number=data.Caller_Caller_ID_Number,
conference__number=data.Conference_Name)
p = None
print p
if p:
p=p[0]
if data.Action == 'add-member':
p.active=True
elif data.Action == 'del-member':
p.active=False
elif data.Action == 'start-talking':
print "start talk"
elif data.Action == 'stop-talking':
print "stop talk"
elif data.Action == 'mute-member':
print "mute"
elif data.Action == 'unmute-member':
print "unmute"
p.save()

print "Type:",type,raw
if type["name"] == "uuid_dump":
temp = [line.strip().split(': ',1) for line in raw.strip().split('\n') if line]
apidata = superdict([(line[0].replace('-','_'),line[1]) for line in temp])
if apidata.Unique_ID in channels:
channels[apidata.Unique_ID].update(apidata)
else:
channels[apidata.Unique_ID] = apidata
channel = channels[apidata.Unique_ID]
kuku = channel.get('variable_kuku',None)
print "Channel ",channel.Unique_ID,kuku

elif type["name"] == "show":
lines = raw.split("\n\n")[0].strip().splitlines()
headers = [header.strip() for header in lines[0].split(',')]
response = [superdict(zip(headers,[e.strip() for e in line.split(',')])) for line in lines[1:]]
self.process_api_response(type,response)

def process_api_response(self,type,response):
print response
if type["subtype"] == "channels":
for r in response:
self.queue_api("uuid_dump %s"%r.uuid,{"name":"uuid_dump"})

def onCustom(self, data):
#pprint.pprint(data)
Expand Down

0 comments on commit 0d48c7a

Please sign in to comment.