From e0c7d1252de41d6f9ff3739aaa24b9065c3cc52c Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Tue, 10 Nov 2015 21:25:51 +0000 Subject: [PATCH] Bug 1223351 - Store a metrics event on the loop server if the data channel setup fails. r=Mardak --- .../loop/content/shared/js/otSdkDriver.js | 6 +- .../loop/test/shared/otSdkDriver_test.js | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/browser/components/loop/content/shared/js/otSdkDriver.js b/browser/components/loop/content/shared/js/otSdkDriver.js index 4fdb1d7bd032..4e0f8af95076 100644 --- a/browser/components/loop/content/shared/js/otSdkDriver.js +++ b/browser/components/loop/content/shared/js/otSdkDriver.js @@ -507,7 +507,9 @@ loop.OTSdkDriver = (function() { case "Session.forceDisconnected": break; default: - if (eventName.indexOf("sdk.exception") === -1) { + // We don't want unexpected events being sent to the server, so + // filter out the unexpected, and let the known ones through. + if (!/^sdk\.(exception|datachannel)/.test(eventName)) { console.error("Unexpected event name", eventName); return; } @@ -676,6 +678,7 @@ loop.OTSdkDriver = (function() { // Sends will queue until the channel is fully open. if (err) { console.error(err); + this._notifyMetricsEvent("sdk.datachannel.sub." + err.message); return; } @@ -726,6 +729,7 @@ loop.OTSdkDriver = (function() { this.publisher._.getDataChannel("text", {}, function(err, channel) { if (err) { console.error(err); + this._notifyMetricsEvent("sdk.datachannel.pub." + err.message); return; } diff --git a/browser/components/loop/test/shared/otSdkDriver_test.js b/browser/components/loop/test/shared/otSdkDriver_test.js index d9bc3b8510f9..976b80811f1f 100644 --- a/browser/components/loop/test/shared/otSdkDriver_test.js +++ b/browser/components/loop/test/shared/otSdkDriver_test.js @@ -1087,6 +1087,8 @@ describe("loop.OTSdkDriver", function() { fakeChannel = _.extend({}, Backbone.Events); fakeStream.connection = fakeConnection; driver._useDataChannels = true; + + sandbox.stub(console, "error"); }); it("should trigger a readyForDataChannel signal after subscribe is complete", function() { @@ -1122,6 +1124,33 @@ describe("loop.OTSdkDriver", function() { sinon.assert.notCalled(fakeSubscriberObject._.getDataChannel); }); + it("should log an error if the data channel couldn't be obtained", function() { + var err = new Error("fakeError"); + + fakeSubscriberObject._.getDataChannel.callsArgWith(2, err); + + session.trigger("streamCreated", { stream: fakeStream }); + + sinon.assert.calledOnce(console.error); + sinon.assert.calledWithMatch(console.error, err); + }); + + it("should dispatch ConnectionStatus if the data channel couldn't be obtained", function() { + fakeSubscriberObject._.getDataChannel.callsArgWith(2, new Error("fakeError")); + + session.trigger("streamCreated", { stream: fakeStream }); + + sinon.assert.called(dispatcher.dispatch); + sinon.assert.calledWithExactly(dispatcher.dispatch, + new sharedActions.ConnectionStatus({ + connections: 0, + event: "sdk.datachannel.sub.fakeError", + sendStreams: 0, + state: "receiving", + recvStreams: 1 + })); + }); + it("should dispatch `DataChannelsAvailable` if the publisher channel is setup", function() { // Fake a publisher channel. driver._publisherChannel = {}; @@ -1549,6 +1578,7 @@ describe("loop.OTSdkDriver", function() { beforeEach(function() { driver.subscriber = subscriber; driver._useDataChannels = true; + sandbox.stub(console, "error"); }); it("should not do anything if data channels are not wanted", function() { @@ -1566,6 +1596,33 @@ describe("loop.OTSdkDriver", function() { sinon.assert.calledOnce(publisher._.getDataChannel); }); + it("should log an error if the data channel couldn't be obtained", function() { + var err = new Error("fakeError"); + + publisher._.getDataChannel.callsArgWith(2, err); + + session.trigger("signal:readyForDataChannel"); + + sinon.assert.calledOnce(console.error); + sinon.assert.calledWithMatch(console.error, err); + }); + + it("should dispatch ConnectionStatus if the data channel couldn't be obtained", function() { + publisher._.getDataChannel.callsArgWith(2, new Error("fakeError")); + + session.trigger("signal:readyForDataChannel"); + + sinon.assert.calledOnce(dispatcher.dispatch); + sinon.assert.calledWithExactly(dispatcher.dispatch, + new sharedActions.ConnectionStatus({ + connections: 0, + event: "sdk.datachannel.pub.fakeError", + sendStreams: 0, + state: "starting", + recvStreams: 0 + })); + }); + it("should dispatch `DataChannelsAvailable` if the subscriber channel is setup", function() { var fakeChannel = _.extend({}, Backbone.Events);