How to get SIP.JS Session from Inviter

1,020 views
Skip to first unread message

Michael Sila

unread,
Mar 16, 2021, 7:54:32 PM3/16/21
to SIP.js
So I'm following the guide and I have the following code:
try {
const inviter = new Inviter(this.userAgentSip, target);
inviter.stateChange.addListener((state: SessionState) => {
console.log(`Session state changed to ${state}`);
switch (state) {
case SessionState.Initial:
break;
case SessionState.Establishing:
break;
case SessionState.Established:
this.setupRemoteMedia(inviter);
break;
case SessionState.Terminating:
// fall through
case SessionState.Terminated:
this.cleanupRemoteMedia();
this.sipSession = null
break;
default:
throw new Error("Unknown session state.");
}
});
inviter.invite().then((info) => {
info.delegate.onAccept = (response ) => {
console.log("Got Session");
this.sipSession = response.session as any ;
this.inviting = false;
}
}).catch(error => {
console.error(error)
this.inviting = false;
this.sipSession = null;
})
} catch(err) {
this.inviting = false;
console.error(err)
}

I was trying to set the session by getting it from the OnAccept Callback. However, the session from that response seems to be fundamentally different than the session object referenced in the guides. Specifically, it is missing several methods and the state object. The guide https://sipjs.com/guides/end-call/ frustratingly skips over how to grab the session. Here's the make call for comparison: https://sipjs.com/guides/make-call/ . There's no description of how to actually grab the session object. 

Rushikesh Koli

unread,
Mar 16, 2021, 11:40:36 PM3/16/21
to SIP.js
This might help you..
case SessionState.Established:
let sessionDescriptionHandler: SessionDescriptionHandler = inviter.sessionDescriptionHandler as SessionDescriptionHandler;
setupRemoteMedia(sessionDescriptionHandler);
break;

Michael Sila

unread,
Mar 16, 2021, 11:42:11 PM3/16/21
to sip...@googlegroups.com
Thank you. I think I figured it out; You can get the session from the inviter object itself.

--
You received this message because you are subscribed to a topic in the Google Groups "SIP.js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sip_js/HxA9zl6IReI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sip_js+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sip_js/00e9acec-9b39-4ff9-acaa-a907f1815596n%40googlegroups.com.

Rushikesh Koli

unread,
Mar 16, 2021, 11:45:56 PM3/16/21
to SIP.js
which method did you use? I am also working with sessions.. Just wanted to know various ways to get a session.

Michael Sila

unread,
Mar 16, 2021, 11:47:22 PM3/16/21
to sip...@googlegroups.com
The inviter object is actually just an instance of a session. When you create an inviter, store it in a non locally scoped variable and then call stuff on it as needed.

Reply all
Reply to author
Forward
0 new messages