|
@@ -648,23 +648,15 @@ export default class JingleSessionPC extends JingleSession {
|
648
|
648
|
* error {string}
|
649
|
649
|
* @private
|
650
|
650
|
*/
|
651
|
|
- _renegotiate(optionalRemoteSdp) {
|
|
651
|
+ async _renegotiate(optionalRemoteSdp) {
|
652
|
652
|
if (this.peerconnection.signalingState === 'closed') {
|
653
|
|
- const error = new Error('Attempted to renegotiate in state closed');
|
654
|
|
-
|
655
|
|
- this.room.eventEmitter.emit(XMPPEvents.RENEGOTIATION_FAILED, error, this);
|
656
|
|
-
|
657
|
|
- return Promise.reject(error);
|
|
653
|
+ throw new Error('Attempted to renegotiate in state closed');
|
658
|
654
|
}
|
659
|
655
|
|
660
|
656
|
const remoteSdp = optionalRemoteSdp || this.peerconnection.remoteDescription.sdp;
|
661
|
657
|
|
662
|
658
|
if (!remoteSdp) {
|
663
|
|
- const error = new Error(`Can not renegotiate without remote description, current state: ${this.state}`);
|
664
|
|
-
|
665
|
|
- this.room.eventEmitter.emit(XMPPEvents.RENEGOTIATION_FAILED, error, this);
|
666
|
|
-
|
667
|
|
- return Promise.reject(error);
|
|
659
|
+ throw new Error(`Cannot renegotiate without remote description, state=${this.state}`);
|
668
|
660
|
}
|
669
|
661
|
|
670
|
662
|
const remoteDescription = {
|
|
@@ -676,23 +668,21 @@ export default class JingleSessionPC extends JingleSession {
|
676
|
668
|
|
677
|
669
|
logger.debug(`${this} Renegotiate: setting remote description`);
|
678
|
670
|
|
679
|
|
- return this.peerconnection.setRemoteDescription(remoteDescription)
|
680
|
|
- .then(() => {
|
681
|
|
- logger.debug(`${this} Renegotiate: creating answer`);
|
682
|
|
-
|
683
|
|
- return this.peerconnection.createAnswer(this.mediaConstraints);
|
684
|
|
- })
|
685
|
|
- .then(answer => {
|
686
|
|
- logger.debug(`${this} Renegotiate: setting local description`);
|
|
671
|
+ try {
|
|
672
|
+ await this.peerconnection.setRemoteDescription(remoteDescription);
|
|
673
|
+ logger.debug(`${this} Renegotiate: creating answer`);
|
|
674
|
+ const answer = await this.peerconnection.createAnswer(this.mediaConstraints);
|
687
|
675
|
|
688
|
|
- return this.peerconnection.setLocalDescription(answer);
|
689
|
|
- })
|
690
|
|
- .then(() => {
|
691
|
|
- if (oldLocalSDP) {
|
692
|
|
- // Send the source updates after every renegotiation cycle.
|
693
|
|
- this.notifyMySSRCUpdate(new SDP(oldLocalSDP), new SDP(this.peerconnection.localDescription.sdp));
|
694
|
|
- }
|
695
|
|
- });
|
|
676
|
+ logger.debug(`${this} Renegotiate: setting local description`);
|
|
677
|
+ await this.peerconnection.setLocalDescription(answer);
|
|
678
|
+ if (oldLocalSDP) {
|
|
679
|
+ // Send the source updates after every renegotiation cycle.
|
|
680
|
+ this.notifyMySSRCUpdate(new SDP(oldLocalSDP), new SDP(this.peerconnection.localDescription.sdp));
|
|
681
|
+ }
|
|
682
|
+ } catch (error) {
|
|
683
|
+ logger.error(`${this} Renegotiate failed:`, error);
|
|
684
|
+ throw error;
|
|
685
|
+ }
|
696
|
686
|
}
|
697
|
687
|
|
698
|
688
|
/**
|
|
@@ -1543,9 +1533,9 @@ export default class JingleSessionPC extends JingleSession {
|
1543
|
1533
|
*
|
1544
|
1534
|
* @param {Array<JitsiLocalTrack>} localTracks the local tracks that will be added, before the offer/answer cycle
|
1545
|
1535
|
* executes (for the local track addition to be an atomic operation together with the offer/answer).
|
1546
|
|
- * @returns {void}
|
|
1536
|
+ * @returns {Promise<void>} that resolves when the offer is sent to the remote peer, rejected otherwise.
|
1547
|
1537
|
*/
|
1548
|
|
- invite(localTracks = []) {
|
|
1538
|
+ async invite(localTracks = []) {
|
1549
|
1539
|
if (!this.isInitiator) {
|
1550
|
1540
|
throw new Error('Trying to invite from the responder session');
|
1551
|
1541
|
}
|
|
@@ -1557,19 +1547,19 @@ export default class JingleSessionPC extends JingleSession {
|
1557
|
1547
|
addTracks.push(this.peerconnection.addTrack(track, this.isInitiator));
|
1558
|
1548
|
}
|
1559
|
1549
|
|
1560
|
|
- Promise.all(addTracks)
|
1561
|
|
- .then(() => this.peerconnection.createOffer(this.mediaConstraints))
|
1562
|
|
- .then(offerSdp => this.peerconnection.setLocalDescription(offerSdp))
|
1563
|
|
- .then(() => {
|
1564
|
|
- this.peerconnection.processLocalSdpForTransceiverInfo(localTracks);
|
1565
|
|
- this._sendSessionInitiate(this.peerconnection.localDescription.sdp);
|
1566
|
|
- })
|
1567
|
|
- .then(() => {
|
1568
|
|
- logger.debug(`${this} invite executed - OK`);
|
1569
|
|
- })
|
1570
|
|
- .catch(error => {
|
1571
|
|
- logger.error(`${this} invite error`, error);
|
1572
|
|
- });
|
|
1550
|
+ try {
|
|
1551
|
+ await Promise.all(addTracks);
|
|
1552
|
+ const offerSdp = await this.peerconnection.createOffer(this.mediaConstraints);
|
|
1553
|
+
|
|
1554
|
+ await this.peerconnection.setLocalDescription(offerSdp);
|
|
1555
|
+ this.peerconnection.processLocalSdpForTransceiverInfo(localTracks);
|
|
1556
|
+ this._sendSessionInitiate(this.peerconnection.localDescription.sdp);
|
|
1557
|
+
|
|
1558
|
+ logger.debug(`${this} invite executed - OK`);
|
|
1559
|
+ } catch (error) {
|
|
1560
|
+ logger.error(`${this} invite error`, error);
|
|
1561
|
+ throw error;
|
|
1562
|
+ }
|
1573
|
1563
|
}
|
1574
|
1564
|
|
1575
|
1565
|
/**
|
|
@@ -2070,10 +2060,9 @@ export default class JingleSessionPC extends JingleSession {
|
2070
|
2060
|
* Sets the answer received from the remote peer as the remote description.
|
2071
|
2061
|
*
|
2072
|
2062
|
* @param {Element} jingleAnswer - The jingle answer element.
|
2073
|
|
- * @returns {void}
|
2074
|
|
- * @throws {Error} if the method is called on a responder session.
|
|
2063
|
+ * @returns {Promise<void>} that resolves when the answer is set as the remote description, rejected otherwise.
|
2075
|
2064
|
*/
|
2076
|
|
- setAnswer(jingleAnswer) {
|
|
2065
|
+ async setAnswer(jingleAnswer) {
|
2077
|
2066
|
if (!this.isInitiator) {
|
2078
|
2067
|
throw new Error('Trying to set an answer on the responder session');
|
2079
|
2068
|
}
|
|
@@ -2086,26 +2075,24 @@ export default class JingleSessionPC extends JingleSession {
|
2086
|
2075
|
sdp: newRemoteSdp.raw
|
2087
|
2076
|
};
|
2088
|
2077
|
|
2089
|
|
- this.peerconnection.setRemoteDescription(remoteDescription)
|
2090
|
|
- .then(() => {
|
2091
|
|
- if (this.state === JingleSessionState.PENDING) {
|
2092
|
|
- this.state = JingleSessionState.ACTIVE;
|
|
2078
|
+ try {
|
|
2079
|
+ await this.peerconnection.setRemoteDescription(remoteDescription);
|
|
2080
|
+ if (this.state === JingleSessionState.PENDING) {
|
|
2081
|
+ this.state = JingleSessionState.ACTIVE;
|
2093
|
2082
|
|
2094
|
|
- // Start processing tasks on the modification queue.
|
2095
|
|
- logger.debug(`${this} Resuming the modification queue after session is established!`);
|
2096
|
|
- this.modificationQueue.resume();
|
2097
|
|
- const newLocalSdp = new SDP(this.peerconnection.localDescription.sdp);
|
|
2083
|
+ // Start processing tasks on the modification queue.
|
|
2084
|
+ logger.debug(`${this} Resuming the modification queue after session is established!`);
|
|
2085
|
+ this.modificationQueue.resume();
|
|
2086
|
+ const newLocalSdp = new SDP(this.peerconnection.localDescription.sdp);
|
2098
|
2087
|
|
2099
|
|
- this._sendContentModify();
|
2100
|
|
- this.notifyMySSRCUpdate(oldLocalSdp, newLocalSdp);
|
2101
|
|
- }
|
2102
|
|
- })
|
2103
|
|
- .then(() => {
|
2104
|
|
- logger.debug(`${this} setAnswer task done`);
|
2105
|
|
- })
|
2106
|
|
- .catch(error => {
|
2107
|
|
- logger.error(`${this} setAnswer task failed: ${error}`);
|
2108
|
|
- });
|
|
2088
|
+ this._sendContentModify();
|
|
2089
|
+ this.notifyMySSRCUpdate(oldLocalSdp, newLocalSdp);
|
|
2090
|
+ }
|
|
2091
|
+ logger.debug(`${this} setAnswer task done`);
|
|
2092
|
+ } catch (error) {
|
|
2093
|
+ logger.error(`${this} setAnswer task failed: ${error}`);
|
|
2094
|
+ throw error;
|
|
2095
|
+ }
|
2109
|
2096
|
}
|
2110
|
2097
|
|
2111
|
2098
|
/**
|