Example #1
0
 def _createRequest(self, text):
     m = self._ua.createRequest('MESSAGE')
     m.Contact = rfc3261.Header(str(self._stack.uri), 'Contact')
     m.Contact.value.uri.user = self.options.user
     if self.options.user_agent:
         m['User-Agent'] = rfc3261.Header(self.options.user_agent, 'User-Agent')
     if self.options.subject:
         m['Subject'] = rfc3261.Header(self.options.subject, 'Subject')
     m['Content-Type'] = rfc3261.Header('text/plain', 'Content-Type')
     m.body = self.options.send
     
     return m
Example #2
0
 def __init__(self, app, stack):
     UA.__init__(self, app, stack)
     remoteParty = self.options.to
     remoteTarget = self.options.uri
     self._createClient(self.localParty, remoteParty, remoteTarget)
     if self.options.proxy:
         self.proxy = rfc2396.URI('%s:%s'%(self.scheme, self.options.proxy, '' if self.options.strict_route else ';lr'))
         self._ua.routeSet = [rfc3261.Header('<%s>'%(str(self.proxy),), 'Route')]
     self._ua.sendRequest(self._createRequest(self.options.send))
Example #3
0
    def sendInvite(self):
        remoteParty = self.options.to
        remoteTarget = self.options.uri
        self._createClient(self.localParty, remoteParty, remoteTarget)
        if self.options.proxy:
            self.proxy = rfc2396.URI('%s:%s%s'%(self.scheme, self.options.proxy, '' if self.options.strict_route else ';lr'))
            self._ua.routeSet = [rfc3261.Header('<%s>'%(str(self.proxy),), 'Route')]
            
        m = self._ua.createRequest('INVITE')
        m.Contact = rfc3261.Header(str(self._stack.uri), 'Contact')
        m.Contact.value.uri.user = self.options.user
        if self.options.user_agent:
            m['User-Agent'] = rfc3261.Header(self.options.user_agent, 'User-Agent')
        if self.options.subject:
            m['Subject'] = rfc3261.Header(self.options.subject, 'Subject')

        if self.options.has_sdp:
            self.media = voip.MediaSession(app=self, streams=self._audio, listen_ip=self.options.int_ip, NetworkClass=rfc3550.gevent_Network) # create local media session
            m['Content-Type'] = rfc3261.Header('application/sdp', 'Content-Type')
            m.body = str(self.media.mysdp)
            
        self.state = 'inviting'
        self._ua.sendRequest(m)
Example #4
0
 def _autoRespond(self):
     self._gen = None
     if self.options.auto_respond >= 200 and self.options.auto_respond < 300:
         logger.info('accepting incoming call')
         self.state = 'accepted'
         m = self._ua.createResponse(200, 'OK')
         m['Content-Type'] = rfc3261.Header('application/sdp', 'Content-Type')
         m.body = str(self.media.mysdp)
         if self.options.auto_terminate_after:
             self._gen = gevent.spawn_later(self.options.auto_terminate_after, self._autoTerminate)
     else:
         logger.info('rejecting incoming call with code %r', self.options.auto_respond)
         self.state = 'idle'
         m = self._ua.createResponse(self.options.auto_respond, 'Decline')
     self._ua.sendResponse(m)
     if self.options.auto_respond >= 300:
         self.close()
Example #5
0
 def _createRequest(self, register=True):
     m = self._ua.createRequest('REGISTER')
     m.Contact = rfc3261.Header(str(self._stack.uri), 'Contact')
     m.Contact.value.uri.user = self.options.user
     m.Expires = rfc3261.Header(str(self.options.register_interval if register else 0), 'Expires')
     return m