ladendirekt / pjsip4net

A wrapper library exposing the pjsip library to the .NET world in a OO-friendly way.
71 stars 42 forks source link

Unable to dial "short codes" #103

Open rndthoughts opened 5 years ago

rndthoughts commented 5 years ago

Describe the bug

My SIP server uses shortcodes to activate night service, pickup calls ringing elsewhere but if i attempt to call "MakeCall" with the short code (e.g. "**20") I get - "Choice stack is empty. Unable to fallback to another state". I am assuming it's because the asterisks are the problem, but how do i get the short code transmitted?

If it's because i need to send Dtmf codes, how do I open the line without making a call to a specific number so that they can be sent?

To Reproduce Steps to reproduce the behavior:

_userAgent.CallManager.MakeCall(x => x.To("**20").At(_serverName).Through("5060").From(_userAgent.AccountManager.Accounts.First()).Call());

Expected behavior Short code executes command on server and user either hears response read back (e.g. "Night mode activated" or call is transferred.

Environment (please complete the following information):

App configuration (please complete the following information):

<sipua srtp="Disabled" secureSignaling="0" logMessages="true" logLevel="5" traceAndDebug="false" autoAnswer="false" autoRecording="false" autoConference="false" maxCalls="5">
    <sipTransport type="udp" Port="5080" />
    <networkSettings natInSDP="true" forceLooseRoute="false">
      <turn enabled="false" server="" type="udp" userName="" password="" realm="" />
      <ice enabled="false" noRTCP="false" />
    </networkSettings>
    <media isVADEnabled="true" />
  </sipua>
siniypin commented 5 years ago

Hi Steve,

thank you for submitting this issue. I guess the SIP parser I wrote doesn't support SIP BNF grammar at full. In particular, it disregards a mark definition that can be used in a username: https://tools.ietf.org/html/rfc3261#section-25.1.
I'll have a look at it, but you can also check to see, if there is an easy fix to it (cause I can not guarantee that I'll have time to do so soon) here: https://github.com/siniypin/pjsip4net/blob/master/pjsip4net.Core/Utils/SipUriParser.cs#L35

In case you fix it before I do, kindly send a pull request back.

siniypin commented 5 years ago

This line needs to be changed: https://github.com/siniypin/pjsip4net/blob/master/pjsip4net.Core/Utils/SipUriParser.cs#L164

rndthoughts commented 5 years ago

Thanks - I'll see what I can do!

rndthoughts commented 5 years ago

Would it be acceptable if I just extend _domainSpecialCharacters to include the other marks on the line below?

https://github.com/siniypin/pjsip4net/blob/master/pjsip4net.Core/Utils/SipUriParser.cs#L44

rndthoughts commented 5 years ago

OK - that didn't work. If i've got this correct, I think when the state machine transitions from //column to extension it's only accepting numbers and needs to accept numbers and _domainSpecialCharacters

https://github.com/siniypin/pjsip4net/blob/master/pjsip4net.Core/Utils/SipUriParser.cs#L205

siniypin commented 5 years ago

That too, you're right!

siniypin commented 5 years ago

And would you mind adding a unit test for this change here: https://github.com/siniypin/pjsip4net/blob/master/Tests/Unit/pjsip4net.Tests/given_a_sip_uri_parser.cs?

siniypin commented 5 years ago

You need to run build.bat https://github.com/siniypin/pjsip4net#examples

rndthoughts commented 5 years ago

I've implemented the code changes on my local version but I think rather than "dialling" them as a number we need to "open" an empty line and send them as Dtmf tones. I can only do this by calling a destination but in this case I need to just send them to directly to the server. How do I get a "dial tone" when I don't have a destination number to call?

(What I'm trying to do is simulate picking up the handset, hearing the dial tone and typing **20)

siniypin commented 5 years ago

Hm, I suspect that that will not work in general. In a dialplan on your server you'd have to define a route for such calls, cause it has to know that you're going to send shortcodes as DTMFs to it upfront. If that is what happening there, then you have to have an extension to call to.

Maybe check once again what exactly happens on your server when it receives a call with an extension with a shortcode.

Did dialing a number with ** in front not work for you?

rndthoughts commented 5 years ago

Not currently - I dialed the number and I move instantly from "Calling" to "Disconnected". If it worked, I would assume the server would have pushed the call into one of my lines which I could subsequently pickup or it would have connected the call to the open line?

siniypin commented 5 years ago

Have you checked your server logs? BTW, would you mind submitting a Pull Request back anyway?

rndthoughts commented 5 years ago

I'll take a look at the logs - no problem with the PR, I'll do it as soon as i can.

siniypin commented 5 years ago

ping! friendly reminder about a PR