Bug 1045643 - Part 1: Notify the Loop server when the desktop client accepts the call, so that it can update the call status. r=nperriault, a=lmandel
authorMark Banner <standard8@mozilla.com>
Fri, 29 Aug 2014 11:22:18 +0100
changeset 216680 be539410c211
parent 216679 062929c9ff5d
child 216681 d820ef3b256d
push id3872
push userryanvm@gmail.com
push date2014-09-08 19:43 +0000
treeherdermozilla-beta@d820ef3b256d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnperriault, lmandel
bugs1045643
milestone33.0
Bug 1045643 - Part 1: Notify the Loop server when the desktop client accepts the call, so that it can update the call status. r=nperriault, a=lmandel
browser/components/loop/content/js/conversation.js
browser/components/loop/content/js/conversation.jsx
browser/components/loop/content/shared/js/websocket.js
browser/components/loop/test/desktop-local/conversation_test.js
browser/components/loop/test/shared/websocket_test.js
browser/components/loop/test/standalone/webapp_test.js
--- a/browser/components/loop/content/js/conversation.js
+++ b/browser/components/loop/content/js/conversation.js
@@ -188,16 +188,17 @@ loop.conversation = (function(OT, mozL10
       }.bind(this));
     },
 
     /**
      * Accepts an incoming call.
      */
     accept: function() {
       window.navigator.mozLoop.stopAlerting();
+      this._websocket.accept();
       this._conversation.incoming();
     },
 
     /**
      * Declines a call and handles closing of the window.
      */
     _declineCall: function() {
       this._websocket.decline();
--- a/browser/components/loop/content/js/conversation.jsx
+++ b/browser/components/loop/content/js/conversation.jsx
@@ -188,16 +188,17 @@ loop.conversation = (function(OT, mozL10
       }.bind(this));
     },
 
     /**
      * Accepts an incoming call.
      */
     accept: function() {
       window.navigator.mozLoop.stopAlerting();
+      this._websocket.accept();
       this._conversation.incoming();
     },
 
     /**
      * Declines a call and handles closing of the window.
      */
     _declineCall: function() {
       this._websocket.decline();
--- a/browser/components/loop/content/shared/js/websocket.js
+++ b/browser/components/loop/content/shared/js/websocket.js
@@ -123,16 +123,26 @@ loop.CallConnectionWebSocket = (function
       this._send({
         messageType: "action",
         event: "terminate",
         reason: "reject"
       });
     },
 
     /**
+     * Notifies the server that the user has accepted the call.
+     */
+    accept: function() {
+      this._send({
+        messageType: "action",
+        event: "accept"
+      });
+    },
+
+    /**
      * Sends data on the websocket.
      *
      * @param {Object} data The data to send.
      */
     _send: function(data) {
       this._log("WS Sending", data);
 
       this.socket.send(JSON.stringify(data));
--- a/browser/components/loop/test/desktop-local/conversation_test.js
+++ b/browser/components/loop/test/desktop-local/conversation_test.js
@@ -32,16 +32,17 @@ describe("loop.conversation", function()
       getStrings: function() {
         return JSON.stringify({textContent: "fakeText"});
       },
       get locale() {
         return "en-US";
       },
       setLoopCharPref: sandbox.stub(),
       getLoopCharPref: sandbox.stub(),
+      getLoopBoolPref: sandbox.stub(),
       startAlerting: function() {},
       stopAlerting: function() {}
     };
 
     // XXX These stubs should be hoisted in a common file
     // Bug 1040968
     document.mozL10n.initialize(navigator.mozLoop);
   });
@@ -296,24 +297,44 @@ describe("loop.conversation", function()
                 done();
               });
             });
           });
         });
       });
 
       describe("#accept", function() {
+        beforeEach(function() {
+          conversation.setSessionData({
+            sessionId:      "sessionId",
+            sessionToken:   "sessionToken",
+            apiKey:         "apiKey",
+            callId:         "Hello",
+            progressURL:    "http://progress.example.com",
+            websocketToken: 123
+          });
+          router._setupWebSocketAndCallView();
+
+          sandbox.stub(router._websocket, "accept");
+          sandbox.stub(navigator.mozLoop, "stopAlerting");
+        });
+
         it("should initiate the conversation", function() {
           router.accept();
 
           sinon.assert.calledOnce(conversation.incoming);
         });
 
+        it("should notify the websocket of the user acceptance", function() {
+          router.accept();
+
+          sinon.assert.calledOnce(router._websocket.accept);
+        });
+
         it("should stop alerting", function() {
-          sandbox.stub(window.navigator.mozLoop, "stopAlerting");
           router.accept();
 
           sinon.assert.calledOnce(window.navigator.mozLoop.stopAlerting);
         });
       });
 
       describe("#conversation", function() {
         beforeEach(function() {
--- a/browser/components/loop/test/shared/websocket_test.js
+++ b/browser/components/loop/test/shared/websocket_test.js
@@ -143,16 +143,30 @@ describe("loop.CallConnectionWebSocket",
         sinon.assert.calledWithExactly(dummySocket.send, JSON.stringify({
           messageType: "action",
           event: "terminate",
           reason: "reject"
         }));
       });
     });
 
+    describe("#accept", function() {
+      it("should send an accept message to the server", function() {
+        callWebSocket.promiseConnect();
+
+        callWebSocket.accept();
+
+        sinon.assert.calledOnce(dummySocket.send);
+        sinon.assert.calledWithExactly(dummySocket.send, JSON.stringify({
+          messageType: "action",
+          event: "accept"
+        }));
+      });
+    });
+
     describe("Events", function() {
       beforeEach(function() {
         sandbox.stub(callWebSocket, "trigger");
 
         callWebSocket.promiseConnect();
       });
 
       describe("Progress", function() {
--- a/browser/components/loop/test/standalone/webapp_test.js
+++ b/browser/components/loop/test/standalone/webapp_test.js
@@ -119,17 +119,17 @@ describe("loop.webapp", function() {
 
         sinon.assert.calledOnce(router._setupWebSocketAndCallView);
         sinon.assert.calledWithExactly(router._setupWebSocketAndCallView, "fake");
       });
     });
 
     describe("#_setupWebSocketAndCallView", function() {
       beforeEach(function() {
-        conversation.setOutgoingSessionData({
+        conversation.setSessionData({
           sessionId:      "sessionId",
           sessionToken:   "sessionToken",
           apiKey:         "apiKey",
           callId:         "Hello",
           progressURL:    "http://progress.example.com",
           websocketToken: 123
         });
       });
@@ -202,17 +202,17 @@ describe("loop.webapp", function() {
               "cannot_start_call_session_not_ready");
             done();
           });
         });
       });
 
       describe("Websocket Events", function() {
         beforeEach(function() {
-          conversation.setOutgoingSessionData({
+          conversation.setSessionData({
             sessionId:      "sessionId",
             sessionToken:   "sessionToken",
             apiKey:         "apiKey",
             callId:         "Hello",
             progressURL:    "http://progress.example.com",
             websocketToken: 123
           });