Unable to handle NOTIFY using onNotify function of Subscriber

662 views
Skip to first unread message

anshk...@gmail.com

unread,
May 3, 2021, 2:49:06 PM5/3/21
to SIP.js
Hello Team,

Somehow we've managed to make it work with FreeSWITCH about sending NOTIFY packets along with conference details. When I'm sending SUBSCRIBE from SIP.js, server is accepting it and sending NOTIFY as well but somehow I'm unable to capture it onNotify delegate method of Subscriber.

Find below snippets which I've used to initiate instance of Subscriber class :
const _confUUID = RANDOM_UUID;
const targetURI = new URI("sip", "conf+"+_confUUID, 'sip.example.com');
const eventType = "conference";
const subscriber = new Subscriber(sharedInstance.userAgent, targetURI, eventType, {extraHeaders : ['Accept: application/conference-info+xml']});

subscriber.delegate = {
onNotify: (notification) => {
console.log("onNotify function")
console.log(notification)
}
};

subscriber.stateChange.addListener((newState) => {
console.log("StateChange Event Listener for "+ newState);
});

subscriber.subscribe();


Please find below SUBSCRIBE and NOTIFY Packets :

Via: SIP/2.0/WSS ugpp1spgs9lp.invalid;branch=z9hG4bK7343839
From: "gkatriy" <sip:gka...@sip.example.com>;tag=9fdp5tud4q
CSeq: 1 SUBSCRIBE
Call-ID: v5b9d54t6q9jktfl9fba
Max-Forwards: 70
Allow: ACK,BYE,CANCEL,INFO,INVITE,MESSAGE,NOTIFY,OPTIONS,PRACK,REFER,REGISTER,SUBSCRIBE
Event: conference
Expires: 3600
Contact: <sip:cc6m...@ugpp1spgs9lp.invalid;transport=ws>
Supported: outbound, 100rel, replaces
User-Agent: SIP.js
Content-Length: 0


NOTIFY sip:cc6m...@113.193.207.243:43558;transport=ws SIP/2.0
Via: SIP/2.0/WSS X.X.X.X:10443;branch=z9hG4bKbf43.e3d1fcd6.0
Max-Forwards: 69
From: "gkatriy" <sip:gka...@sip.example.com>;tag=9fdp5tud4q
Call-ID: v5b9d54t6q9jktfl9fba
CSeq: 35479674 NOTIFY
Contact: <sip:X.X.X.X:10443;transport=wss;thinfo=VG9PbzAdIFs+PDAwIwAlHTEhYmRmQWNebUR+UGBjblpgV3ZhUBQ3I25eZ11tR2FPZ2N6W2RVdURmUQ-->
User-Agent: RingRX
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, outbound, path, replaces
Event: conference
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Subscription-State: active
Content-Type: application/conference-info+xml
Content-Length: 2152

<?xml version="1.0"?>
<conference-info version="7" state="full" xmlns="urn:ietf:params:xml:ns:conference-info" entity="sip:conf-66098324-9f2f-4...@sip.example.com">
  <conference-description>
    <display-text>FreeSWITCH Conference</display-text>
    <conf-uris>
      <entry>
      </entry>
    </conf-uris>
  </conference-description>
  <conference-state>
    <user-count>3</user-count>
    <active>true</active>
  </conference-state>
  <users>
    <user state="full" entity="sip:t34r...@sip.example.com">
      <display-text>Outbound Call</display-text>
      <endpoint entity="sip:t34r...@sip.example.com">
        <display-text>Outbound Call</display-text>
        <status>connected</status>
        <joining-info>
          <when>2021-05-03T18:35:27+00:00</when>
        </joining-info>
        <media id="11a">
          <type>audio</type>
          <src-id>815064998</src-id>
          <status>sendrecv</status>
        </media>
      </endpoint>
    </user>
    <user state="full" entity="sip:t34r...@sip.example.com">
      <display-text>Outbound Call</display-text>
      <endpoint entity="sip:t34r...@sip.example.com">
        <display-text>Outbound Call</display-text>
        <status>connected</status>
        <joining-info>
          <when>2021-05-03T18:35:27+00:00</when>
        </joining-info>
        <media id="10a">
          <type>audio</type>
          <src-id>1553342490</src-id>
          <status>sendrecv</status>
        </media>
      </endpoint>
    </user>
    <user state="full" entity="sip:gka...@sip.example.com">
      <display-text>gkatriy</display-text>
      <endpoint entity="sip:gka...@sip.example.com">
        <display-text>gkatriy</display-text>
        <status>connected</status>
        <joining-info>
          <when>2021-05-03T18:35:27+00:00</when>
        </joining-info>
        <media id="9a">
          <type>audio</type>
          <src-id>614663605</src-id>
          <status>sendrecv</status>
        </media>
      </endpoint>
    </user>
  </users>
</conference-info>


SIP.js is sending SIP/2.0 481 Call/Transaction Does Not Exist in response of NOTIFY received. 

[Tue May 04 2021 24:06:04.834]  WARN     Tue May 04 2021 00:06:04 GMT+0530 (IST) | sip.user-agent-client | Timer N expired for SUBSCRIBE user agent client. Timed out waiting for NOTIFY.

[Tue May 04 2021 24:06:04.851]  LOG      Tue May 04 2021 00:06:04 GMT+0530 (IST) | sip.Subscription | Subscription undefined transitioned to Terminated

[Tue May 04 2021 24:06:04.853]  LOG      StateChange Event Listener for Terminated

[Tue May 04 2021 24:06:04.857]  LOG      Tue May 04 2021 00:06:04 GMT+0530 (IST) | sip.Subscriber | Subscription v5b9d54t6q9jktfl9fba9fdp5tud4qconference in state Terminated is being disposed

Currently, I'm using SIP.js 0.17.x. Will it make any difference to upgrade to latest version? Is there any specific changes for this?

Can anyone help me with this?


Slavik Bialik

unread,
May 3, 2021, 4:12:35 PM5/3/21
to SIP.js
I would suggest to try and make an upgrade. The upgrade will be very easy for you, as 0.17 and 0.20 are using the same API, so I think you'll not break anything.
I can confirm that for me it works (also doing SUBSCRIBE to conference events to FreeSWITCH).

But in your case it seems like a misbehavior (and not from SIP.js side), because if SIP.js return 481 Call/Transaction Does Not Exist, it means that it won't recognize the NOTIFY to be part of SUBSCRIBE SIP dialog. So SIP.js thinks it is an out-of-dialog NOTIFY which gets rejected with 481 (had some experience with it lately when I made a log of "games" with NOTIFYs using Kamailio). 

Anyway, as I see it, the NOTIFY "From" & "To" headers should be in a reversed order. So are the tags. 
The NOTIFY SHOULD come back when "To" header is "gkatriy" <sip:gka...@sip.example.com>;tag=9fdp5tud4q
And "From" header should have: <sip:conf+conf-66098324-9f2f...@sip.example.com>;tag=cZIIBPkBx9MH
But it's reversed.
Is there a chance you're modifying the message on some Kamailio/OpenSIPS server before it reaches the client? 

anshk...@gmail.com

unread,
May 4, 2021, 2:36:43 AM5/4/21
to SIP.js
Hello Slavik, Thanks for the help.
There was an issue with From and To headers of NOTIFY. 

Rushikesh

unread,
May 6, 2021, 11:37:42 AM5/6/21
to SIP.js
Hey, How did you map the contact name to IP address? Because in contact field it is user...@randString.invalid But server expects IP in contact field right? How did you solve this for subscribe and notify?

Slavik Bialik

unread,
May 6, 2021, 12:52:23 PM5/6/21
to SIP.js
See my answer here:

2 parameters you need: 
  • contactName
  • viaHost

anshk...@gmail.com

unread,
May 6, 2021, 1:01:14 PM5/6/21
to SIP.js
I've enabled 

hackIpInContact: true

parameter while constructing UserAgent object.

Slavik Bialik

unread,
May 6, 2021, 1:06:35 PM5/6/21
to SIP.js
No need to use those hacks... only in cases you do not have a choice, but you do :)
Setting contactName & viaHost in UserAgentOptions object will do the trick.

Reply all
Reply to author
Forward
0 new messages