Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Bug 1249015 - Context is still updated in standalone when sharing is …
Browse files Browse the repository at this point in the history
…stopped. r=mancas
  • Loading branch information
Mardak committed Feb 18, 2016
1 parent de19221 commit 5f94d79
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 13 deletions.
33 changes: 30 additions & 3 deletions shared/js/activeRoomStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ loop.store.ActiveRoomStore = (function(mozL10n) {
localVideoDimensions: {},
remoteVideoDimensions: {},
screenSharingState: SCREEN_SHARE_STATES.INACTIVE,
sharingPaused: false,
receivingScreenShare: false,
// Any urls (aka context) associated with the room.
roomContextUrls: null,
Expand Down Expand Up @@ -264,6 +265,7 @@ loop.store.ActiveRoomStore = (function(mozL10n) {
"videoDimensionsChanged",
"startBrowserShare",
"endScreenShare",
"toggleBrowserSharing",
"updateSocialShareInfo",
"connectionStatus",
"mediaConnected"
Expand Down Expand Up @@ -924,10 +926,19 @@ loop.store.ActiveRoomStore = (function(mozL10n) {
console.error("Unexpectedly received windowId for browser sharing when pending");
}

// The browser being shared changed, so update to the new context
// Only update context if sharing is not paused and there's somebody.
if (!this.getStoreState().sharingPaused && this._hasParticipants()) {
this._checkTabContext();
}
},

/**
* Get the current tab context to update the room context.
*/
_checkTabContext: function() {
loop.request("GetSelectedTabMetadata").then(function(meta) {
// Avoid sending the event if there is no data nor participants nor url
if (!meta || !meta.url || !this._hasParticipants()) {
// Avoid sending the event if there is no data nor url.
if (!meta || !meta.url) {
return;
}

Expand Down Expand Up @@ -989,6 +1000,22 @@ loop.store.ActiveRoomStore = (function(mozL10n) {
}
},

/**
* Handle browser sharing being enabled or disabled.
*
* @param {sharedActions.ToggleBrowserSharing} actionData
*/
toggleBrowserSharing: function(actionData) {
this.setStoreState({
sharingPaused: !actionData.enabled
});

// If unpausing, check the context as it might have changed.
if (actionData.enabled) {
this._checkTabContext();
}
},

/**
* Handles recording when a remote peer has connected to the servers.
*/
Expand Down
76 changes: 66 additions & 10 deletions shared/test/activeRoomStore_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ describe("loop.store.ActiveRoomStore", function() {
it("should request the new metadata when the browser being shared change", function() {
store.startBrowserShare(new sharedActions.StartBrowserShare());
clock.tick(500);

sinon.assert.calledOnce(getSelectedTabMetadataStub);
sinon.assert.calledTwice(dispatcher.dispatch);
sinon.assert.calledWith(dispatcher.dispatch.getCall(1),
Expand Down Expand Up @@ -1630,35 +1631,42 @@ describe("loop.store.ActiveRoomStore", function() {
});

it("should not process a request without url", function() {
clock.tick(500);
getSelectedTabMetadataStub.returns({
title: "fakeTitle",
favicon: "fakeFavicon"
});

store.startBrowserShare(new sharedActions.StartBrowserShare());
clock.tick(500);

sinon.assert.calledOnce(getSelectedTabMetadataStub);
sinon.assert.calledOnce(dispatcher.dispatch);
});

it("should not process a request if sharing is paused", function() {
store.setStoreState({
sharingPaused: true
});

store.startBrowserShare(new sharedActions.StartBrowserShare());
clock.tick(500);

sinon.assert.notCalled(getSelectedTabMetadataStub);
sinon.assert.calledOnce(dispatcher.dispatch);
});

it("should not process a request if no-one is in the room", function() {
store.setStoreState({
roomState: ROOM_STATES.JOINED,
roomToken: "fakeToken",
sessionToken: "1627384950",
participants: [{
displayName: "Owner",
owner: true
}]
});
clock.tick(500);
getSelectedTabMetadataStub.returns({
title: "fakeTitle",
favicon: "fakeFavicon"
});

store.startBrowserShare(new sharedActions.StartBrowserShare());
sinon.assert.calledOnce(getSelectedTabMetadataStub);
clock.tick(500);

sinon.assert.notCalled(getSelectedTabMetadataStub);
sinon.assert.calledOnce(dispatcher.dispatch);
});
});
Expand Down Expand Up @@ -1731,6 +1739,54 @@ describe("loop.store.ActiveRoomStore", function() {
});
});

describe("#toggleBrowserSharing", function() {
it("should set paused to false when enabled", function() {
store.toggleBrowserSharing(new sharedActions.ToggleBrowserSharing({
enabled: true
}));

expect(store.getStoreState().sharingPaused).eql(false);
});

it("should set paused to true when not enabled", function() {
store.toggleBrowserSharing(new sharedActions.ToggleBrowserSharing({
enabled: false
}));

expect(store.getStoreState().sharingPaused).eql(true);
});

it("should update context when enabled", function() {
var getSelectedTabMetadataStub = sinon.stub();
LoopMochaUtils.stubLoopRequest({
GetSelectedTabMetadata: getSelectedTabMetadataStub.returns({
title: "fakeTitle",
favicon: "fakeFavicon",
url: "http://www.fakeurl.com"
})
});
store.setStoreState({
roomState: ROOM_STATES.JOINED,
roomToken: "fakeToken"
});

store.toggleBrowserSharing(new sharedActions.ToggleBrowserSharing({
enabled: true
}));
clock.tick(500);

sinon.assert.calledOnce(getSelectedTabMetadataStub);
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWith(dispatcher.dispatch,
new sharedActions.UpdateRoomContext({
newRoomDescription: "fakeTitle",
newRoomThumbnail: "fakeFavicon",
newRoomURL: "http://www.fakeurl.com",
roomToken: "fakeToken"
}));
});
});

describe("#remotePeerConnected", function() {
it("should set the state to `HAS_PARTICIPANTS`", function() {
store.remotePeerConnected();
Expand Down

0 comments on commit 5f94d79

Please sign in to comment.