Bug 1033579 - Add channel to POST calls for Loop to allow different servers based on the channel. r=dmose a=lmandel
authorAdam Roach [:abr] <adam@nostrum.com>
Thu, 23 Oct 2014 20:37:58 +0100
changeset 225825 d43a7b8995a6
parent 225824 45d717da277d
child 225826 080cfa7f5d79
push id4027
push userrjesup@wgate.com
push date2014-10-26 23:18 +0000
treeherdermozilla-beta@080cfa7f5d79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmose, lmandel
bugs1033579
milestone34.0
Bug 1033579 - Add channel to POST calls for Loop to allow different servers based on the channel. r=dmose a=lmandel
browser/components/loop/content/js/client.js
browser/components/loop/standalone/content/js/standaloneClient.js
browser/components/loop/test/desktop-local/client_test.js
browser/components/loop/test/standalone/standalone_client_test.js
--- a/browser/components/loop/content/js/client.js
+++ b/browser/components/loop/content/js/client.js
@@ -227,17 +227,19 @@ loop.Client = (function($) {
      * @param {Function} cb Callback(err, result)
      */
     setupOutgoingCall: function(calleeIds, callType, cb) {
       // For direct calls, we only ever use the logged-in session. Direct
       // calls by guests aren't valid.
       this.mozLoop.hawkRequest(this.mozLoop.LOOP_SESSION_TYPE.FXA,
         "/calls", "POST", {
           calleeId: calleeIds,
-          callType: callType
+          callType: callType,
+          channel: this.mozLoop.appVersionInfo ?
+                   this.mozLoop.appVersionInfo.channel : "unknown"
         },
         function (err, responseText) {
           if (err) {
             this._failureHandler(cb, err);
             return;
           }
 
           try {
--- a/browser/components/loop/standalone/content/js/standaloneClient.js
+++ b/browser/components/loop/standalone/content/js/standaloneClient.js
@@ -110,17 +110,17 @@ loop.StandaloneClient = (function($) {
         throw new Error("missing required parameter loopToken");
       }
 
       var req = $.ajax({
         url:         this.settings.baseServerUrl + "/calls/" + loopToken,
         method:      "POST",
         contentType: "application/json",
         dataType:    "json",
-        data: JSON.stringify({callType: callType})
+        data: JSON.stringify({callType: callType, channel: "standalone"})
       });
 
       req.done(function(sessionData) {
         try {
           cb(null, this._validate(sessionData, expectedCallsProperties));
         } catch (err) {
           console.error("Error requesting call info", err.message);
           cb(err);
--- a/browser/components/loop/test/desktop-local/client_test.js
+++ b/browser/components/loop/test/desktop-local/client_test.js
@@ -267,17 +267,33 @@ describe("loop.Client", function() {
       it("should make a POST call to /calls", function() {
         client.setupOutgoingCall(calleeIds, callType);
 
         sinon.assert.calledOnce(hawkRequestStub);
         sinon.assert.calledWith(hawkRequestStub,
           mozLoop.LOOP_SESSION_TYPE.FXA,
           "/calls",
           "POST",
-          { calleeId: calleeIds, callType: callType }
+          { calleeId: calleeIds, callType: callType, channel: "unknown" }
+        );
+      });
+
+      it("should include the channel when defined", function() {
+        mozLoop.appVersionInfo = {
+          channel: "beta"
+        };
+
+        client.setupOutgoingCall(calleeIds, callType);
+
+        sinon.assert.calledOnce(hawkRequestStub);
+        sinon.assert.calledWith(hawkRequestStub,
+          mozLoop.LOOP_SESSION_TYPE.FXA,
+          "/calls",
+          "POST",
+          { calleeId: calleeIds, callType: callType, channel: "beta" }
         );
       });
 
       it("should call the callback if the request is successful", function() {
         var requestData = {
           apiKey: "fake",
           callId: "fakeCall",
           progressURL: "fakeurl",
--- a/browser/components/loop/test/standalone/standalone_client_test.js
+++ b/browser/components/loop/test/standalone/standalone_client_test.js
@@ -123,17 +123,17 @@ describe("loop.StandaloneClient", functi
         });
 
       it("should post data for the given call", function() {
         client.requestCallInfo("fake", "audio", callback);
 
         expect(requests).to.have.length.of(1);
         expect(requests[0].url).to.be.equal("http://fake.api/calls/fake");
         expect(requests[0].method).to.be.equal("POST");
-        expect(requests[0].requestBody).to.be.equal('{"callType":"audio"}');
+        expect(requests[0].requestBody).to.be.equal('{"callType":"audio","channel":"standalone"}');
       });
 
       it("should receive call data for the given call", function() {
         client.requestCallInfo("fake", "audio-video", callback);
 
         var sessionData = {
           sessionId: "one",
           sessionToken: "two",