How do I get the onaddstream event of peerconnection on 0.8.2 ?

356 views
Skip to first unread message

Nuno Nunes

unread,
Oct 31, 2017, 11:29:10 AM10/31/17
to SIP.js
The documentation is great until the part to put the media on the dom. No documentation at all, I guess I need to get the onaddstream event from peerconnection, but I don't know how to get the peerconnection object. 


var session = userAgent.invite('sip:12345',options);

session.sessionDescriptionHandler.peerConnection.onaddstream =  = function(){
console.log('stream added');
}

Don't work gives the error:

Uncaught TypeError: Cannot read property 'peerConnection' of undefined


although if I console log session object right before, I can see the peerconnection under sessionDescriptionHandler... .wtf...

ige...@gmail.com

unread,
Oct 31, 2017, 3:00:52 PM10/31/17
to SIP.js
peerconnection is not available right away, use addStream event instead:

session.sessionDescriptionHandler.on('addStream', function() { console.log('stream added') })

Eric Green

unread,
Oct 31, 2017, 3:04:52 PM10/31/17
to SIP.js
The issue is that the sessionDescriptionHandler is not defined right away. It is not defined until it is needed. I do emit an event when it is created, though it is a bit obscure. See my example below.

session.on('SessionDescriptionHandler-created', function(sessionDescriptionHandler) {
  // sessionDescriptionHandler.peerConnection will absolutely be defined here
});

I will try and document this a little better on our website. I have a few documentation tasks to do.

-Eric Green

Eric Green

unread,
Oct 31, 2017, 3:07:10 PM10/31/17
to SIP.js
Also,

session.sessionDescriptionHandler.on('addStream', function()...)

May suffer from the same issue of the sessionDescriptionHandler being undefined. Additionally, addStream is on it's way out. The underlying WebRTC implementation is moving in the direction of tracks. It is just not fully there yet in all the browsers which is why there is split behavior between browsers. Consider using adapter.js to get a more consistent API.

-Eric Green

bruce...@lakeshoress.com

unread,
Jan 18, 2018, 1:07:52 PM1/18/18
to SIP.js
Has this been resolved? I get the same sessionDescriptionHandler undefined erro when I call:

session.on('SessionDescriptionHandler-created', function(sessionDescriptionHandler)

Is there any documentation on the proper method for using sessionDescriptionHandler?

James Criscuolo

unread,
Jan 18, 2018, 1:25:04 PM1/18/18
to SIP.js
Reply all
Reply to author
Forward
0 new messages