drachtio / drachtio-srf

drachtio signaling resource framework
https://drachtio.org
MIT License
171 stars 60 forks source link

Sending request to self #40

Open WhiteyDude opened 5 years ago

WhiteyDude commented 5 years ago

Hi Dave,

I have a scenario where I need to programatically generate a new call. I'll likely wrap this in sinatra or similar.

I've built a quick PoC like this:

function makeGreetingCall(srf, mediaserver) {
  // Create a media endpoint
  let ep;
  mediaserver.createEndpoint()
  .then((endpoint) => {
    ep = endpoint;
    return srf.createUAC('sip:100@127.0.0.1', {
      localSdp: endpoint.local.sdp,
      headers: {
        'X-Call-Type': 'Test'
      }
    });
  })
  .then((dialog) => {
...

And called it directly from the console. However I get thrown:

(node:26498) UnhandledPromiseRejectionWarning: can not send request to myself

I'm assuming this is something built into drachtio server to ensure we don't get caught in a loop scenario. What would you recommend is the best way to "cold initiate" a call like this?

Thanks!

davehorton commented 5 years ago

Yes the issue is you are trying to send to sip:100@127.0.0.1, which looks like a loop to the drachtio server.

The code you have is basically fine, and would work if you were sending for instance out a sip trunk. Is there a reason you want to send the INVITE in a loop?

WhiteyDude commented 5 years ago

Thanks Dave, that's what I suspected!

Drachtio is acting as a PBX and a UAC in this scenario. We have a trunk on the edge to take inbound and outbound calls.

In this instance, I want drachtio to initiate and INVITE out to the trunk. However I wish to trigger this invite from an external application.

So the first drachtio application (the UAC, example above) sends an INVITE to drachtio-server. There is a second drachtio application listening for INVITE requests. This creates a media endpoint and creates a second INVITE out via the trunk. Once answered, the two endpoints are bridged and playback, user input etc is done on the second endpoint.

I hope I've explained this right. The basic flow is:

Exposed web API -> Drachtio UAC instance -> Drachtio Server -> Drachtio "PBX" instance -> Trunk