Bug 834153 - Queue CreateAnswer State Checks, remove extraneous _executeNext calls. r=jesup
authorAdam Roach [:abr] <adam@nostrum.com>
Thu, 24 Jan 2013 21:44:30 -0600
changeset 119875 e4e3590aa1daf8e92b1d132a625e644a4ab8f638
parent 119874 f28ae1d9b685f1f1fb1ffd4a1dc78eb136a3b4a9
child 119876 5a2c4f450e07f554f5fddd8535ecb174b776544c
push id1317
push userryanvm@gmail.com
push dateSun, 27 Jan 2013 02:21:57 +0000
treeherderfx-team@47684913d63d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs834153
milestone21.0a1
Bug 834153 - Queue CreateAnswer State Checks, remove extraneous _executeNext calls. r=jesup
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -430,44 +430,65 @@ PeerConnection.prototype = {
 
     this._queueOrRun({
       func: this._pc.createOffer,
       args: [constraints],
       wait: true
     });
   },
 
-  createAnswer: function(onSuccess, onError, constraints, provisional) {
+  _createAnswer: function(onSuccess, onError, constraints, provisional) {
+    this._onCreateAnswerSuccess = onSuccess;
+    this._onCreateAnswerFailure = onError;
+
     if (!this.remoteDescription) {
-      throw new Error("setRemoteDescription not called");
+      this._observer.onCreateAnswerError(3); // PC_INVALID_REMOTE_SDP
+      /*
+        This needs to be matched to spec -- see bug 834270. The final
+        code will be of the form:
+
+      this._observer.onCreateAnswerError(ci.IPeerConnection.kInvalidState,
+                                         "setRemoteDescription not called");
+      */
+      return;
     }
 
     if (this.remoteDescription.type != "offer") {
-      throw new Error("No outstanding offer");
+      this._observer.onCreateAnswerError(3); // PC_INVALID_REMOTE_SDP
+      /*
+        This needs to be matched to spec -- see bug 834270. The final
+        code will be of the form:
+
+      this._observer.onCreateAnswerError(ci.IPeerConnection.kInvalidState,
+                                         "No outstanding offer");
+      */
+      return;
     }
 
+    // TODO: Implement provisional answer.
+
+    this._pc.createAnswer(constraints);
+  },
+
+  createAnswer: function(onSuccess, onError, constraints, provisional) {
     if (!constraints) {
       constraints = {};
     }
 
     if (!this._validateConstraints(constraints)) {
       throw new Error("createAnswer passed invalid constraints");
     }
 
-    this._onCreateAnswerSuccess = onSuccess;
-    this._onCreateAnswerFailure = onError;
-
     if (!provisional) {
       provisional = false;
     }
 
-    // TODO: Implement provisional answer.
     this._queueOrRun({
-      func: this._pc.createAnswer,
-      args: [constraints],
+      func: this._createAnswer,
+      args: [onSuccess, onError, constraints, provisional],
       wait: true
     });
   },
 
   setLocalDescription: function(desc, onSuccess, onError) {
     // TODO -- if we have two setLocalDescriptions in the
     // queue,this code overwrites the callbacks for the first
     // one with the callbacks for the second one. See Bug 831759.
@@ -765,23 +786,21 @@ PeerConnectionObserver.prototype = {
         iceGatherCb("gathering");
         break;
       case Ci.IPeerConnection.kIceWaiting:
         iceCb("starting");
         this._dompc._executeNext();
         break;
       case Ci.IPeerConnection.kIceChecking:
         iceCb("checking");
-        this._dompc._executeNext();
         break;
       case Ci.IPeerConnection.kIceConnected:
         // ICE gathering complete.
         iceCb("connected");
         iceGatherCb("complete");
-        this._dompc._executeNext();
         break;
       case Ci.IPeerConnection.kIceFailed:
         iceCb("failed");
         break;
       default:
         // Unknown state!
         break;
     }
@@ -791,66 +810,60 @@ PeerConnectionObserver.prototype = {
     if (this._dompc.onaddstream) {
       try {
         this._dompc.onaddstream.onCallback({
           stream: stream, type: type,
           __exposedProps__: { stream: "r", type: "r" }
         });
       } catch(e) {}
     }
-    this._dompc._executeNext();
   },
 
   onRemoveStream: function(stream, type) {
     if (this._dompc.onremovestream) {
       try {
         this._dompc.onremovestream.onCallback({
           stream: stream, type: type,
           __exposedProps__: { stream: "r", type: "r" }
         });
       } catch(e) {}
     }
-    this._dompc._executeNext();
   },
 
   foundIceCandidate: function(cand) {
     if (this._dompc.onicecandidate) {
       try {
         this._dompc.onicecandidate.onCallback({
           candidate: cand,
           __exposedProps__: { candidate: "rw" }
         });
       } catch(e) {}
     }
-    this._dompc._executeNext();
   },
 
   notifyDataChannel: function(channel) {
     if (this._dompc.ondatachannel) {
       try {
         this._dompc.ondatachannel.onCallback(channel);
       } catch(e) {}
     }
-    this._dompc._executeNext();
   },
 
   notifyConnection: function() {
     if (this._dompc.onconnection) {
       try {
         this._dompc.onconnection.onCallback();
       } catch(e) {}
     }
-    this._dompc._executeNext();
   },
 
   notifyClosedConnection: function() {
     if (this._dompc.onclosedconnection) {
       try {
         this._dompc.onclosedconnection.onCallback();
       } catch(e) {}
     }
-    this._dompc._executeNext();
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
   [GlobalPCList, IceCandidate, SessionDescription, PeerConnection]
 );