Bug 1168366 - Loop Link-clicker: Joining a room, giving feedback, looses context information until the page is reloaded. r=mikedeboer

This commit is contained in:
Mark Banner 2015-05-27 12:59:43 +01:00
parent f7c5935f10
commit 1b9d2188b0
2 changed files with 83 additions and 10 deletions

View File

@ -67,8 +67,28 @@ loop.store.ActiveRoomStore = (function() {
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 {
@ -750,6 +770,15 @@ loop.store.ActiveRoomStore = (function() {
// 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;
@ -768,12 +797,16 @@ loop.store.ActiveRoomStore = (function() {
},
/**
* 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
});
},
/**

View File

@ -493,18 +493,26 @@ describe("loop.store.ActiveRoomStore", function () {
});
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);
});
});
@ -1302,6 +1310,38 @@ describe("loop.store.ActiveRoomStore", function () {
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() {