SIP Failure and End Causes handling with version 0.20.x

832 views
Skip to first unread message

shrey shah

unread,
Sep 13, 2021, 2:15:54 AM9/13/21
to SIP.js
Hi, I need to get all the failure and end causes with the current version. Can anyone provide me how to implement this part. Mainly I need to get the call termination cause (busy, no answer, etc.)

I am using the following code to get some events, now I need further events to know call terminated cause.

this.callInviter.stateChange.addListener((newStateSessionState) => {
      switch (newState) {
        case SessionState.Establishing:
          break;
        case SessionState.Established:
          break;
        case SessionState.Terminated:
         break;
        default:
          break;
      }
    });

Slavik Bialik

unread,
Sep 13, 2021, 6:31:09 AM9/13/21
to SIP.js
No,
this is not the correct way. You need to use "delegate" on the Invitation / Inviter objects.
You can delegate on: onBye, onReject (4xx/5xx/6xx errors), onCancel (my small contribution, but will be only in the next release) and some others.
If you're trying to catch failures, most of them will be caught using `onReject` callback, when it's called you can fetch every piece of data from that SIP message that triggered that callback,
like the status code, status reason, and all other headers you'll need.

Here's a small example of how to do it. It shows how to delegate it using Inviter... but you can do the same for Invitation also if you need.

var inviterInviteOptions: InviterInviteOptions = {
requestDelegate: {
onAccept(response: AckableIncomingResponseWithSession)
{
console.log('call has been answered');
},
onReject(response: IncomingResponse)
{
console.log(`Couldn't establish a call as a result of SIP error: (${response.message.statusCode}) ${response.message.reasonPhrase}`);
}
}
}

this.inviter.invite(inviterInviteOptions);

shrey shah

unread,
Sep 14, 2021, 1:47:09 AM9/14/21
to SIP.js
Thanks a lot for the solution!

João Garrett Florêncio

unread,
Sep 14, 2021, 11:04:06 AM9/14/21
to SIP.js
I'm also having the same issue. 
How should I place the delegate if there is no InviterInviteOptions on Invitation, only on Inviter. Is there a delegate for incoming requests?

Thanks,
Joao Florencio

Message has been deleted

Slavik Bialik

unread,
Sep 15, 2021, 5:47:54 AM9/15/21
to SIP.js
Hi  João,
Yes you can delegate. But for Invitation it'll look like this:

invitation.delegate = {
onBye(bye)
{
console.log(`we received a bye message!`);
}
};

You do not have `onReject` for Invitation delegation. Depends on what you need exactly...

😎

Joao Florencio

unread,
Sep 15, 2021, 10:31:20 AM9/15/21
to SIP.js
That's what I'm trying to do but I what I really wanted is the onCancel to retrieve the "Reason" to know if I should present a missed call notification or not depending if the call was answered elsewhere.

Is there a delegate for onCancel?

Thanks!

Slavik Bialik

unread,
Sep 15, 2021, 12:35:52 PM9/15/21
to SIP.js
There is no onCancel that you can delegate on.
But from next release you'll have it. I contributed it as a PR, as I also needed that.

So in my platform I'm already working with this `onCancel` and it's working great for me.

Don't know when the next SIP.js release will be released. Hopefully soon, as I also want to go back to work with packages and not with a private Git repository for that.

Joao Florencio

unread,
Sep 16, 2021, 5:39:10 AM9/16/21
to SIP.js
I've read the PR notes and this will be more than enough for my case, in which I just want to go through the Reason header of the Cancel .

Has the PR been accepted yet? 

Thanks for the contribution by the way! 😉


Slavik Bialik

unread,
Sep 17, 2021, 6:26:36 AM9/17/21
to SIP.js
Yes, the PR has been accepted already. :)

Mitul Jadav

unread,
Mar 30, 2023, 11:00:06 AM3/30/23
to SIP.js
Hii,
I am using version 0.21.x. And i have same issue that if call rejected by remote side not fired any event callback.

I am using the following code to get some events. But didn't get logs in onReject() callback on terminate call without receive.

const socketServer = `wss://${sipURL}`;

const userAgentOptions: UserAgentOptions = {
transportOptions: { server: socketServer },
uri: UserAgent.makeURI(`sip:${username}@${sipURL}`),
authorizationUsername: username,
authorizationPassword: password,
delegate: {
onDisconnect(error) {
console.log('HELLO UA DISCONNECT', error);
},
},
};
const UaAgent = new UserAgent(userAgentOptions);
await UaAgent.start();

const target = UserAgent.makeURI(`sip:${'+9190****6554'}@${sipURL}`);

if (!UaAgent || !target) return;
const inviter = new Inviter(UaAgent, target);

inviter
.invite({
requestDelegate: {
onReject: (response) => console.log('HELLO REJECTED', response),
onAccept: (response) => console.log('HELLo ACCEPTED', response),
},
})
.then(() => console.log('HELLO Invite Then'));

Muneeb Ahmed

unread,
Jan 24, 2024, 5:18:34 AM1/24/24
to SIP.js
hey man any update in this ???

HOANG NGUYEN

unread,
Dec 3, 2025, 11:21:49 PM (4 days ago) Dec 3
to SIP.js
Hello everyone, I'm having a pretty serious problem when using sipjs version 0.20, I often get errors 486 and 430. Do I need to upgrade to version 0.21 to solve this problem?

Vào lúc 17:18:34 UTC+7 ngày Thứ Tư, 24 tháng 1, 2024, Muneeb Ahmed đã viết:

Muneeb Ahmed

unread,
Dec 4, 2025, 5:21:39 AM (4 days ago) Dec 4
to SIP.js
Can you share some browser logs for better clarity... also the setup details.
Reply all
Reply to author
Forward
0 new messages