|
@@ -1686,10 +1686,7 @@ TraceablePeerConnection.prototype._adjustLocalMediaDirection = function(
|
1686
|
1686
|
return localDescription;
|
1687
|
1687
|
};
|
1688
|
1688
|
|
1689
|
|
-TraceablePeerConnection.prototype.setLocalDescription = function(
|
1690
|
|
- description,
|
1691
|
|
- successCallback,
|
1692
|
|
- failureCallback) {
|
|
1689
|
+TraceablePeerConnection.prototype.setLocalDescription = function(description) {
|
1693
|
1690
|
let localSdp = description;
|
1694
|
1691
|
|
1695
|
1692
|
this.trace('setLocalDescription::preTransform', dumpSDP(localSdp));
|
|
@@ -1725,26 +1722,27 @@ TraceablePeerConnection.prototype.setLocalDescription = function(
|
1725
|
1722
|
dumpSDP(localSdp));
|
1726
|
1723
|
}
|
1727
|
1724
|
|
1728
|
|
- this.peerconnection.setLocalDescription(localSdp,
|
1729
|
|
- () => {
|
1730
|
|
- this.trace('setLocalDescriptionOnSuccess');
|
1731
|
|
- const localUfrag = SDPUtil.getUfrag(localSdp.sdp);
|
|
1725
|
+ return new Promise((resolve, reject) => {
|
|
1726
|
+ this.peerconnection.setLocalDescription(localSdp)
|
|
1727
|
+ .then(() => {
|
|
1728
|
+ this.trace('setLocalDescriptionOnSuccess');
|
|
1729
|
+ const localUfrag = SDPUtil.getUfrag(localSdp.sdp);
|
1732
|
1730
|
|
1733
|
|
- if (localUfrag !== this.localUfrag) {
|
1734
|
|
- this.localUfrag = localUfrag;
|
|
1731
|
+ if (localUfrag !== this.localUfrag) {
|
|
1732
|
+ this.localUfrag = localUfrag;
|
|
1733
|
+ this.eventEmitter.emit(
|
|
1734
|
+ RTCEvents.LOCAL_UFRAG_CHANGED, this, localUfrag);
|
|
1735
|
+ }
|
|
1736
|
+ resolve();
|
|
1737
|
+ })
|
|
1738
|
+ .catch(err => {
|
|
1739
|
+ this.trace('setLocalDescriptionOnFailure', err);
|
1735
|
1740
|
this.eventEmitter.emit(
|
1736
|
|
- RTCEvents.LOCAL_UFRAG_CHANGED, this, localUfrag);
|
1737
|
|
- }
|
1738
|
|
- successCallback();
|
1739
|
|
- },
|
1740
|
|
- err => {
|
1741
|
|
- this.trace('setLocalDescriptionOnFailure', err);
|
1742
|
|
- this.eventEmitter.emit(
|
1743
|
|
- RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
|
1744
|
|
- err, this);
|
1745
|
|
- failureCallback(err);
|
1746
|
|
- }
|
1747
|
|
- );
|
|
1741
|
+ RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
|
|
1742
|
+ err, this);
|
|
1743
|
+ reject(err);
|
|
1744
|
+ });
|
|
1745
|
+ });
|
1748
|
1746
|
};
|
1749
|
1747
|
|
1750
|
1748
|
/**
|
|
@@ -1810,10 +1808,7 @@ TraceablePeerConnection.prototype._insertUnifiedPlanSimulcastReceive
|
1810
|
1808
|
});
|
1811
|
1809
|
};
|
1812
|
1810
|
|
1813
|
|
-TraceablePeerConnection.prototype.setRemoteDescription = function(
|
1814
|
|
- description,
|
1815
|
|
- successCallback,
|
1816
|
|
- failureCallback) {
|
|
1811
|
+TraceablePeerConnection.prototype.setRemoteDescription = function(description) {
|
1817
|
1812
|
this.trace('setRemoteDescription::preTransform', dumpSDP(description));
|
1818
|
1813
|
|
1819
|
1814
|
// TODO the focus should squeze or explode the remote simulcast
|
|
@@ -1876,27 +1871,28 @@ TraceablePeerConnection.prototype.setRemoteDescription = function(
|
1876
|
1871
|
description = this._injectH264IfNotPresent(description);
|
1877
|
1872
|
}
|
1878
|
1873
|
|
1879
|
|
- this.peerconnection.setRemoteDescription(
|
1880
|
|
- description,
|
1881
|
|
- () => {
|
1882
|
|
- this.trace('setRemoteDescriptionOnSuccess');
|
1883
|
|
- const remoteUfrag = SDPUtil.getUfrag(description.sdp);
|
|
1874
|
+ return new Promise((resolve, reject) => {
|
|
1875
|
+ this.peerconnection.setRemoteDescription(description)
|
|
1876
|
+ .then(() => {
|
|
1877
|
+ this.trace('setRemoteDescriptionOnSuccess');
|
|
1878
|
+ const remoteUfrag = SDPUtil.getUfrag(description.sdp);
|
1884
|
1879
|
|
1885
|
|
- if (remoteUfrag !== this.remoteUfrag) {
|
1886
|
|
- this.remoteUfrag = remoteUfrag;
|
|
1880
|
+ if (remoteUfrag !== this.remoteUfrag) {
|
|
1881
|
+ this.remoteUfrag = remoteUfrag;
|
|
1882
|
+ this.eventEmitter.emit(
|
|
1883
|
+ RTCEvents.REMOTE_UFRAG_CHANGED, this, remoteUfrag);
|
|
1884
|
+ }
|
|
1885
|
+ resolve();
|
|
1886
|
+ })
|
|
1887
|
+ .catch(err => {
|
|
1888
|
+ this.trace('setRemoteDescriptionOnFailure', err);
|
1887
|
1889
|
this.eventEmitter.emit(
|
1888
|
|
- RTCEvents.REMOTE_UFRAG_CHANGED, this, remoteUfrag);
|
1889
|
|
- }
|
1890
|
|
- successCallback();
|
1891
|
|
- },
|
1892
|
|
- err => {
|
1893
|
|
- this.trace('setRemoteDescriptionOnFailure', err);
|
1894
|
|
- this.eventEmitter.emit(
|
1895
|
|
- RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
|
1896
|
|
- err,
|
1897
|
|
- this);
|
1898
|
|
- failureCallback(err);
|
1899
|
|
- });
|
|
1890
|
+ RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
|
|
1891
|
+ err,
|
|
1892
|
+ this);
|
|
1893
|
+ reject(err);
|
|
1894
|
+ });
|
|
1895
|
+ });
|
1900
|
1896
|
};
|
1901
|
1897
|
|
1902
|
1898
|
/**
|
|
@@ -2104,10 +2100,7 @@ const _fixAnswerRFC4145Setup = function(offer, answer) {
|
2104
|
2100
|
}
|
2105
|
2101
|
};
|
2106
|
2102
|
|
2107
|
|
-TraceablePeerConnection.prototype.createAnswer = function(
|
2108
|
|
- successCallback,
|
2109
|
|
- failureCallback,
|
2110
|
|
- constraints) {
|
|
2103
|
+TraceablePeerConnection.prototype.createAnswer = function(constraints) {
|
2111
|
2104
|
if (browser.supportsRtpSender() && this.isSimulcastOn()) {
|
2112
|
2105
|
const videoSender
|
2113
|
2106
|
= this.peerconnection.getSenders().find(sender =>
|
|
@@ -2130,30 +2123,22 @@ TraceablePeerConnection.prototype.createAnswer = function(
|
2130
|
2123
|
|
2131
|
2124
|
videoSender.setParameters(simParams);
|
2132
|
2125
|
}
|
2133
|
|
- this._createOfferOrAnswer(
|
2134
|
|
- false /* answer */, successCallback, failureCallback, constraints);
|
2135
|
|
-};
|
2136
|
2126
|
|
2137
|
|
-TraceablePeerConnection.prototype.createOffer = function(
|
2138
|
|
- successCallback,
|
2139
|
|
- failureCallback,
|
2140
|
|
- constraints) {
|
2141
|
|
- this._createOfferOrAnswer(
|
2142
|
|
- true /* offer */, successCallback, failureCallback, constraints);
|
|
2127
|
+ return this._createOfferOrAnswer(false /* answer */, constraints);
|
2143
|
2128
|
};
|
2144
|
2129
|
|
2145
|
|
-/* eslint-disable max-params */
|
|
2130
|
+TraceablePeerConnection.prototype.createOffer = function(constraints) {
|
|
2131
|
+ return this._createOfferOrAnswer(true /* offer */, constraints);
|
|
2132
|
+};
|
2146
|
2133
|
|
2147
|
2134
|
TraceablePeerConnection.prototype._createOfferOrAnswer = function(
|
2148
|
2135
|
isOffer,
|
2149
|
|
- successCallback,
|
2150
|
|
- failureCallback,
|
2151
|
2136
|
constraints) {
|
2152
|
2137
|
const logName = isOffer ? 'Offer' : 'Answer';
|
2153
|
2138
|
|
2154
|
2139
|
this.trace(`create${logName}`, JSON.stringify(constraints, null, ' '));
|
2155
|
2140
|
|
2156
|
|
- const _successCallback = resultSdp => {
|
|
2141
|
+ const handleSuccess = (resultSdp, resolveFn, rejectFn) => {
|
2157
|
2142
|
try {
|
2158
|
2143
|
this.trace(
|
2159
|
2144
|
`create${logName}OnSuccess::preTransform`, dumpSDP(resultSdp));
|
|
@@ -2206,7 +2191,6 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
|
2206
|
2191
|
|
2207
|
2192
|
// Add simulcast streams if simulcast is enabled
|
2208
|
2193
|
if (this.isSimulcastOn()) {
|
2209
|
|
-
|
2210
|
2194
|
// eslint-disable-next-line no-param-reassign
|
2211
|
2195
|
resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
|
2212
|
2196
|
this.trace(
|
|
@@ -2249,16 +2233,17 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
|
2249
|
2233
|
logger.debug('Got local SSRCs MAP: ', ssrcMap);
|
2250
|
2234
|
this._processLocalSSRCsMap(ssrcMap);
|
2251
|
2235
|
|
2252
|
|
- successCallback(resultSdp);
|
|
2236
|
+ resolveFn(resultSdp);
|
2253
|
2237
|
} catch (e) {
|
2254
|
2238
|
this.trace(`create${logName}OnError`, e);
|
2255
|
2239
|
this.trace(`create${logName}OnError`, dumpSDP(resultSdp));
|
2256
|
2240
|
logger.error(`create${logName}OnError`, e, dumpSDP(resultSdp));
|
2257
|
|
- failureCallback(e);
|
|
2241
|
+
|
|
2242
|
+ rejectFn(e);
|
2258
|
2243
|
}
|
2259
|
2244
|
};
|
2260
|
2245
|
|
2261
|
|
- const _errorCallback = err => {
|
|
2246
|
+ const handleFailure = (err, rejectFn) => {
|
2262
|
2247
|
this.trace(`create${logName}OnFailure`, err);
|
2263
|
2248
|
const eventType
|
2264
|
2249
|
= isOffer
|
|
@@ -2266,19 +2251,24 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
|
2266
|
2251
|
: RTCEvents.CREATE_ANSWER_FAILED;
|
2267
|
2252
|
|
2268
|
2253
|
this.eventEmitter.emit(eventType, err, this);
|
2269
|
|
- failureCallback(err);
|
|
2254
|
+
|
|
2255
|
+ rejectFn(err);
|
2270
|
2256
|
};
|
2271
|
2257
|
|
2272
|
|
- if (isOffer) {
|
2273
|
|
- this.peerconnection.createOffer(
|
2274
|
|
- _successCallback, _errorCallback, constraints);
|
2275
|
|
- } else {
|
2276
|
|
- this.peerconnection.createAnswer(
|
2277
|
|
- _successCallback, _errorCallback, constraints);
|
2278
|
|
- }
|
2279
|
|
-};
|
|
2258
|
+ return new Promise((resolve, reject) => {
|
|
2259
|
+ let oaPromise;
|
2280
|
2260
|
|
2281
|
|
-/* eslint-enable max-params */
|
|
2261
|
+ if (isOffer) {
|
|
2262
|
+ oaPromise = this.peerconnection.createOffer(constraints);
|
|
2263
|
+ } else {
|
|
2264
|
+ oaPromise = this.peerconnection.createAnswer(constraints);
|
|
2265
|
+ }
|
|
2266
|
+
|
|
2267
|
+ oaPromise
|
|
2268
|
+ .then(sdp => handleSuccess(sdp, resolve, reject))
|
|
2269
|
+ .catch(error => handleFailure(error, reject));
|
|
2270
|
+ });
|
|
2271
|
+};
|
2282
|
2272
|
|
2283
|
2273
|
/**
|
2284
|
2274
|
* Extract primary SSRC from given {@link TrackSSRCInfo} object.
|
|
@@ -2344,18 +2334,15 @@ TraceablePeerConnection.prototype._processLocalSSRCsMap = function(ssrcMap) {
|
2344
|
2334
|
}
|
2345
|
2335
|
};
|
2346
|
2336
|
|
2347
|
|
-TraceablePeerConnection.prototype.addIceCandidate = function(
|
2348
|
|
- candidate,
|
2349
|
|
- successCallback,
|
2350
|
|
- failureCallback) {
|
|
2337
|
+TraceablePeerConnection.prototype.addIceCandidate = function(candidate) {
|
2351
|
2338
|
this.trace('addIceCandidate', JSON.stringify({
|
2352
|
2339
|
candidate: candidate.candidate,
|
2353
|
2340
|
sdpMid: candidate.sdpMid,
|
2354
|
2341
|
sdpMLineIndex: candidate.sdpMLineIndex,
|
2355
|
2342
|
usernameFragment: candidate.usernameFragment
|
2356
|
2343
|
}, null, ' '));
|
2357
|
|
- this.peerconnection.addIceCandidate(
|
2358
|
|
- candidate, successCallback, failureCallback);
|
|
2344
|
+
|
|
2345
|
+ return this.peerconnection.addIceCandidate(candidate);
|
2359
|
2346
|
};
|
2360
|
2347
|
|
2361
|
2348
|
/**
|