Skip to content

Commit

Permalink
versatica#432 icencandidate timeout gathering
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaol committed Feb 20, 2019
1 parent dc11695 commit c63db00
Show file tree
Hide file tree
Showing 5 changed files with 918 additions and 1,490 deletions.
55 changes: 28 additions & 27 deletions dist/jssip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JsSIP v3.2.11
* the Javascript SIP library
* Copyright: 2012-2018 José Luis Millán <[email protected]> (https://github.com/jmillan)
* Copyright: 2012-2019 José Luis Millán <[email protected]> (https://github.com/jmillan)
* Homepage: http://jssip.net
* License: MIT
*/
Expand Down Expand Up @@ -16001,34 +16001,35 @@ module.exports = function (_EventEmitter) {

// Add 'pc.onicencandidate' event handler to resolve on last candidate.
return new Promise(function (resolve) {
var finished = false;
var listener = void 0;
// let finished = false;
var _listener = void 0;

var ready = function ready() {
connection.removeEventListener('icecandidate', listener);
connection.addEventListener('icecandidate', _listener = function listener(event) {
var that = _this13;

finished = true;
_this13._rtcReady = true;

var e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

debug('emit "sdp"');

_this13.emit('sdp', e);

resolve(e.sdp);
};
setTimeout(function () {
if (connection.iceGatheringState === 'complete') {
return;
}
debug('ICE Timeout reached!');
connection.removeEventListener('icecandidate', _listener);
that._rtcReady = true;
var e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

connection.addEventListener('icecandidate', listener = function listener(event) {
debug('emit "sdp"');
that.emit('sdp', e);
resolve(e.sdp);
}, 2000);
var candidate = event.candidate;

if (candidate) {
_this13.emit('icecandidate', {
candidate: candidate,
ready: ready
});
} else if (!finished) {
ready();
if (!candidate) {
connection.removeEventListener('icecandidate', _listener);
_this13._rtcReady = true;
var _e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

debug('emit "sdp"');
_this13.emit('sdp', _e);
resolve(_e.sdp);
}
});
});
Expand Down Expand Up @@ -16792,12 +16793,12 @@ module.exports = function (_EventEmitter) {
break;
}

var _e = { originator: 'remote', type: 'answer', sdp: response.body };
var _e2 = { originator: 'remote', type: 'answer', sdp: response.body };

debug('emit "sdp"');
this.emit('sdp', _e);
this.emit('sdp', _e2);

var _answer = new RTCSessionDescription({ type: 'answer', sdp: _e.sdp });
var _answer = new RTCSessionDescription({ type: 'answer', sdp: _e2.sdp });

this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
// Be ready for 200 with SDP after a 180/183 with SDP.
Expand Down
4 changes: 2 additions & 2 deletions dist/jssip.min.js

Large diffs are not rendered by default.

51 changes: 25 additions & 26 deletions lib/RTCSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -1882,40 +1882,39 @@ module.exports = class RTCSession extends EventEmitter
// Add 'pc.onicencandidate' event handler to resolve on last candidate.
return new Promise((resolve) =>
{
let finished = false;
// let finished = false;
let listener;

const ready = () =>
{
connection.removeEventListener('icecandidate', listener);

finished = true;
this._rtcReady = true;

const e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

debug('emit "sdp"');

this.emit('sdp', e);

resolve(e.sdp);
};

connection.addEventListener('icecandidate', listener = (event) =>
{
const candidate = event.candidate;
const that = this;

if (candidate)
setTimeout(function()
{
this.emit('icecandidate', {
candidate,
ready
});
}
if (connection.iceGatheringState === 'complete')
{
return;
}
debug('ICE Timeout reached!');
connection.removeEventListener('icecandidate', listener);
that._rtcReady = true;
const e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

debug('emit "sdp"');
that.emit('sdp', e);
resolve(e.sdp);
}, 2000);
const candidate = event.candidate;

else if (! finished)
if (! candidate)
{
ready();
connection.removeEventListener('icecandidate', listener);
this._rtcReady = true;
const e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };

debug('emit "sdp"');
this.emit('sdp', e);
resolve(e.sdp);
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,10 @@ module.exports = class UA extends EventEmitter
if (this._configuration.contact_uri)
{
// this._configuration.via_host = this._configuration.contact_uri.host;
// TODO: for user in Contact by zhaolei
this._configuration.via_host = `${Utils.createRandomToken(12)}.invalid`;
// TODO: for user in Contact by zhaolei
this._configuration.via_host = `${Utils.createRandomToken(12)}.invalid`;
this._configuration.contact_uri = new URI('sip', this._configuration.contact_uri.user, this._configuration.via_host, null, { transport: 'ws' });
// end
// end
}

// Contact URI.
Expand Down
Loading

0 comments on commit c63db00

Please sign in to comment.