sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.42k stars 431 forks source link

Question regarding SIPRegistrationUserAgent #1044

Closed mnik17 closed 8 months ago

mnik17 commented 8 months ago

Hello,

I have a question regarding the registration method and how to use this afterwards.

I have a SIP server (FreePBX) running locally. Additionally, I have two MicroSIP softphones, which are connected to the server. Finally, I am developing an application using sipsorcery. My goal is to be able to register my application with the SIP server (where I have created an extension) and then place a call. The thing is, when I place the call, in the softphone it looks like the call is coming from an unknown source. I want it to display the corresponding number of the extension (user) I have registered the application with.

For example: Softphone registered as 1000. Sipsorcery application registered as 2000. Application calls the Softphone. Softphone displays: 2000 is calling you.

Current Behaviour: Softphone registered as 1000. Sipsorcery application registered as 2000. Application calls the Softphone. Softphone displays: "unregistered" is calling you.

This behaviour works with the two MicroSIP clients, so the server is working as expected.

In the documentation , I saw that I should use SIPRegistrationUserAgent to do the registration and SIPUserAgent to place the call.

Currently I have the following code (credentials and IPs are modified):

    private SIPRegistrationUserAgent CreateRegistrationSIPUserAgent()
    {
      return new SIPRegistrationUserAgent(_sipTransport, "username", "password", "1.1.1.1", 300);
    }

and the constructor of the class:

    public SipClient(IAudioEncoder audioEncoder, ISettingsManager settingsManager, MediaEndpointType mediaEndpointType, string deviceID, Guid streamID)
    {
      _sipSettingsManager = new SipSettingsManager(settingsManager, deviceID, streamID, mediaEndpointType);
      _sipTransport = CreateTransport();
      _mediaEndPoint = CreateMediaEndPoint(audioEncoder, mediaEndpointType);
      _voipMediaSession = CreateVoIPMediaSession();

      _sipRegistrationUserAgent = CreateRegistrationSIPUserAgent();

      _sipRegistrationUserAgent.RegistrationFailed += _sipRegistrationUserAgent_RegistrationFailed;
      _sipRegistrationUserAgent.RegistrationTemporaryFailure += _sipRegistrationUserAgent_RegistrationTemporaryFailure;
      _sipRegistrationUserAgent.RegistrationRemoved += _sipRegistrationUserAgent_RegistrationRemoved;
      _sipRegistrationUserAgent.RegistrationSuccessful += _sipRegistrationUserAgent_RegistrationSuccessful;

      _sipRegistrationUserAgent.Start();

      _sipUserAgent = CreateSIPUserAgent();
    }

However, in the Asterisk logs, I cannot see any attemt at registering and I'm not sure what I am doing wrong. Is the documentation up to date?

Additionally, I cannot understand how to then "tell" the SIPUserAgent to use the result of the registration. Or is there even such a need?

sipsorcery commented 8 months ago

Additionally, I cannot understand how to then "tell" the SIPUserAgent to use the result of the registration. Or is there even such a need?

You can't really do that. In SIP, REGISTER and INVITE requests are separate things and aren't intriincally related. A SIP server can do things like only accept invite requests from the same socket a valid registration exists on but that's up to the server and not part of the core standard.

To track down why your registration is not working the easiest way is to turn on full SIP traces. If you get a response from your server it should help determine why the registration failed. If you don't get a response your request probably didn't get to the server. Here is an example of how to turn on full SIP traces.

mnik17 commented 8 months ago

Thank you for your fast reply.

I was under the impression that REGISTER is supposed to provide information (for example some kind of identifier) to the rest of the requests/responses. Anyway, I found that I just had to provide the authentication credentials to the Call function of the SIPUserAgent and it worked fine. I checked in Wireshark and apparently the registration itself was successful as well. So it seems this is solved.

So I will close it here, but I have just one more question: when creating the SIPUserAgent, you can provide an ISIPAccount parameter. What is this used for? I tried passing the credentials there without having them in the Call function, but to no avail.