Bug 1332826: return error when calling addIceCandidate before setRemoteDescription. r?jib
MozReview-Commit-ID: LYeDkr5G7Tx
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1032,21 +1032,28 @@ class RTCPeerConnection {
async _addIceCandidate({ candidate, sdpMid, sdpMLineIndex }) {
this._checkClosed();
if (sdpMid === null && sdpMLineIndex === null) {
throw new this._win.DOMException(
"Invalid candidate (both sdpMid and sdpMLineIndex are null).",
"TypeError");
}
- return await this._chain(() => new Promise((resolve, reject) => {
- this._onAddIceCandidateSuccess = resolve;
- this._onAddIceCandidateError = reject;
- this._impl.addIceCandidate(candidate, sdpMid || "", sdpMLineIndex);
- }));
+ return await this._chain(() => {
+ if (!this.remoteDescription) {
+ throw new this._win.DOMException(
+ "setRemoteDescription needs to called before addIceCandidate",
+ "InvalidStateError");
+ }
+ return new Promise((resolve, reject) => {
+ this._onAddIceCandidateSuccess = resolve;
+ this._onAddIceCandidateError = reject;
+ this._impl.addIceCandidate(candidate, sdpMid || "", sdpMLineIndex);
+ });
+ });
}
addStream(stream) {
stream.getTracks().forEach(track => this.addTrack(track, stream));
}
addTrack(track, stream) {
if (stream.currentTime === undefined) {