Bug 1168366 - Loop Link-clicker: Joining a room, giving feedback, looses context information until the page is reloaded. r=mikedeboer
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -63,17 +63,37 @@ loop.store.ActiveRoomStore = (function()
throw new Error("Missing option sdkDriver");
}
this._sdkDriver = options.sdkDriver;
this._isDesktop = options.isDesktop || false;
},
/**
+ * This is a list of states that need resetting when the room is left,
+ * due to user choice, failure or other reason. It is a subset of
+ * getInitialStoreState as some items (e.g. roomState, failureReason,
+ * context information) can persist across room exit & re-entry.
+ *
+ * @type {Array}
+ */
+ _statesToResetOnLeave: [
+ "audioMuted",
+ "localVideoDimensions",
+ "receivingScreenShare",
+ "remoteVideoDimensions",
+ "screenSharingState",
+ "videoMuted"
+ ],
+
+ /**
* Returns initial state data for this active room.
+ *
+ * When adding states, consider if _statesToResetOnLeave needs updating
+ * as well.
*/
getInitialStoreState: function() {
return {
roomState: ROOM_STATES.INIT,
audioMuted: false,
videoMuted: false,
failureReason: undefined,
// Tracks if the room has been used during this
@@ -745,16 +765,25 @@ loop.store.ActiveRoomStore = (function()
// Remove the browser sharing listener as we don't need it now.
this._mozLoop.removeBrowserSharingListener(this._browserSharingListener);
this._browserSharingListener = null;
}
// We probably don't need to end screen share separately, but lets be safe.
this._sdkDriver.disconnectSession();
+ // Reset various states.
+ var originalStoreState = this.getInitialStoreState();
+ var newStoreState = {};
+
+ this._statesToResetOnLeave.forEach(function(state) {
+ newStoreState[state] = originalStoreState[state];
+ });
+ this.setStoreState(newStoreState);
+
if (this._timeout) {
clearTimeout(this._timeout);
delete this._timeout;
}
if (!failedJoinRequest &&
(this._storeState.roomState === ROOM_STATES.JOINING ||
this._storeState.roomState === ROOM_STATES.JOINED ||
@@ -763,22 +792,26 @@ loop.store.ActiveRoomStore = (function()
this._mozLoop.rooms.leave(this._storeState.roomToken,
this._storeState.sessionToken);
}
this.setStoreState({roomState: nextState});
},
/**
- * When feedback is complete, we reset the room to the initial state.
+ * When feedback is complete, we go back to the ready state, rather than
+ * init or gather, as we don't need to get the data from the server again.
*/
feedbackComplete: function() {
- // Note, that we want some values, such as the windowId, so we don't
- // do a full reset here.
- this.setStoreState(this.getInitialStoreState());
+ this.setStoreState({
+ roomState: ROOM_STATES.READY,
+ // Reset the used state here as the user has now given feedback and the
+ // next time they enter the room, the other person might not be there.
+ used: false
+ });
},
/**
* Handles a change in dimensions of a video stream and updates the store data
* with the new dimensions of a local or remote stream.
*
* @param {sharedActions.VideoDimensionsChanged} actionData
*/
--- a/browser/components/loop/test/shared/activeRoomStore_test.js
+++ b/browser/components/loop/test/shared/activeRoomStore_test.js
@@ -488,28 +488,36 @@ describe("loop.store.ActiveRoomStore", f
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,
new sharedActions.UpdateRoomInfo(_.extend(roomContext, expectedDetails)));
});
});
});
describe("#feedbackComplete", function() {
- it("should reset the room store state", function() {
- var initialState = store.getInitialStoreState();
+ it("should set the room state to READY", function() {
store.setStoreState({
roomState: ROOM_STATES.ENDED,
- audioMuted: true,
- videoMuted: true,
- failureReason: "foo"
+ used: true
});
store.feedbackComplete(new sharedActions.FeedbackComplete());
- expect(store.getStoreState()).eql(initialState);
+ expect(store.getStoreState().roomState).eql(ROOM_STATES.READY);
+ });
+
+ it("should reset the 'used' state", function() {
+ store.setStoreState({
+ roomState: ROOM_STATES.ENDED,
+ used: true
+ });
+
+ store.feedbackComplete(new sharedActions.FeedbackComplete());
+
+ expect(store.getStoreState().used).eql(false);
});
});
describe("#videoDimensionsChanged", function() {
it("should not contain any video dimensions at the very start", function() {
expect(store.getStoreState()).eql(store.getInitialStoreState());
});
@@ -1297,16 +1305,48 @@ describe("loop.store.ActiveRoomStore", f
sinon.assert.calledOnce(fakeMozLoop.removeBrowserSharingListener);
});
it("should set the state to ENDED", function() {
store.leaveRoom();
expect(store._storeState.roomState).eql(ROOM_STATES.ENDED);
});
+
+ it("should reset various store states", function() {
+ store.setStoreState({
+ audioMuted: true,
+ localVideoDimensions: { x: 10 },
+ receivingScreenShare: true,
+ remoteVideoDimensions: { y: 10 },
+ screenSharingState: true,
+ videoMuted: true
+ });
+
+ store.leaveRoom();
+
+ expect(store._storeState.audioMuted).eql(false);
+ expect(store._storeState.localVideoDimensions).eql({});
+ expect(store._storeState.receivingScreenShare).eql(false);
+ expect(store._storeState.remoteVideoDimensions).eql({});
+ expect(store._storeState.screenSharingState).eql(SCREEN_SHARE_STATES.INACTIVE);
+ expect(store._storeState.videoMuted).eql(false);
+ });
+
+ it("should not reset the room context", function() {
+ store.setStoreState({
+ roomContextUrls: [{ fake: 1 }],
+ roomName: "fred"
+ });
+
+ store.leaveRoom();
+
+ expect(store._storeState.roomName).eql("fred");
+ expect(store._storeState.roomContextUrls).eql([{ fake: 1 }]);
+ });
});
describe("#_handleSocialShareUpdate", function() {
it("should dispatch an UpdateRoomInfo action", function() {
store._handleSocialShareUpdate();
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,