drachtio / drachtio-srf

drachtio signaling resource framework
https://drachtio.org
MIT License
168 stars 59 forks source link

Can I get the headers of received CANCEL? #152

Closed calvet27 closed 1 year ago

calvet27 commented 1 year ago

Hi,

Can I get the headsers of received CANCEL? From SRF, We can listen the emitted event for canceled inbound request.

req.on('cancel', () => {
  // TODO something.
});

But we cannot get the headers of CANCEL from that way. It is required to get some causes of firing CANCEL such as Reason header.

CANCEL sip:68050961695239@...:5060 SIP/2.0 From: "Jess Portugal"sip:*1139@...;tag=2aca825f-14fb3c5-1f1d3e-b89f53e0-45090a0a-13c4-759 To: sip:68050961695239@... Call-ID: 2dca6bc8-127d3ab1-1f1d3e-afd33848-45090a0a-13c4-759 CSeq: 1 CANCEL Via: SIP/2.0/UDP ...:5060;rport;branch=z9hG4bK-28d9f76a-1f1d3e-798a3bae-bb733988 Max-Forwards: 70 Supported: 100rel,timer,replaces Reason: SIP ;cause=200 ;text="Call completed elsewhere User-Agent: ... Content-Length: 0

Please let me know how to get the headers.

JSimoni42 commented 1 year ago

It looks like this is where the CANCEL event is emitted: https://github.com/drachtio/drachtio-srf/blob/97d8317e0670b153f9197c591d448cc0ff461323/lib/drachtio-agent.js#L593. You can get the headers from the SipMessage passed to the event listener

calvet27 commented 1 year ago

@JSimoni42 ,

Thank you for your answer. But I already tried to do that,

req.on('cancel', async (cancelReq) => {
...
});

But I think cancelReq.headers is not define. Actually, I double checked that cancelReq is undefined in that case. Is it a req object from CANCEL?

davehorton commented 1 year ago

@xquanluu can you comment? I think we just dealt with this requirement recently

xquanluu commented 1 year ago

Take a look at this example:

expectCancel(uri) {
    this.srf.invite((req, res) => {
      req.on('cancel', (cancelReq) => {
        const headers = cancelReq.headers;
        console.log(headers);
      })
      this.srf.createB2BUA(req, res, uri)
        .then(({uas, uac}) => {
          throw new Error('unexpected dialog success - expected CANCEL from uac');
        })
        .catch((err) => {
          debug(`expectCancel: expected a final 487, got ${err}`);
          if (err.status === 487) return;
          throw err;
        });
    });
  }

Output:

{ via: 'SIP/2.0/UDP 172.29.0.2:5060;branch=z9hG4bK-1-1-0;rport=5060', from: 'sipp sip:sipp@172.29.0.2:5060;tag=1SIPpTag001', to: 'service sip:service@172.29.0.10:5060', 'call-id': '1-1@172.29.0.2-4', cseq: '1 CANCEL', reason: 'SIP;cause=200;text="Call completed elsewhere"', 'content-length': '0' }

xquanluu commented 1 year ago

Not sure is what you are looking for? @calvet27

xquanluu commented 1 year ago

You may want to play with this testcase: https://github.com/drachtio/drachtio-srf/blob/main/test/scripts/b2b.js#L24

calvet27 commented 1 year ago

@xquanluu

Can you give me version information about supporting cancelReq?

xquanluu commented 1 year ago

Can you use drachtio-srf: 4.5.28 drachtio-server: latest

calvet27 commented 1 year ago

@xquanluu

I use 4.4.18. After updating to 4.5.28, I will let you know the results.

calvet27 commented 1 year ago

@xquanluu

Can I get you tag information of the latest drachtio? Is it same with 0.8.22?

xquanluu commented 1 year ago

Yes it's correct.

calvet27 commented 1 year ago

@xquanluu But it looks different. 0.8.22 does not give me cancel object but latest give me. I updated drachtio-srf to 4.5.26. Any advice?

xquanluu commented 1 year ago

Can you tell me how you build and deployed drachtio? via docker?

calvet27 commented 1 year ago

@xquanluu Yes. I installed Drachtio SIP Server via Docker. The image is from Docker hub. Drachtio

I had some tests to compare 0.8.22 and latest and then I noticed that the only the latest one worked properly. cancelReq is undefined with 0.8.22 and Drachtio SRF 4.5.26 was used for both cases.

xquanluu commented 1 year ago

hmm. Strange but yes please use latest tag.,

0.8.2 was released 2 months ago, from that time up to now there is no official release yet.

calvet27 commented 1 year ago

@xquanluu

I'm sorry to make you confused. Now 0.8.22 works properly. Close this issue! Thank you for your support!

xquanluu commented 1 year ago

Closing this issue.