add some tests,examples to fshelper, clean up the reconnect error message in fseventlistener
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5957 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7c93a4e4eb
commit
1e06f16717
|
@ -213,13 +213,17 @@ class FreeswitchEventListenerFactory(ClientFactory):
|
||||||
self.protocol = None
|
self.protocol = None
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
print "clientConnectionFailed! conn=%s, reason=%s" % (connector,
|
|
||||||
reason)
|
|
||||||
#self.protocol = None
|
|
||||||
if self.num_attempts < 100:
|
if self.num_attempts < 100:
|
||||||
self.num_attempts += 1
|
self.num_attempts += 1
|
||||||
|
print "Connection refused, retrying attempt #%s in 5 seconds" % \
|
||||||
|
(self.num_attempts)
|
||||||
return reactor.callLater(5, self.connect)
|
return reactor.callLater(5, self.connect)
|
||||||
else:
|
else:
|
||||||
|
print "clientConnectionFailed! conn=%s, reason=%s" % (connector,
|
||||||
|
reason)
|
||||||
|
print ("Retry attempts exhausted, total attempts: %s" %
|
||||||
|
self.num_attempts)
|
||||||
deferred2callback = self.connection_deferred
|
deferred2callback = self.connection_deferred
|
||||||
deferred2callback.errback(reason)
|
deferred2callback.errback(reason)
|
||||||
|
|
||||||
|
|
|
@ -321,6 +321,10 @@ class FsHelperTest:
|
||||||
|
|
||||||
def test_dialconf(self):
|
def test_dialconf(self):
|
||||||
|
|
||||||
|
# the following parties will be dialed out from the conference
|
||||||
|
# called "freeswitch" on the local freeswitch instance.
|
||||||
|
# one party is actually another conference, just to make
|
||||||
|
# the example more confusing.
|
||||||
people2dial = [{'name':'freeswitch',
|
people2dial = [{'name':'freeswitch',
|
||||||
'number':'888@conference.freeswitch.org'},
|
'number':'888@conference.freeswitch.org'},
|
||||||
{'name':'mouselike',
|
{'name':'mouselike',
|
||||||
|
@ -333,7 +337,6 @@ class FsHelperTest:
|
||||||
d.addErrback(failed)
|
d.addErrback(failed)
|
||||||
def worked(*args):
|
def worked(*args):
|
||||||
print "Worked! Dialed user result: %s" % str(args)
|
print "Worked! Dialed user result: %s" % str(args)
|
||||||
#reactor.stop()
|
|
||||||
d.addCallback(worked)
|
d.addCallback(worked)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -366,7 +369,9 @@ class FsHelperTest:
|
||||||
|
|
||||||
def test1():
|
def test1():
|
||||||
kick_everyone = False
|
kick_everyone = False
|
||||||
fshelper = FsHelper("mydomain.com")
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
fsht = FsHelperTest(fshelper)
|
fsht = FsHelperTest(fshelper)
|
||||||
fsht.test_dialconf()
|
fsht.test_dialconf()
|
||||||
d = fsht.test_listconf()
|
d = fsht.test_listconf()
|
||||||
|
@ -391,10 +396,113 @@ def test1():
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def test2():
|
def test2():
|
||||||
fshelper = FsHelper("mydomain.com")
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
fshelper.sofia_profile_restart("mydomain.com")
|
fshelper.sofia_profile_restart("mydomain.com")
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
def test3():
|
||||||
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
|
print "Calling originate.."
|
||||||
|
party2dial="sofia/foo/600@192.168.1.202:5080"
|
||||||
|
d = fshelper.originate(party2dial=party2dial,
|
||||||
|
dest_ext_app="101",
|
||||||
|
bgapi=True)
|
||||||
|
|
||||||
|
def worked(result):
|
||||||
|
print "Originate succeeded: %s" % result
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
|
def failed(failure):
|
||||||
|
print "failed: %s" % str(failure)
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
|
d.addCallback(worked)
|
||||||
|
d.addErrback(failed)
|
||||||
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
|
def test4():
|
||||||
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
|
|
||||||
|
def worked(result):
|
||||||
|
print "Originate succeeded: %s" % result
|
||||||
|
#reactor.stop()
|
||||||
|
|
||||||
|
def failed(failure):
|
||||||
|
print "failed: %s" % str(failure)
|
||||||
|
#reactor.stop()
|
||||||
|
|
||||||
|
|
||||||
|
dest_ext_app = "101"
|
||||||
|
party2dial="sofia/foo/600@192.168.1.202:5080"
|
||||||
|
d = fshelper.originate(party2dial=party2dial,
|
||||||
|
dest_ext_app=dest_ext_app,
|
||||||
|
bgapi=True)
|
||||||
|
d.addCallback(worked)
|
||||||
|
d.addErrback(failed)
|
||||||
|
party2dial="sofia/foo/someone@bar.com"
|
||||||
|
d2 = fshelper.originate(party2dial=party2dial,
|
||||||
|
dest_ext_app=dest_ext_app,
|
||||||
|
bgapi=True)
|
||||||
|
|
||||||
|
d2.addCallback(worked)
|
||||||
|
d2.addErrback(failed)
|
||||||
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
|
def test5():
|
||||||
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
|
|
||||||
|
def worked(result):
|
||||||
|
print "Originate succeeded: %s" % result
|
||||||
|
#reactor.stop()
|
||||||
|
|
||||||
|
def failed(failure):
|
||||||
|
print "failed: %s" % str(failure)
|
||||||
|
#reactor.stop()
|
||||||
|
|
||||||
|
for i in xrange(20):
|
||||||
|
|
||||||
|
party2dial="sofia/foo/600@192.168.1.202:5080"
|
||||||
|
d = fshelper.originate(party2dial=party2dial,
|
||||||
|
dest_ext_app="700",
|
||||||
|
bgapi=True)
|
||||||
|
d.addCallback(worked)
|
||||||
|
d.addErrback(failed)
|
||||||
|
|
||||||
|
reactor.run()
|
||||||
|
|
||||||
|
def test6():
|
||||||
|
"""
|
||||||
|
show channels for a given sofia profile
|
||||||
|
"""
|
||||||
|
fshelper = FsHelper(host="127.0.0.1",
|
||||||
|
passwd="ClueCon",
|
||||||
|
port=8021)
|
||||||
|
from wikipbx import channelsutil
|
||||||
|
def show_chanels(raw_xml):
|
||||||
|
print raw_xml
|
||||||
|
|
||||||
|
def failure(failure):
|
||||||
|
print failure
|
||||||
|
|
||||||
|
d = fshelper.showchannels(bgapi=False)
|
||||||
|
d.addCallback(show_chanels)
|
||||||
|
d.addErrback(failure)
|
||||||
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
#test1()
|
#test1()
|
||||||
test2()
|
#test2()
|
||||||
|
#test3()
|
||||||
|
test4()
|
||||||
|
#test5()
|
||||||
|
|
Loading…
Reference in New Issue