sipsorcery icon indicating copy to clipboard operation
sipsorcery copied to clipboard

Problem with subscribing to notifications using SIPNotifierClient.

Open BratProgrammer opened this issue 2 years ago • 3 comments

Hello! I am a beginner developer, so please do not judge strictly, if something is unclear, I will add more information.

I need to receive notifications from accounts on a working SIP server. I connect to accounts using a login and password. I need to pull out the phone numbers of the callers from incoming calls.

To get notification text I use the following code, provided in your documentation:

        var userName = "example user name"
        var server = "exemple server adress"   
     
        var mwiURI = SIPURI.ParseSIPURIRelaxed($"{userName}@{server}");
        int expiry = 120;

        SIPNotifierClient mwiSubscriber = new SIPNotifierClient(sipTransport, null, SIPEventPackagesEnum.MessageSummary, mwiURI, userName, null, password, expiry, null);
        mwiSubscriber.SubscriptionFailed += (uri, failureStatus, errorMessage) => Console.WriteLine($"MWI failed for {uri}, {errorMessage}");
        mwiSubscriber.SubscriptionSuccessful += (uri) => Console.WriteLine($"MWI subscription successful for {uri}");
        mwiSubscriber.NotificationReceived += (evt, msg) => Console.WriteLine($"MWI notification, type {evt}, message {msg}.");

        mwiSubscriber.Start();

But he subscription fails with error code:

        MWI failed for sip:userName@server, Subscription request to sip:userName@server failed with TimedOut.

What could be causing this? And how can this problem be fixed?

Thanks a lot in advance!

Alex.

BratProgrammer avatar Mar 12 '22 10:03 BratProgrammer

Not all SIP servers suport SIP events, or they can be turned off, so the first thing to check is that they are available.

Assuming they are available the next caveat is that the sipsorcery library does not hav great support for SIP events. I've done bits here and there with them over the years but they've never been a highly requested featuer. The main use has been for vociemail (or message waiting indication) notifications, which is what the example you've posted is attempting to to subscribe for.

You'll need to use the SIPEventPackagesEnum.Dialog events package to get notifications about call events. And while what you're describing is a common use case, being able to get notifications about all the calls happening on the server, it's not likely to be enabled by default as it's a big security minefield.

Before you even get to that point you need to work out why you can't connect to your SIP server. The Timed Out error indicates you didn't get any kind of response which could mean you have the server address wrong or that your request was ignored or blocked on the server.

I'd suggest trying to use the SIPUserAgent to place a call as the first step. Even if it fails the error response will at least let you know you were able to connect to the server.

sipsorcery avatar Mar 13 '22 10:03 sipsorcery

Everything works for me with SIPRegistrationUserAgent() registration passes, but no listeners can be attached to the received object. And passing the result to a regular SIPUserAgent also fails.

The question arises How to connect a specific sip account to SIPUserAgent using login and password? In the class, I did not find a function that would implement this.

And why is SIPRegistrationUserAgent needed if it cannot be passed to the SIPUserAgent object.

I just don't understand something.)

BratProgrammer avatar Mar 15 '22 20:03 BratProgrammer

How to connect a specific sip account to SIPUserAgent using login and password? In the class, I did not find a function that would implement this.

You typically set the username and password when you place a call. A single SIPUserAgent instance can thus be used to place multiple calls to different SIP servers using different credentials.

If you really do want to tie it down to a single set of credentials you can set the ISIPAccount answerSipAccount parameter on the constructor.

And why is SIPRegistrationUserAgent needed if it cannot be passed to the SIPUserAgent object.

They are completely separate operations, both in this library and in the SIP protocol. You don't need to register to make a call (unless the provide is enforcing a custom biz rule).

sipsorcery avatar Mar 15 '22 21:03 sipsorcery