[SIP Beyond VoIP] Problem with SIP Simple SDK notification handling

Dan Pascu dan at ag-projects.com
Thu Mar 14 16:05:24 CET 2019


On 14 Mar 2019, at 13:47, Alexey Nikitenko wrote:

> I try to handle notifications in my simple sip application. I can handle many notifications connected with session, application end engine, but I can't handle notifications, connected with incoming and outgoing low-level requests.

By default no request is handled as a low level request. In order to have some requests handled as low level ones you need to indicate that by passing incoming_requests=[list_of_method_names] as an argument to Engine.start

If you use SIPApplication, it will start the engine without passing any incoming_requests. In that case you need to call add_incoming_request on the Engine after you got SIPApplicationDidStart to add them on the fly at runtime.

Keep in mind this only works for single-transaction out-of-dialog requests. In dialog requests will always be handled in dialog and will not generate an IncomingRequest object even if the method matches the ones in engine.incoming_requests

In this particular example you'll have to add

self.engine.add_incoming_request('INFO')

in the beginning of _NH_SIPApplicationDidStart

Check the documentation here:

http://old.sipsimpleclient.org/projects/sipsimpleclient/wiki/SipCoreApiDocumentation#IncomingRequest

> 
> There is incoming INFO messages is session, I can see in Wireshark, but it not handled with _NH_SIPIncomingRequestGotRequest. 
> 
> Full listing of class: 
> 
> class SimpleCallApplication(SIPApplication):
> 
>     def __init__(self, number, password, server_ip, server_port, logger):
>         SIPApplication.__init__(self)
>         self.logger = logger
>         self.ended = Event()
>         self.session = None
>         self.uri = None
>         self.player = None
>         self._wave_file = None
>         self.number = number
>         self.password = password
>         self.domain = '{}:{}'.format(server_ip, server_port)
>         self.number_with_domain = '{}@{}'.format(number, self.domain)
>         self.notification_center = NotificationCenter()
>         self.notification_center.add_observer(self)
> 
>     def call(self, uri, filename):
>         self.uri = uri
>         self._wave_file = filename
>         self.start(FileStorage('config'))
> 
>     @run_in_green_thread
>     def _NH_SIPApplicationDidStart(self, notification):
> 
>         acc = None
>         try:
>             acc = AccountManager().get_account(self.number_with_domain)
>         except KeyError:
>             pass
>         if acc is not None:
>             self.account = acc
>         else:
>             self.account = Account(self.number_with_domain)
> 
>         self.account.__setstate__({'password': self.password})
>         self.account.enabled = True
>         self.account.save()
> 
>         to = ToHeader(SIPURI.parse(self.uri))
>         settings = SIPSimpleSettings()
>         settings.audio.input_device = None
>         settings.audio.output_device = None
>         settings.save()
>         self.player = WavePlayer(SIPApplication.voice_audio_mixer, self._wave_file, loop_count=1)
>         try:
>             lookup = DNSLookup()
>             routes = lookup.lookup_sip_proxy(to.uri, ['udp']).wait()
>         except DNSLookupError, e:
>             print 'DNS lookup failed: %s' % str(e)
>         else:
>             self.session = Session(self.account)
>             stream = AudioStream()
> 
>             self.session.connect(to, routes, [stream])
> 
>     def _NH_SIPSessionGotRingIndication(self, notification):
>         print 'Ringing!'
>         session = notification.sender
>         session.send(struct.pack('>BBBB', 1, 2, 3, 4))
> 
>     def _NH_SIPSessionDidStart(self, notification):
>         print 'Session started!'
>         session = notification.sender
>         audio_stream = session.streams[0]
>         audio_stream.bridge.add(self.player)
>         self.player.play()
> 
>     def _NH_SIPSessionDidFail(self, notification):
>         print 'Failed to connect'
>         self.stop()
> 
>     def _NH_SIPSessionWillEnd(self, notification):
>         session = notification.sender
>         audio_stream = session.streams[0]
>         self.player.stop()
>         audio_stream.bridge.remove(self.player)
> 
>     def _NH_SIPSessionDidEnd(self, notification):
>         print 'Session ended'
>         self.stop()
> 
>     def _NH_SIPApplicationDidEnd(self, notification):
>         self.ended.set()
> 
>     def _NH_AudioStreamGotDTMF(self, notification):
>         print 'DTMF detected! {}'.format(notification.data.__dict__)
> 
>     def _NH_SIPIncomingRequestGotRequest(self, notification):
>         print 'Incoming request'
> 
>     def _NH_SIPInvitationGotSDPUpdate(self, notification):
>         print 'SDP update: {}'.format(notification.sender.state)
> 
>     def _NH_SIPRequestDidEnd(self, notification):
>         print 'request ended'
> 
>     def _NH_SIPEngineLog(self, notification):
>         print 'got a log!' 
> _______________________________________________
> SIPBeyondVoIP mailing list
> SIPBeyondVoIP at lists.ag-projects.com
> http://lists.ag-projects.com/mailman/listinfo/sipbeyondvoip


--
Dan






More information about the SIPBeyondVoIP mailing list