Bug 1018875 Prevent displaying OT GuM custom dialog. r=Standard8
authorNicolas Perriault <nperriault@mozilla.com>
Thu, 05 Jun 2014 15:51:59 +0200
changeset 187783 ea180661e23b
parent 187782 e8a128be7a6d
child 187784 fa0b0d413edb
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs1018875
milestone32.0a1
Bug 1018875 Prevent displaying OT GuM custom dialog. r=Standard8
browser/components/loop/content/shared/js/views.js
browser/components/loop/test/shared/views_test.js
--- a/browser/components/loop/content/shared/js/views.js
+++ b/browser/components/loop/content/shared/js/views.js
@@ -173,24 +173,37 @@ loop.shared.views = (function(_, OT, l10
      * Publishes remote streams available once a session is connected.
      *
      * http://tokbox.com/opentok/libraries/client/js/reference/SessionConnectEvent.html
      *
      * @param  {SessionConnectEvent} event
      */
     publish: function(event) {
       var outgoing = this.$(".outgoing").get(0);
+
       this.publisher = this.sdk.initPublisher(outgoing, this.videoStyles);
+
+      // Suppress OT GuM custom dialog, see bug 1018875
+      function preventOpeningAccessDialog(event) {
+        event.preventDefault();
+      }
+      this.publisher.on("accessDialogOpened", preventOpeningAccessDialog);
+      this.publisher.on("accessDenied", preventOpeningAccessDialog);
+
       this.model.session.publish(this.publisher);
     },
 
     /**
      * Unpublishes local stream.
      */
     unpublish: function() {
+      // Unregister access OT GuM custom dialog listeners, see bug 1018875
+      this.publisher.off("accessDialogOpened");
+      this.publisher.off("accessDenied");
+
       this.model.session.unpublish(this.publisher);
     },
 
     /**
      * Renders this view.
      *
      * @return {ConversationView}
      */
--- a/browser/components/loop/test/shared/views_test.js
+++ b/browser/components/loop/test/shared/views_test.js
@@ -36,34 +36,38 @@ describe("loop.shared.views", function()
       view.render();
 
       sinon.assert.calledOnce(l10n.translate);
       sinon.assert.calledWithExactly(l10n.translate, view.el);
     });
   });
 
   describe("ConversationView", function() {
-    var fakeSDK, fakeSessionData, fakeSession, model;
+    var fakeSDK, fakeSessionData, fakeSession, fakePublisher, model;
 
     beforeEach(function() {
       fakeSessionData = {
         sessionId:    "sessionId",
         sessionToken: "sessionToken",
         apiKey:       "apiKey"
       };
       fakeSession = _.extend({
         connection: {connectionId: 42},
         connect: sandbox.spy(),
         disconnect: sandbox.spy(),
         publish: sandbox.spy(),
         unpublish: sandbox.spy(),
         subscribe: sandbox.spy()
       }, Backbone.Events);
+      fakePublisher = {
+        on: sandbox.spy(),
+        off: sandbox.spy()
+      };
       fakeSDK = {
-        initPublisher: sandbox.spy(),
+        initPublisher: sandbox.stub().returns(fakePublisher),
         initSession: sandbox.stub().returns(fakeSession)
       };
       model = new sharedModels.ConversationModel(fakeSessionData, {
         sdk: fakeSDK
       });
     });
 
     describe("#initialize", function() {
@@ -85,48 +89,77 @@ describe("loop.shared.views", function()
     describe("constructed", function() {
       describe("#hangup", function() {
         it("should disconnect the session", function() {
           var view = new sharedViews.ConversationView({
             sdk: fakeSDK,
             model: model
           });
           sandbox.stub(model, "endSession");
+          view.publish();
 
           view.hangup({preventDefault: function() {}});
 
           sinon.assert.calledOnce(model.endSession);
         });
       });
 
       describe("#publish", function() {
-        it("should publish local stream", function() {
-          var view = new sharedViews.ConversationView({
+        var view;
+
+        beforeEach(function() {
+          view = new sharedViews.ConversationView({
             sdk: fakeSDK,
             model: model
           });
+        });
 
+        it("should publish local stream", function() {
           view.publish();
 
           sinon.assert.calledOnce(fakeSDK.initPublisher);
           sinon.assert.calledOnce(fakeSession.publish);
         });
+
+        it("should start listening to OT publisher accessDialogOpened and " +
+          " accessDenied events",
+          function() {
+            view.publish();
+
+            sinon.assert.calledTwice(fakePublisher.on);
+            sinon.assert.calledWith(fakePublisher.on, "accessDialogOpened");
+            sinon.assert.calledWith(fakePublisher.on, "accessDenied");
+          });
       });
 
       describe("#unpublish", function() {
-        it("should unpublish local stream", function() {
-          var view = new sharedViews.ConversationView({
+        var view;
+
+        beforeEach(function() {
+          view = new sharedViews.ConversationView({
             sdk: fakeSDK,
             model: model
           });
+          view.publish();
+        });
 
+        it("should unpublish local stream", function() {
           view.unpublish();
 
           sinon.assert.calledOnce(fakeSession.unpublish);
         });
+
+        it("should unsubscribe from accessDialogOpened and accessDenied events",
+          function() {
+            view.unpublish();
+
+            sinon.assert.calledTwice(fakePublisher.off);
+            sinon.assert.calledWith(fakePublisher.off, "accessDialogOpened");
+            sinon.assert.calledWith(fakePublisher.off, "accessDenied");
+          });
       });
 
       describe("Model events", function() {
         var view;
 
         beforeEach(function() {
           sandbox.stub(sharedViews.ConversationView.prototype, "publish");
           sandbox.stub(sharedViews.ConversationView.prototype, "unpublish");