|
|
@@ -2,7 +2,7 @@
|
|
2
|
2
|
|
|
3
|
3
|
import {getLogger} from "jitsi-meet-logger";
|
|
4
|
4
|
const logger = getLogger(__filename);
|
|
5
|
|
-var JingleSession = require("./JingleSession");
|
|
|
5
|
+import JingleSession from "./JingleSession";
|
|
6
|
6
|
var SDPDiffer = require("./SDPDiffer");
|
|
7
|
7
|
var SDPUtil = require("./SDPUtil");
|
|
8
|
8
|
var SDP = require("./SDP");
|
|
|
@@ -21,6 +21,8 @@ import * as JingleSessionState from "./JingleSessionState";
|
|
21
|
21
|
*/
|
|
22
|
22
|
var IQ_TIMEOUT = 10000;
|
|
23
|
23
|
|
|
|
24
|
+export default class JingleSessionPC extends JingleSession {
|
|
|
25
|
+
|
|
24
|
26
|
/**
|
|
25
|
27
|
* Creates new <tt>JingleSessionPC</tt>
|
|
26
|
28
|
* @param {string} me our JID
|
|
|
@@ -45,10 +47,9 @@ var IQ_TIMEOUT = 10000;
|
|
45
|
47
|
*
|
|
46
|
48
|
* @implements {SignalingLayer}
|
|
47
|
49
|
*/
|
|
48
|
|
-function JingleSessionPC(me, sid, peerjid, connection,
|
|
|
50
|
+constructor(me, sid, peerjid, connection,
|
|
49
|
51
|
media_constraints, ice_config, options) {
|
|
50
|
|
- JingleSession.call(this, me, sid, peerjid, connection,
|
|
51
|
|
- media_constraints, ice_config);
|
|
|
52
|
+ super(me, sid, peerjid, connection, media_constraints, ice_config);
|
|
52
|
53
|
|
|
53
|
54
|
this.lasticecandidate = false;
|
|
54
|
55
|
this.closed = false;
|
|
|
@@ -93,10 +94,7 @@ function JingleSessionPC(me, sid, peerjid, connection,
|
|
93
|
94
|
this.modificationQueue = async.queue(this._processQueueTasks.bind(this), 1);
|
|
94
|
95
|
}
|
|
95
|
96
|
|
|
96
|
|
-JingleSessionPC.prototype = Object.create(JingleSession.prototype);
|
|
97
|
|
-JingleSessionPC.prototype.constructor = JingleSessionPC;
|
|
98
|
|
-
|
|
99
|
|
-JingleSessionPC.prototype.doInitialize = function () {
|
|
|
97
|
+doInitialize () {
|
|
100
|
98
|
var self = this;
|
|
101
|
99
|
this.lasticecandidate = false;
|
|
102
|
100
|
// True if reconnect is in progress
|
|
|
@@ -202,9 +200,9 @@ JingleSessionPC.prototype.doInitialize = function () {
|
|
202
|
200
|
this.peerconnection.onnegotiationneeded = function () {
|
|
203
|
201
|
self.room.eventEmitter.emit(XMPPEvents.PEERCONNECTION_READY, self);
|
|
204
|
202
|
};
|
|
205
|
|
-};
|
|
|
203
|
+}
|
|
206
|
204
|
|
|
207
|
|
-JingleSessionPC.prototype.sendIceCandidate = function (candidate) {
|
|
|
205
|
+sendIceCandidate (candidate) {
|
|
208
|
206
|
var self = this;
|
|
209
|
207
|
const localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
|
210
|
208
|
if (candidate && !this.lasticecandidate) {
|
|
|
@@ -236,9 +234,9 @@ JingleSessionPC.prototype.sendIceCandidate = function (candidate) {
|
|
236
|
234
|
// FIXME: remember to re-think in ICE-restart
|
|
237
|
235
|
this.lasticecandidate = true;
|
|
238
|
236
|
}
|
|
239
|
|
-};
|
|
|
237
|
+}
|
|
240
|
238
|
|
|
241
|
|
-JingleSessionPC.prototype.sendIceCandidates = function (candidates) {
|
|
|
239
|
+sendIceCandidates (candidates) {
|
|
242
|
240
|
logger.log('sendIceCandidates', candidates);
|
|
243
|
241
|
var cand = $iq({to: this.peerjid, type: 'set'})
|
|
244
|
242
|
.c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
|
|
@@ -288,9 +286,9 @@ JingleSessionPC.prototype.sendIceCandidates = function (candidates) {
|
|
288
|
286
|
GlobalOnErrorHandler.callErrorHandler(
|
|
289
|
287
|
new Error("Jingle error: " + JSON.stringify(error)));
|
|
290
|
288
|
}), IQ_TIMEOUT);
|
|
291
|
|
-};
|
|
|
289
|
+}
|
|
292
|
290
|
|
|
293
|
|
-JingleSessionPC.prototype.readSsrcInfo = function (contents) {
|
|
|
291
|
+readSsrcInfo (contents) {
|
|
294
|
292
|
var self = this;
|
|
295
|
293
|
$(contents).each(function (idx, content) {
|
|
296
|
294
|
var ssrcs = $(content).find('description>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
|
|
|
@@ -307,20 +305,20 @@ JingleSessionPC.prototype.readSsrcInfo = function (contents) {
|
|
307
|
305
|
);
|
|
308
|
306
|
});
|
|
309
|
307
|
});
|
|
310
|
|
-};
|
|
|
308
|
+}
|
|
311
|
309
|
|
|
312
|
310
|
/**
|
|
313
|
311
|
* Makes the underlying TraceablePeerConnection generate new SSRC for
|
|
314
|
312
|
* the recvonly video stream.
|
|
315
|
313
|
* @deprecated
|
|
316
|
314
|
*/
|
|
317
|
|
-JingleSessionPC.prototype.generateRecvonlySsrc = function() {
|
|
|
315
|
+generateRecvonlySsrc () {
|
|
318
|
316
|
if (this.peerconnection) {
|
|
319
|
317
|
this.peerconnection.generateRecvonlySsrc();
|
|
320
|
318
|
} else {
|
|
321
|
319
|
logger.error("Unable to generate recvonly SSRC - no peerconnection");
|
|
322
|
320
|
}
|
|
323
|
|
-};
|
|
|
321
|
+}
|
|
324
|
322
|
|
|
325
|
323
|
/**
|
|
326
|
324
|
* Does accept incoming Jingle 'session-initiate' and should send
|
|
|
@@ -333,8 +331,7 @@ JingleSessionPC.prototype.generateRecvonlySsrc = function() {
|
|
333
|
331
|
* the incoming offer. 'error' argument can be used to log some details
|
|
334
|
332
|
* about the error.
|
|
335
|
333
|
*/
|
|
336
|
|
-JingleSessionPC.prototype.acceptOffer = function(jingleOffer,
|
|
337
|
|
- success, failure) {
|
|
|
334
|
+acceptOffer (jingleOffer, success, failure) {
|
|
338
|
335
|
this.state = JingleSessionState.ACTIVE;
|
|
339
|
336
|
this.setOfferCycle(
|
|
340
|
337
|
jingleOffer,
|
|
|
@@ -347,7 +344,7 @@ JingleSessionPC.prototype.acceptOffer = function(jingleOffer,
|
|
347
|
344
|
this.sendSessionAccept(success, failure);
|
|
348
|
345
|
},
|
|
349
|
346
|
failure);
|
|
350
|
|
-};
|
|
|
347
|
+}
|
|
351
|
348
|
|
|
352
|
349
|
/**
|
|
353
|
350
|
* This is a setRemoteDescription/setLocalDescription cycle which starts at
|
|
|
@@ -359,9 +356,7 @@ JingleSessionPC.prototype.acceptOffer = function(jingleOffer,
|
|
359
|
356
|
* @param failure callback called with an error object as an argument if we fail
|
|
360
|
357
|
* at any point during setRD, createAnswer, setLD.
|
|
361
|
358
|
*/
|
|
362
|
|
-JingleSessionPC.prototype.setOfferCycle = function (jingleOfferIq,
|
|
363
|
|
- success,
|
|
364
|
|
- failure) {
|
|
|
359
|
+setOfferCycle(jingleOfferIq, success, failure) {
|
|
365
|
360
|
let workFunction = (finishedCallback) => {
|
|
366
|
361
|
let newRemoteSdp = this._processNewJingleOfferIq(jingleOfferIq);
|
|
367
|
362
|
this._renegotiate(newRemoteSdp)
|
|
|
@@ -383,7 +378,7 @@ JingleSessionPC.prototype.setOfferCycle = function (jingleOfferIq,
|
|
383
|
378
|
}
|
|
384
|
379
|
}
|
|
385
|
380
|
);
|
|
386
|
|
-};
|
|
|
381
|
+}
|
|
387
|
382
|
|
|
388
|
383
|
/**
|
|
389
|
384
|
* Although it states "replace transport" it does accept full Jingle offer
|
|
|
@@ -393,9 +388,7 @@ JingleSessionPC.prototype.setOfferCycle = function (jingleOfferIq,
|
|
393
|
388
|
* @param success callback called when we succeed to accept new offer.
|
|
394
|
389
|
* @param failure function(error) called when we fail to accept new offer.
|
|
395
|
390
|
*/
|
|
396
|
|
-JingleSessionPC.prototype.replaceTransport = function (jingleOfferElem,
|
|
397
|
|
- success,
|
|
398
|
|
- failure) {
|
|
|
391
|
+replaceTransport (jingleOfferElem, success, failure) {
|
|
399
|
392
|
|
|
400
|
393
|
// We need to first set an offer without the 'data' section to have the SCTP
|
|
401
|
394
|
// stack cleaned up. After that the original offer is set to have the SCTP
|
|
|
@@ -420,17 +413,16 @@ JingleSessionPC.prototype.replaceTransport = function (jingleOfferElem,
|
|
420
|
413
|
},
|
|
421
|
414
|
failure
|
|
422
|
415
|
);
|
|
423
|
|
-};
|
|
|
416
|
+}
|
|
424
|
417
|
|
|
425
|
418
|
/**
|
|
426
|
419
|
* Sends Jingle 'session-accept' message.
|
|
427
|
|
- * @param localSDP the 'SDP' object with local session description
|
|
428
|
420
|
* @param {function()} success callback called when we recive 'RESULT' packet for
|
|
429
|
421
|
* 'session-accept'
|
|
430
|
422
|
* @param {function(error)} failure called when we receive an error response or
|
|
431
|
423
|
* when the request has timed out.
|
|
432
|
424
|
*/
|
|
433
|
|
-JingleSessionPC.prototype.sendSessionAccept = function (success, failure) {
|
|
|
425
|
+sendSessionAccept (success, failure) {
|
|
434
|
426
|
// NOTE: since we're just reading from it, we don't need to be within
|
|
435
|
427
|
// the modification queue to access the local description
|
|
436
|
428
|
let localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
|
|
@@ -487,7 +479,7 @@ JingleSessionPC.prototype.sendSessionAccept = function (success, failure) {
|
|
487
|
479
|
// immediate requests).
|
|
488
|
480
|
//
|
|
489
|
481
|
// this.connection.flush();
|
|
490
|
|
-};
|
|
|
482
|
+}
|
|
491
|
483
|
|
|
492
|
484
|
/**
|
|
493
|
485
|
* Sends Jingle 'transport-accept' message which is a response to
|
|
|
@@ -498,8 +490,7 @@ JingleSessionPC.prototype.sendSessionAccept = function (success, failure) {
|
|
498
|
490
|
* @param failure function(error) called when we receive an error response or
|
|
499
|
491
|
* when the request has timed out.
|
|
500
|
492
|
*/
|
|
501
|
|
-JingleSessionPC.prototype.sendTransportAccept = function(localSDP, success,
|
|
502
|
|
- failure) {
|
|
|
493
|
+sendTransportAccept (localSDP, success, failure) {
|
|
503
|
494
|
var self = this;
|
|
504
|
495
|
var tAccept = $iq({to: this.peerjid, type: 'set'})
|
|
505
|
496
|
.c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
|
|
@@ -526,7 +517,7 @@ JingleSessionPC.prototype.sendTransportAccept = function(localSDP, success,
|
|
526
|
517
|
success,
|
|
527
|
518
|
self.newJingleErrorHandler(tAccept, failure),
|
|
528
|
519
|
IQ_TIMEOUT);
|
|
529
|
|
-};
|
|
|
520
|
+}
|
|
530
|
521
|
|
|
531
|
522
|
/**
|
|
532
|
523
|
* Sends Jingle 'transport-reject' message which is a response to
|
|
|
@@ -536,7 +527,7 @@ JingleSessionPC.prototype.sendTransportAccept = function(localSDP, success,
|
|
536
|
527
|
* @param failure function(error) called when we receive an error response or
|
|
537
|
528
|
* when the request has timed out.
|
|
538
|
529
|
*/
|
|
539
|
|
-JingleSessionPC.prototype.sendTransportReject = function(success, failure) {
|
|
|
530
|
+sendTransportReject (success, failure) {
|
|
540
|
531
|
// Send 'transport-reject', so that the focus will
|
|
541
|
532
|
// know that we've failed
|
|
542
|
533
|
var tReject = $iq({to: this.peerjid, type: 'set'})
|
|
|
@@ -552,13 +543,12 @@ JingleSessionPC.prototype.sendTransportReject = function(success, failure) {
|
|
552
|
543
|
success,
|
|
553
|
544
|
this.newJingleErrorHandler(tReject, failure),
|
|
554
|
545
|
IQ_TIMEOUT);
|
|
555
|
|
-};
|
|
|
546
|
+}
|
|
556
|
547
|
|
|
557
|
548
|
/**
|
|
558
|
549
|
* @inheritDoc
|
|
559
|
550
|
*/
|
|
560
|
|
-JingleSessionPC.prototype.terminate = function (reason, text,
|
|
561
|
|
- success, failure) {
|
|
|
551
|
+terminate (reason, text, success, failure) {
|
|
562
|
552
|
this.state = JingleSessionState.ENDED;
|
|
563
|
553
|
|
|
564
|
554
|
var term = $iq({to: this.peerjid,
|
|
|
@@ -583,10 +573,9 @@ JingleSessionPC.prototype.terminate = function (reason, text,
|
|
583
|
573
|
|
|
584
|
574
|
// this should result in 'onTerminated' being called by strope.jingle.js
|
|
585
|
575
|
this.connection.jingle.terminate(this.sid);
|
|
586
|
|
-};
|
|
|
576
|
+}
|
|
587
|
577
|
|
|
588
|
|
-JingleSessionPC.prototype.onTerminated = function (reasonCondition,
|
|
589
|
|
- reasonText) {
|
|
|
578
|
+onTerminated (reasonCondition, reasonText) {
|
|
590
|
579
|
this.state = 'ended';
|
|
591
|
580
|
|
|
592
|
581
|
// Do something with reason and reasonCondition when we start to care
|
|
|
@@ -595,7 +584,7 @@ JingleSessionPC.prototype.onTerminated = function (reasonCondition,
|
|
595
|
584
|
logger.info("Session terminated", this, reasonCondition, reasonText);
|
|
596
|
585
|
|
|
597
|
586
|
this.close();
|
|
598
|
|
-};
|
|
|
587
|
+}
|
|
599
|
588
|
|
|
600
|
589
|
/**
|
|
601
|
590
|
* Parse the information from the xml sourceAddElem and translate it
|
|
|
@@ -607,7 +596,7 @@ JingleSessionPC.prototype.onTerminated = function (reasonCondition,
|
|
607
|
596
|
* @returns {list} a list of SDP line strings that should
|
|
608
|
597
|
* be added to the remote SDP
|
|
609
|
598
|
*/
|
|
610
|
|
-JingleSessionPC.prototype._parseSsrcInfoFromSourceAdd = function (sourceAddElem, currentRemoteSdp) {
|
|
|
599
|
+_parseSsrcInfoFromSourceAdd (sourceAddElem, currentRemoteSdp) {
|
|
611
|
600
|
let addSsrcInfo = [];
|
|
612
|
601
|
$(sourceAddElem).each(function (idx, content) {
|
|
613
|
602
|
var name = $(content).attr('name');
|
|
|
@@ -646,13 +635,13 @@ JingleSessionPC.prototype._parseSsrcInfoFromSourceAdd = function (sourceAddElem,
|
|
646
|
635
|
});
|
|
647
|
636
|
});
|
|
648
|
637
|
return addSsrcInfo;
|
|
649
|
|
-};
|
|
|
638
|
+}
|
|
650
|
639
|
|
|
651
|
640
|
/**
|
|
652
|
641
|
* Handles a Jingle source-add message for this Jingle session.
|
|
653
|
642
|
* @param elem An array of Jingle "content" elements.
|
|
654
|
643
|
*/
|
|
655
|
|
-JingleSessionPC.prototype.addRemoteStream = function (elem) {
|
|
|
644
|
+addRemoteStream (elem) {
|
|
656
|
645
|
// FIXME: dirty waiting
|
|
657
|
646
|
if (!this.peerconnection.localDescription) {
|
|
658
|
647
|
logger.warn("addSource - localDescription not ready yet");
|
|
|
@@ -683,13 +672,13 @@ JingleSessionPC.prototype.addRemoteStream = function (elem) {
|
|
683
|
672
|
});
|
|
684
|
673
|
};
|
|
685
|
674
|
this.modificationQueue.push(workFunction);
|
|
686
|
|
-};
|
|
|
675
|
+}
|
|
687
|
676
|
|
|
688
|
677
|
/**
|
|
689
|
678
|
* Handles a Jingle source-remove message for this Jingle session.
|
|
690
|
679
|
* @param elem An array of Jingle "content" elements.
|
|
691
|
680
|
*/
|
|
692
|
|
-JingleSessionPC.prototype.removeRemoteStream = function (elem) {
|
|
|
681
|
+removeRemoteStream (elem) {
|
|
693
|
682
|
// FIXME: dirty waiting
|
|
694
|
683
|
if (!this.peerconnection.localDescription) {
|
|
695
|
684
|
logger.warn("removeSource - localDescription not ready yet");
|
|
|
@@ -718,7 +707,7 @@ JingleSessionPC.prototype.removeRemoteStream = function (elem) {
|
|
718
|
707
|
});
|
|
719
|
708
|
};
|
|
720
|
709
|
this.modificationQueue.push(workFunction);
|
|
721
|
|
-};
|
|
|
710
|
+}
|
|
722
|
711
|
|
|
723
|
712
|
/**
|
|
724
|
713
|
* The 'task' function will be given a callback it MUST call with either:
|
|
|
@@ -734,16 +723,16 @@ JingleSessionPC.prototype.removeRemoteStream = function (elem) {
|
|
734
|
723
|
* }
|
|
735
|
724
|
* });
|
|
736
|
725
|
*/
|
|
737
|
|
-JingleSessionPC.prototype._processQueueTasks = function (task, finishedCallback) {
|
|
|
726
|
+_processQueueTasks (task, finishedCallback) {
|
|
738
|
727
|
task(finishedCallback);
|
|
739
|
|
-};
|
|
|
728
|
+}
|
|
740
|
729
|
|
|
741
|
730
|
/**
|
|
742
|
731
|
* Takes in a jingle offer iq, returns the new sdp offer
|
|
743
|
732
|
* @param {jquery xml element} offerIq the incoming offer
|
|
744
|
733
|
* @returns {SDP object} the jingle offer translated to SDP
|
|
745
|
734
|
*/
|
|
746
|
|
-JingleSessionPC.prototype._processNewJingleOfferIq = function(offerIq) {
|
|
|
735
|
+_processNewJingleOfferIq (offerIq) {
|
|
747
|
736
|
let remoteSdp = new SDP('');
|
|
748
|
737
|
if (this.webrtcIceTcpDisable) {
|
|
749
|
738
|
remoteSdp.removeTcpCandidates = true;
|
|
|
@@ -758,7 +747,7 @@ JingleSessionPC.prototype._processNewJingleOfferIq = function(offerIq) {
|
|
758
|
747
|
remoteSdp.fromJingle(offerIq);
|
|
759
|
748
|
this.readSsrcInfo($(offerIq).find(">content"));
|
|
760
|
749
|
return remoteSdp;
|
|
761
|
|
-};
|
|
|
750
|
+}
|
|
762
|
751
|
|
|
763
|
752
|
/**
|
|
764
|
753
|
* Remove the given ssrc lines from the current remote sdp
|
|
|
@@ -767,7 +756,7 @@ JingleSessionPC.prototype._processNewJingleOfferIq = function(offerIq) {
|
|
767
|
756
|
* @returns type {SDP Object} the new remote SDP (after removing the lines
|
|
768
|
757
|
* in removeSsrcInfo
|
|
769
|
758
|
*/
|
|
770
|
|
-JingleSessionPC.prototype._processRemoteRemoveSource = function (removeSsrcInfo) {
|
|
|
759
|
+_processRemoteRemoveSource (removeSsrcInfo) {
|
|
771
|
760
|
let remoteSdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
|
772
|
761
|
removeSsrcInfo.forEach(function(lines, idx) {
|
|
773
|
762
|
lines = lines.split('\r\n');
|
|
|
@@ -779,7 +768,7 @@ JingleSessionPC.prototype._processRemoteRemoveSource = function (removeSsrcInfo)
|
|
779
|
768
|
remoteSdp.raw = remoteSdp.session + remoteSdp.media.join('');
|
|
780
|
769
|
|
|
781
|
770
|
return remoteSdp;
|
|
782
|
|
-};
|
|
|
771
|
+}
|
|
783
|
772
|
|
|
784
|
773
|
/**
|
|
785
|
774
|
* Add the given ssrc lines to the current remote sdp
|
|
|
@@ -788,7 +777,7 @@ JingleSessionPC.prototype._processRemoteRemoveSource = function (removeSsrcInfo)
|
|
788
|
777
|
* @returns type {SDP Object} the new remote SDP (after removing the lines
|
|
789
|
778
|
* in removeSsrcInfo
|
|
790
|
779
|
*/
|
|
791
|
|
-JingleSessionPC.prototype._processRemoteAddSource = function (addSsrcInfo) {
|
|
|
780
|
+_processRemoteAddSource (addSsrcInfo) {
|
|
792
|
781
|
let remoteSdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
|
793
|
782
|
addSsrcInfo.forEach(function(lines, idx) {
|
|
794
|
783
|
remoteSdp.media[idx] += lines;
|
|
|
@@ -796,7 +785,7 @@ JingleSessionPC.prototype._processRemoteAddSource = function (addSsrcInfo) {
|
|
796
|
785
|
remoteSdp.raw = remoteSdp.session + remoteSdp.media.join('');
|
|
797
|
786
|
|
|
798
|
787
|
return remoteSdp;
|
|
799
|
|
-};
|
|
|
788
|
+}
|
|
800
|
789
|
|
|
801
|
790
|
/**
|
|
802
|
791
|
* Do a new o/a flow using the existing remote description
|
|
|
@@ -807,7 +796,7 @@ JingleSessionPC.prototype._processRemoteAddSource = function (addSsrcInfo) {
|
|
807
|
796
|
* o/a flow is complete with no arguments or
|
|
808
|
797
|
* rejects with an error {string}
|
|
809
|
798
|
*/
|
|
810
|
|
-JingleSessionPC.prototype._renegotiate = function(optionalRemoteSdp) {
|
|
|
799
|
+_renegotiate (optionalRemoteSdp) {
|
|
811
|
800
|
let media_constraints = this.media_constraints;
|
|
812
|
801
|
let remoteSdp = optionalRemoteSdp || new SDP(this.peerconnection.remoteDescription.sdp);
|
|
813
|
802
|
let remoteDescription = new RTCSessionDescription({
|
|
|
@@ -823,7 +812,7 @@ JingleSessionPC.prototype._renegotiate = function(optionalRemoteSdp) {
|
|
823
|
812
|
// logic below could listen to that and be separated from
|
|
824
|
813
|
// core flows like this.
|
|
825
|
814
|
return new Promise((resolve, reject) => {
|
|
826
|
|
- let remoteUfrag = getUfrag(remoteDescription.sdp);
|
|
|
815
|
+ let remoteUfrag = JingleSessionPC.getUfrag(remoteDescription.sdp);
|
|
827
|
816
|
if (remoteUfrag != this.remoteUfrag) {
|
|
828
|
817
|
this.remoteUfrag = remoteUfrag;
|
|
829
|
818
|
this.room.eventEmitter.emit(
|
|
|
@@ -840,7 +829,7 @@ JingleSessionPC.prototype._renegotiate = function(optionalRemoteSdp) {
|
|
840
|
829
|
logger.debug("Renegotiate: creating answer");
|
|
841
|
830
|
this.peerconnection.createAnswer(
|
|
842
|
831
|
(answer) => {
|
|
843
|
|
- let localUfrag = getUfrag(answer.sdp);
|
|
|
832
|
+ let localUfrag = JingleSessionPC.getUfrag(answer.sdp);
|
|
844
|
833
|
if (localUfrag != this.localUfrag) {
|
|
845
|
834
|
this.localUfrag = localUfrag;
|
|
846
|
835
|
this.room.eventEmitter.emit(
|
|
|
@@ -862,7 +851,7 @@ JingleSessionPC.prototype._renegotiate = function(optionalRemoteSdp) {
|
|
862
|
851
|
}
|
|
863
|
852
|
);
|
|
864
|
853
|
});
|
|
865
|
|
-};
|
|
|
854
|
+}
|
|
866
|
855
|
|
|
867
|
856
|
/**
|
|
868
|
857
|
* Replaces oldStream with newStream and performs a single offer/answer
|
|
|
@@ -875,7 +864,7 @@ JingleSessionPC.prototype._renegotiate = function(optionalRemoteSdp) {
|
|
875
|
864
|
* @returns {Promise} which resolves once the replacement is complete
|
|
876
|
865
|
* with no arguments or rejects with an error {string}
|
|
877
|
866
|
*/
|
|
878
|
|
-JingleSessionPC.prototype.replaceTrack = function (oldTrack, newTrack) {
|
|
|
867
|
+replaceTrack (oldTrack, newTrack) {
|
|
879
|
868
|
return new Promise((resolve, reject) => {
|
|
880
|
869
|
let workFunction = (finishedCallback) => {
|
|
881
|
870
|
let oldSdp = new SDP(this.peerconnection.localDescription.sdp);
|
|
|
@@ -902,7 +891,7 @@ JingleSessionPC.prototype.replaceTrack = function (oldTrack, newTrack) {
|
|
902
|
891
|
}
|
|
903
|
892
|
);
|
|
904
|
893
|
});
|
|
905
|
|
-};
|
|
|
894
|
+}
|
|
906
|
895
|
|
|
907
|
896
|
/**
|
|
908
|
897
|
* Just add the stream to the peerconnection
|
|
|
@@ -911,12 +900,12 @@ JingleSessionPC.prototype.replaceTrack = function (oldTrack, newTrack) {
|
|
911
|
900
|
* NOTE: must be called within a work function being executed
|
|
912
|
901
|
* by the modification queue.
|
|
913
|
902
|
*/
|
|
914
|
|
-JingleSessionPC.prototype.addStreamToPeerConnection = function (stream, ssrcInfo) {
|
|
|
903
|
+addStreamToPeerConnection (stream, ssrcInfo) {
|
|
915
|
904
|
let actualStream = stream && stream.getOriginalStream ? stream.getOriginalStream() : stream;
|
|
916
|
905
|
if (this.peerconnection) {
|
|
917
|
906
|
this.peerconnection.addStream(actualStream, ssrcInfo);
|
|
918
|
907
|
}
|
|
919
|
|
-};
|
|
|
908
|
+}
|
|
920
|
909
|
|
|
921
|
910
|
/**
|
|
922
|
911
|
* Parse the information from the xml sourceRemoveElem and translate it
|
|
|
@@ -928,7 +917,7 @@ JingleSessionPC.prototype.addStreamToPeerConnection = function (stream, ssrcInfo
|
|
928
|
917
|
* @returns {list} a list of SDP line strings that should
|
|
929
|
918
|
* be removed from the remote SDP
|
|
930
|
919
|
*/
|
|
931
|
|
-JingleSessionPC.prototype._parseSsrcInfoFromSourceRemove = function (sourceRemoveElem, currentRemoteSdp) {
|
|
|
920
|
+_parseSsrcInfoFromSourceRemove (sourceRemoveElem, currentRemoteSdp) {
|
|
932
|
921
|
let removeSsrcInfo = [];
|
|
933
|
922
|
$(sourceRemoveElem).each(function (idx, content) {
|
|
934
|
923
|
var name = $(content).attr('name');
|
|
|
@@ -965,7 +954,7 @@ JingleSessionPC.prototype._parseSsrcInfoFromSourceRemove = function (sourceRemov
|
|
965
|
954
|
});
|
|
966
|
955
|
});
|
|
967
|
956
|
return removeSsrcInfo;
|
|
968
|
|
-};
|
|
|
957
|
+}
|
|
969
|
958
|
|
|
970
|
959
|
/**
|
|
971
|
960
|
* Adds stream.
|
|
|
@@ -984,8 +973,7 @@ JingleSessionPC.prototype._parseSsrcInfoFromSourceRemove = function (sourceRemov
|
|
984
|
973
|
* logic should be moved into a helper function that could be called within
|
|
985
|
974
|
* the 'doReplaceStream' task or the 'doAddStream' task (for example)
|
|
986
|
975
|
*/
|
|
987
|
|
-JingleSessionPC.prototype.addStream = function (stream, callback, errorCallback,
|
|
988
|
|
- ssrcInfo, dontModifySources) {
|
|
|
976
|
+addStream (stream, callback, errorCallback, ssrcInfo, dontModifySources) {
|
|
989
|
977
|
|
|
990
|
978
|
let workFunction = (finishedCallback) => {
|
|
991
|
979
|
if (!this.peerconnection) {
|
|
|
@@ -1025,22 +1013,22 @@ JingleSessionPC.prototype.addStream = function (stream, callback, errorCallback,
|
|
1025
|
1013
|
}
|
|
1026
|
1014
|
}
|
|
1027
|
1015
|
);
|
|
1028
|
|
-};
|
|
|
1016
|
+}
|
|
1029
|
1017
|
|
|
1030
|
1018
|
/**
|
|
1031
|
1019
|
* Generate ssrc info object for a stream with the following properties:
|
|
1032
|
1020
|
* - ssrcs - Array of the ssrcs associated with the stream.
|
|
1033
|
1021
|
* - groups - Array of the groups associated with the stream.
|
|
1034
|
1022
|
*/
|
|
1035
|
|
-JingleSessionPC.prototype.generateNewStreamSSRCInfo = function () {
|
|
|
1023
|
+generateNewStreamSSRCInfo () {
|
|
1036
|
1024
|
return this.peerconnection.generateNewStreamSSRCInfo();
|
|
1037
|
|
-};
|
|
|
1025
|
+}
|
|
1038
|
1026
|
|
|
1039
|
1027
|
/**
|
|
1040
|
1028
|
* Remove stream handling for firefox
|
|
1041
|
1029
|
* @param stream: webrtc media stream
|
|
1042
|
1030
|
*/
|
|
1043
|
|
-JingleSessionPC.prototype._handleFirefoxRemoveStream = function (stream) {
|
|
|
1031
|
+_handleFirefoxRemoveStream (stream) {
|
|
1044
|
1032
|
if (!stream) { //There is nothing to be changed
|
|
1045
|
1033
|
return;
|
|
1046
|
1034
|
}
|
|
|
@@ -1075,7 +1063,7 @@ JingleSessionPC.prototype._handleFirefoxRemoveStream = function (stream) {
|
|
1075
|
1063
|
} else {
|
|
1076
|
1064
|
logger.log("Cannot remove tracks: no RTPSender.");
|
|
1077
|
1065
|
}
|
|
1078
|
|
-};
|
|
|
1066
|
+}
|
|
1079
|
1067
|
|
|
1080
|
1068
|
/**
|
|
1081
|
1069
|
* Just remove the stream from the peerconnection
|
|
|
@@ -1083,7 +1071,7 @@ JingleSessionPC.prototype._handleFirefoxRemoveStream = function (stream) {
|
|
1083
|
1071
|
* NOTE: must be called within a work function being executed
|
|
1084
|
1072
|
* by the modification queue.
|
|
1085
|
1073
|
*/
|
|
1086
|
|
-JingleSessionPC.prototype.removeStreamFromPeerConnection = function (stream) {
|
|
|
1074
|
+removeStreamFromPeerConnection (stream) {
|
|
1087
|
1075
|
let actualStream
|
|
1088
|
1076
|
= stream && stream.getOriginalStream
|
|
1089
|
1077
|
? stream.getOriginalStream() : stream;
|
|
|
@@ -1096,7 +1084,7 @@ JingleSessionPC.prototype.removeStreamFromPeerConnection = function (stream) {
|
|
1096
|
1084
|
} else if (actualStream) {
|
|
1097
|
1085
|
this.peerconnection.removeStream(actualStream);
|
|
1098
|
1086
|
}
|
|
1099
|
|
-};
|
|
|
1087
|
+}
|
|
1100
|
1088
|
|
|
1101
|
1089
|
/**
|
|
1102
|
1090
|
* Remove streams.
|
|
|
@@ -1106,8 +1094,7 @@ JingleSessionPC.prototype.removeStreamFromPeerConnection = function (stream) {
|
|
1106
|
1094
|
* @param ssrcInfo object with information about the SSRCs associated with the
|
|
1107
|
1095
|
* stream.
|
|
1108
|
1096
|
*/
|
|
1109
|
|
-JingleSessionPC.prototype.removeStream = function (stream, callback, errorCallback,
|
|
1110
|
|
- ssrcInfo) {
|
|
|
1097
|
+removeStream (stream, callback, errorCallback, ssrcInfo) {
|
|
1111
|
1098
|
let workFunction = (finishedCallback) => {
|
|
1112
|
1099
|
if (!this.peerconnection) {
|
|
1113
|
1100
|
finishedCallback();
|
|
|
@@ -1145,14 +1132,14 @@ JingleSessionPC.prototype.removeStream = function (stream, callback, errorCallba
|
|
1145
|
1132
|
}
|
|
1146
|
1133
|
}
|
|
1147
|
1134
|
);
|
|
1148
|
|
-};
|
|
|
1135
|
+}
|
|
1149
|
1136
|
|
|
1150
|
1137
|
/**
|
|
1151
|
1138
|
* Figures out added/removed ssrcs and send update IQs.
|
|
1152
|
1139
|
* @param old_sdp SDP object for old description.
|
|
1153
|
1140
|
* @param new_sdp SDP object for new description.
|
|
1154
|
1141
|
*/
|
|
1155
|
|
-JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
|
|
|
1142
|
+notifyMySSRCUpdate (old_sdp, new_sdp) {
|
|
1156
|
1143
|
|
|
1157
|
1144
|
if (this.state !== JingleSessionState.ACTIVE){
|
|
1158
|
1145
|
logger.warn(
|
|
|
@@ -1208,7 +1195,7 @@ JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
|
|
1208
|
1195
|
} else {
|
|
1209
|
1196
|
logger.log('addition not necessary');
|
|
1210
|
1197
|
}
|
|
1211
|
|
-};
|
|
|
1198
|
+}
|
|
1212
|
1199
|
|
|
1213
|
1200
|
/**
|
|
1214
|
1201
|
* Method returns function(errorResponse) which is a callback to be passed to
|
|
|
@@ -1228,7 +1215,7 @@ JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
|
|
1228
|
1215
|
* when a timeout has occurred.
|
|
1229
|
1216
|
* @returns {function(this:JingleSessionPC)}
|
|
1230
|
1217
|
*/
|
|
1231
|
|
-JingleSessionPC.prototype.newJingleErrorHandler = function(request, failureCb) {
|
|
|
1218
|
+newJingleErrorHandler (request, failureCb) {
|
|
1232
|
1219
|
return function (errResponse) {
|
|
1233
|
1220
|
|
|
1234
|
1221
|
var error = { };
|
|
|
@@ -1261,42 +1248,42 @@ JingleSessionPC.prototype.newJingleErrorHandler = function(request, failureCb) {
|
|
1261
|
1248
|
failureCb(error);
|
|
1262
|
1249
|
}
|
|
1263
|
1250
|
}.bind(this);
|
|
1264
|
|
-};
|
|
|
1251
|
+}
|
|
1265
|
1252
|
|
|
1266
|
|
-JingleSessionPC.onJingleFatalError = function (session, error)
|
|
|
1253
|
+static onJingleFatalError (session, error)
|
|
1267
|
1254
|
{
|
|
1268
|
1255
|
if (this.room) {
|
|
1269
|
1256
|
this.room.eventEmitter.emit(XMPPEvents.CONFERENCE_SETUP_FAILED, error);
|
|
1270
|
1257
|
this.room.eventEmitter.emit(XMPPEvents.JINGLE_FATAL_ERROR, session, error);
|
|
1271
|
1258
|
}
|
|
1272
|
|
-};
|
|
|
1259
|
+}
|
|
1273
|
1260
|
|
|
1274
|
1261
|
/**
|
|
1275
|
1262
|
* @inheritDoc
|
|
1276
|
1263
|
*/
|
|
1277
|
|
-JingleSessionPC.prototype.getPeerMediaInfo = function (owner, mediaType) {
|
|
|
1264
|
+getPeerMediaInfo (owner, mediaType) {
|
|
1278
|
1265
|
return this.room.getMediaPresenceInfo(owner, mediaType);
|
|
1279
|
|
-};
|
|
|
1266
|
+}
|
|
1280
|
1267
|
|
|
1281
|
1268
|
/**
|
|
1282
|
1269
|
* @inheritDoc
|
|
1283
|
1270
|
*/
|
|
1284
|
|
-JingleSessionPC.prototype.getSSRCOwner = function(ssrc) {
|
|
|
1271
|
+getSSRCOwner (ssrc) {
|
|
1285
|
1272
|
return this.ssrcOwners[ssrc];
|
|
1286
|
|
-};
|
|
|
1273
|
+}
|
|
1287
|
1274
|
|
|
1288
|
1275
|
/**
|
|
1289
|
1276
|
* Returns the ice connection state for the peer connection.
|
|
1290
|
1277
|
* @returns the ice connection state for the peer connection.
|
|
1291
|
1278
|
*/
|
|
1292
|
|
-JingleSessionPC.prototype.getIceConnectionState = function () {
|
|
|
1279
|
+getIceConnectionState () {
|
|
1293
|
1280
|
return this.peerconnection.iceConnectionState;
|
|
1294
|
|
-};
|
|
|
1281
|
+}
|
|
1295
|
1282
|
|
|
1296
|
1283
|
/**
|
|
1297
|
1284
|
* Closes the peerconnection.
|
|
1298
|
1285
|
*/
|
|
1299
|
|
-JingleSessionPC.prototype.close = function () {
|
|
|
1286
|
+close () {
|
|
1300
|
1287
|
this.closed = true;
|
|
1301
|
1288
|
// do not try to close if already closed.
|
|
1302
|
1289
|
this.peerconnection
|
|
|
@@ -1305,7 +1292,7 @@ JingleSessionPC.prototype.close = function () {
|
|
1305
|
1292
|
|| (this.peerconnection.connectionState
|
|
1306
|
1293
|
&& this.peerconnection.connectionState !== 'closed'))
|
|
1307
|
1294
|
&& this.peerconnection.close();
|
|
1308
|
|
-};
|
|
|
1295
|
+}
|
|
1309
|
1296
|
|
|
1310
|
1297
|
|
|
1311
|
1298
|
/**
|
|
|
@@ -1314,7 +1301,7 @@ JingleSessionPC.prototype.close = function () {
|
|
1314
|
1301
|
* @param jingle the jingle packet that is going to be sent
|
|
1315
|
1302
|
* @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
1316
|
1303
|
*/
|
|
1317
|
|
-JingleSessionPC.prototype.fixJingle = function(jingle) {
|
|
|
1304
|
+fixJingle (jingle) {
|
|
1318
|
1305
|
var action = $(jingle.nodeTree).find("jingle").attr("action");
|
|
1319
|
1306
|
switch (action) {
|
|
1320
|
1307
|
case "source-add":
|
|
|
@@ -1333,7 +1320,7 @@ JingleSessionPC.prototype.fixJingle = function(jingle) {
|
|
1333
|
1320
|
|
|
1334
|
1321
|
var sources = $(jingle.tree()).find(">jingle>content>description>source");
|
|
1335
|
1322
|
return sources && sources.length > 0;
|
|
1336
|
|
-};
|
|
|
1323
|
+}
|
|
1337
|
1324
|
|
|
1338
|
1325
|
/**
|
|
1339
|
1326
|
* Fixes the outgoing jingle packets with action source-add by removing the
|
|
|
@@ -1341,7 +1328,7 @@ JingleSessionPC.prototype.fixJingle = function(jingle) {
|
|
1341
|
1328
|
* @param jingle the jingle packet that is going to be sent
|
|
1342
|
1329
|
* @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
1343
|
1330
|
*/
|
|
1344
|
|
-JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
|
|
|
1331
|
+fixSourceAddJingle (jingle) {
|
|
1345
|
1332
|
var ssrcs = this.modifiedSSRCs["unmute"];
|
|
1346
|
1333
|
this.modifiedSSRCs["unmute"] = [];
|
|
1347
|
1334
|
if(ssrcs && ssrcs.length) {
|
|
|
@@ -1369,7 +1356,8 @@ JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
|
|
1369
|
1356
|
this.modifiedSSRCs["addMuted"] = [];
|
|
1370
|
1357
|
if(ssrcs && ssrcs.length) {
|
|
1371
|
1358
|
ssrcs.forEach(function (ssrcObj) {
|
|
1372
|
|
- var desc = createDescriptionNode(jingle, ssrcObj.mtype);
|
|
|
1359
|
+ var desc
|
|
|
1360
|
+ = JingleSessionPC.createDescriptionNode(jingle, ssrcObj.mtype);
|
|
1373
|
1361
|
var cname = Math.random().toString(36).substring(2);
|
|
1374
|
1362
|
ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
|
|
1375
|
1363
|
var sourceNode = desc.find(">source[ssrc=\"" +ssrc + "\"]");
|
|
|
@@ -1396,7 +1384,7 @@ JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
|
|
1396
|
1384
|
});
|
|
1397
|
1385
|
});
|
|
1398
|
1386
|
}
|
|
1399
|
|
-};
|
|
|
1387
|
+}
|
|
1400
|
1388
|
|
|
1401
|
1389
|
/**
|
|
1402
|
1390
|
* Fixes the outgoing jingle packets with action source-remove by removing the
|
|
|
@@ -1404,7 +1392,7 @@ JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
|
|
1404
|
1392
|
* @param jingle the jingle packet that is going to be sent
|
|
1405
|
1393
|
* @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
1406
|
1394
|
*/
|
|
1407
|
|
-JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
|
|
|
1395
|
+fixSourceRemoveJingle (jingle) {
|
|
1408
|
1396
|
var ssrcs = this.modifiedSSRCs["mute"];
|
|
1409
|
1397
|
this.modifiedSSRCs["mute"] = [];
|
|
1410
|
1398
|
if(ssrcs && ssrcs.length)
|
|
|
@@ -1428,7 +1416,8 @@ JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
|
|
1428
|
1416
|
this.modifiedSSRCs["remove"] = [];
|
|
1429
|
1417
|
if(ssrcs && ssrcs.length)
|
|
1430
|
1418
|
ssrcs.forEach(function (ssrcObj) {
|
|
1431
|
|
- var desc = createDescriptionNode(jingle, ssrcObj.mtype);
|
|
|
1419
|
+ var desc
|
|
|
1420
|
+ = JingleSessionPC.createDescriptionNode(jingle, ssrcObj.mtype);
|
|
1432
|
1421
|
ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
|
|
1433
|
1422
|
var sourceNode = desc.find(">source[ssrc=\"" +ssrc + "\"]");
|
|
1434
|
1423
|
if(!sourceNode || !sourceNode.length) {
|
|
|
@@ -1451,7 +1440,7 @@ JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
|
|
1451
|
1440
|
}
|
|
1452
|
1441
|
});
|
|
1453
|
1442
|
});
|
|
1454
|
|
-};
|
|
|
1443
|
+}
|
|
1455
|
1444
|
|
|
1456
|
1445
|
/**
|
|
1457
|
1446
|
* Returns the description node related to the passed content type. If the node
|
|
|
@@ -1459,7 +1448,7 @@ JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
|
|
1459
|
1448
|
* @param jingle - the jingle packet
|
|
1460
|
1449
|
* @param mtype - the content type(audio, video, etc.)
|
|
1461
|
1450
|
*/
|
|
1462
|
|
-function createDescriptionNode(jingle, mtype) {
|
|
|
1451
|
+static createDescriptionNode(jingle, mtype) {
|
|
1463
|
1452
|
var content = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
1464
|
1453
|
mtype + "\"]");
|
|
1465
|
1454
|
|
|
|
@@ -1483,7 +1472,7 @@ function createDescriptionNode(jingle, mtype) {
|
|
1483
|
1472
|
/**
|
|
1484
|
1473
|
* Extracts the ice username fragment from an SDP string.
|
|
1485
|
1474
|
*/
|
|
1486
|
|
-function getUfrag(sdp) {
|
|
|
1475
|
+static getUfrag(sdp) {
|
|
1487
|
1476
|
var ufragLines = sdp.split('\n').filter(function(line) {
|
|
1488
|
1477
|
return line.startsWith("a=ice-ufrag:");});
|
|
1489
|
1478
|
if (ufragLines.length > 0) {
|
|
|
@@ -1491,4 +1480,4 @@ function getUfrag(sdp) {
|
|
1491
|
1480
|
}
|
|
1492
|
1481
|
}
|
|
1493
|
1482
|
|
|
1494
|
|
-module.exports = JingleSessionPC;
|
|
|
1483
|
+}
|