Пример #1
0
 def acceptCall(self, call):
     from shtoom.doug.leg import Leg
     log.msg("acceptCall dialog is %r" % (call.dialog), system='doug')
     calltype = call.dialog.getDirection()
     if call.cookie is None:
         cookie = self.getCookie()
     else:
         cookie = call.cookie
     self._calls[cookie] = call
     d = self._createRTP(cookie,
                         call.getLocalSIPAddress()[0], call.getSTUNState())
     if calltype == 'outbound':
         # Outbound call, trigger the callback immediately
         d.addCallback(lambda x: cookie)
     elif calltype == 'inbound':
         # Otherwise we chain callbacks
         self.initVoiceapp(cookie)
         d.addErrback(lambda x: self.rejectedCall(cookie, x))
         ad = defer.Deferred()
         inbound = Leg(cookie, call.dialog)
         inbound.incomingCall(ad)
         self._voiceapps[cookie].va_callstart(inbound)
         d.addCallback(lambda x, ad=ad: ad)
     else:
         raise ValueError("unknown call type %s" % (calltype))
     d.addErrback(self.bong)
     return d
Пример #2
0
 def acceptCall(self, call):
     from shtoom.doug.leg import Leg
     log.msg("acceptCall dialog is %r"%(call.dialog), system='doug')
     calltype = call.dialog.getDirection()
     if call.cookie is None:
         cookie = self.getCookie()
     else:
         cookie = call.cookie
     self._calls[cookie] = call
     d = self._createRTP(cookie,
                         call.getLocalSIPAddress()[0],
                         call.getSTUNState())
     if calltype == 'outbound':
         # Outbound call, trigger the callback immediately
         d.addCallback(lambda x: cookie)
     elif calltype == 'inbound':
         # Otherwise we chain callbacks
         self.initVoiceapp(cookie)
         d.addErrback(lambda x: self.rejectedCall(cookie, x))
         ad = defer.Deferred()
         inbound = Leg(cookie, call.dialog)
         inbound.incomingCall(ad)
         self._voiceapps[cookie].va_callstart(inbound)
         d.addCallback(lambda x, ad=ad: ad)
     else:
         raise ValueError, "unknown call type %s"%(calltype)
     d.addErrback(self.bong)
     return d
Пример #3
0
    def test_legCallSetup(self):
        from shtoom.sip import Dialog
        ae = self.assertEquals
        d = Dialog()
        cookie = 'NCookie'

        class A:
            res = None

            def good(self, res):
                self.res = res

            def bad(self, err):
                self.res = err

        l = Leg(cookie, d)
        a = A()
        d = defer.Deferred()
        d.addCallbacks(a.good, a.bad)
        l.incomingCall(d)
        ae(a.res, None)
        l.answerCall(voiceapp=None)
        twisted.trial.util.wait(d)
        ae(a.res, cookie)
        l.rejectCall(Exception('because'))
        twisted.trial.util.wait(d)
        ae(a.res, cookie)

        l = Leg(cookie, d)
        a = A()
        d = defer.Deferred()
        d.addCallbacks(a.good, a.bad)
        l.incomingCall(d)
        ae(a.res, None)
        # XXX should be an exception
        l.rejectCall(Exception('because'))
        twisted.trial.util.wait(d)
        # rejectCall triggers an errback, so we get
        # Failure(DefaultException(reason))
        ae(a.res.value.args, ('because', ))
Пример #4
0
    def test_legCallSetup(self):
        from shtoom.sip import Dialog
        ae = self.assertEquals
        d = Dialog()
        cookie = 'NCookie'
        class A:
            res = None
            def good(self, res):
                self.res = res
            def bad(self, err):
                self.res = err

        l = Leg(cookie, d)
        a = A()
        d = defer.Deferred()
        d.addCallbacks(a.good, a.bad)
        l.incomingCall(d)
        ae(a.res, None)
        l.answerCall(voiceapp=None)
        twisted.trial.util.wait(d)
        ae(a.res, cookie)
        l.rejectCall(Exception('because'))
        twisted.trial.util.wait(d)
        ae(a.res, cookie)

        l = Leg(cookie, d)
        a = A()
        d = defer.Deferred()
        d.addCallbacks(a.good, a.bad)
        l.incomingCall(d)
        ae(a.res, None)
        # XXX should be an exception
        l.rejectCall(Exception('because'))
        twisted.trial.util.wait(d)
        # rejectCall triggers an errback, so we get
        # Failure(DefaultException(reason))
        ae(a.res.value.args, ('because',))