Bug 1208201 - Simplify setup flows for standalone and desktop in Loop's activeRoomStore. r=mikedeboer

This commit is contained in:
Mark Banner 2015-09-25 12:57:25 +01:00
Родитель f7c532aa89
Коммит b3e8cd935f
3 изменённых файлов: 78 добавлений и 139 удалений

Просмотреть файл

@ -450,21 +450,6 @@ loop.shared.actions = (function() {
failedJoinRequest: Boolean
}),
/**
* Sets up the room information when it is received.
* XXX: should move to some roomActions module - refs bug 1079284
*
* @see https://wiki.mozilla.org/Loop/Architecture/Rooms#GET_.2Frooms.2F.7Btoken.7D
*/
SetupRoomInfo: Action.define("setupRoomInfo", {
// roomContextUrls: Array - Optional.
// roomDescription: String - Optional.
// roomName: String - Optional.
roomToken: String,
roomUrl: String,
socialShareProviders: Array
}),
/**
* Updates the room information when it is received.
* XXX: should move to some roomActions module - refs bug 1079284
@ -472,11 +457,15 @@ loop.shared.actions = (function() {
* @see https://wiki.mozilla.org/Loop/Architecture/Rooms#GET_.2Frooms.2F.7Btoken.7D
*/
UpdateRoomInfo: Action.define("updateRoomInfo", {
// description: String - Optional.
// roomName: String - Optional.
roomUrl: String
// urls: Array - Optional.
// participants: Array - Optional.
// roomContextUrls: Array - Optional.
// See https://wiki.mozilla.org/Loop/Architecture/Context#Format_of_context.value
// roomDescription: String - Optional.
// roomInfoFailure: String - Optional.
// roomName: String - Optional.
// roomState: String - Optional.
roomUrl: String
// socialShareProviders: Array - Optional.
}),
/**

Просмотреть файл

@ -49,12 +49,13 @@ loop.store.ActiveRoomStore = (function() {
var ROOM_INFO_FAILURES = loop.shared.utils.ROOM_INFO_FAILURES;
var OPTIONAL_ROOMINFO_FIELDS = {
urls: "roomContextUrls",
description: "roomDescription",
participants: "participants",
roomContextUrls: "roomContextUrls",
roomDescription: "roomDescription",
roomInfoFailure: "roomInfoFailure",
roomName: "roomName",
roomState: "roomState"
roomState: "roomState",
socialShareProviders: "socialShareProviders"
};
/**
@ -142,8 +143,6 @@ loop.store.ActiveRoomStore = (function() {
receivingScreenShare: false,
// Any urls (aka context) associated with the room.
roomContextUrls: null,
// The roomCryptoKey to decode the context data if necessary.
roomCryptoKey: null,
// The description for a room as stored in the context data.
roomDescription: null,
// Room information failed to be obtained for a reason. See ROOM_INFO_FAILURES.
@ -237,7 +236,6 @@ loop.store.ActiveRoomStore = (function() {
this.dispatcher.register(this, [
"roomFailure",
"retryAfterRoomFailure",
"setupRoomInfo",
"updateRoomInfo",
"gotMediaPermission",
"joinRoom",
@ -262,6 +260,15 @@ loop.store.ActiveRoomStore = (function() {
"connectionStatus",
"mediaConnected"
]);
this._onUpdateListener = this._handleRoomUpdate.bind(this);
this._onDeleteListener = this._handleRoomDelete.bind(this);
this._onSocialShareUpdate = this._handleSocialShareUpdate.bind(this);
this._mozLoop.rooms.on("update:" + this._storeState.roomToken, this._onUpdateListener);
this._mozLoop.rooms.on("delete:" + this._storeState.roomToken, this._onDeleteListener);
window.addEventListener("LoopShareWidgetChanged", this._onSocialShareUpdate);
window.addEventListener("LoopSocialProvidersChanged", this._onSocialShareUpdate);
},
/**
@ -278,13 +285,14 @@ loop.store.ActiveRoomStore = (function() {
return;
}
this._registerPostSetupActions();
this.setStoreState({
roomState: ROOM_STATES.GATHER,
roomToken: actionData.roomToken,
windowId: actionData.windowId
});
this._registerPostSetupActions();
// Get the window data from the mozLoop api.
this._mozLoop.rooms.get(actionData.roomToken,
function(error, roomData) {
@ -296,12 +304,12 @@ loop.store.ActiveRoomStore = (function() {
return;
}
this.dispatchAction(new sharedActions.SetupRoomInfo({
this.dispatchAction(new sharedActions.UpdateRoomInfo({
participants: roomData.participants,
roomToken: actionData.roomToken,
roomContextUrls: roomData.decryptedContext.urls,
roomDescription: roomData.decryptedContext.description,
roomName: roomData.decryptedContext.roomName,
roomState: ROOM_STATES.READY,
roomUrl: roomData.roomUrl,
socialShareProviders: this._mozLoop.getSocialShareProviders()
}));
@ -326,23 +334,18 @@ loop.store.ActiveRoomStore = (function() {
return;
}
this._registerPostSetupActions();
this.setStoreState({
roomToken: actionData.token,
roomState: ROOM_STATES.GATHER,
roomCryptoKey: actionData.cryptoKey
roomToken: actionData.token,
standalone: true
});
this._mozLoop.rooms.on("update:" + actionData.roomToken,
this._handleRoomUpdate.bind(this));
this._mozLoop.rooms.on("delete:" + actionData.roomToken,
this._handleRoomDelete.bind(this));
this._registerPostSetupActions();
this._getRoomDataForStandalone();
this._getRoomDataForStandalone(actionData.cryptoKey);
},
_getRoomDataForStandalone: function() {
_getRoomDataForStandalone: function(roomCryptoKey) {
this._mozLoop.rooms.get(this._storeState.roomToken, function(err, result) {
if (err) {
this.dispatchAction(new sharedActions.RoomFailure({
@ -353,15 +356,14 @@ loop.store.ActiveRoomStore = (function() {
}
var roomInfoData = new sharedActions.UpdateRoomInfo({
// If we've got this far, then we want to go to the ready state
// regardless of success of failure. This is because failures of
// crypto don't stop the user using the room, they just stop
// us putting up the information.
roomState: ROOM_STATES.READY,
roomUrl: result.roomUrl
});
// If we've got this far, then we want to go to the ready state
// regardless of success of failure. This is because failures of
// crypto don't stop the user using the room, they just stop
// us putting up the information.
roomInfoData.roomState = ROOM_STATES.READY;
if (!result.context && !result.roomName) {
roomInfoData.roomInfoFailure = ROOM_INFO_FAILURES.NO_DATA;
this.dispatcher.dispatch(roomInfoData);
@ -381,8 +383,6 @@ loop.store.ActiveRoomStore = (function() {
return;
}
var roomCryptoKey = this.getStoreState("roomCryptoKey");
if (!roomCryptoKey) {
roomInfoData.roomInfoFailure = ROOM_INFO_FAILURES.NO_CRYPTO_KEY;
this.dispatcher.dispatch(roomInfoData);
@ -395,8 +395,8 @@ loop.store.ActiveRoomStore = (function() {
.then(function(decryptedResult) {
var realResult = JSON.parse(decryptedResult);
roomInfoData.description = realResult.description;
roomInfoData.urls = realResult.urls;
roomInfoData.roomDescription = realResult.description;
roomInfoData.roomContextUrls = realResult.urls;
roomInfoData.roomName = realResult.roomName;
dispatcher.dispatch(roomInfoData);
@ -407,39 +407,6 @@ loop.store.ActiveRoomStore = (function() {
}.bind(this));
},
/**
* Handles the setupRoomInfo action. Sets up the initial room data and
* sets the state to `READY`.
*
* @param {sharedActions.SetupRoomInfo} actionData
*/
setupRoomInfo: function(actionData) {
if (this._onUpdateListener) {
console.error("Room info already set up!");
return;
}
this.setStoreState({
participants: actionData.participants,
roomContextUrls: actionData.roomContextUrls,
roomDescription: actionData.roomDescription,
roomName: actionData.roomName,
roomState: ROOM_STATES.READY,
roomToken: actionData.roomToken,
roomUrl: actionData.roomUrl,
socialShareProviders: actionData.socialShareProviders
});
this._onUpdateListener = this._handleRoomUpdate.bind(this);
this._onDeleteListener = this._handleRoomDelete.bind(this);
this._onSocialShareUpdate = this._handleSocialShareUpdate.bind(this);
this._mozLoop.rooms.on("update:" + actionData.roomToken, this._onUpdateListener);
this._mozLoop.rooms.on("delete:" + actionData.roomToken, this._onDeleteListener);
window.addEventListener("LoopShareWidgetChanged", this._onSocialShareUpdate);
window.addEventListener("LoopSocialProvidersChanged", this._onSocialShareUpdate);
},
/**
* Handles the updateRoomInfo action. Updates the room data.
*

Просмотреть файл

@ -326,19 +326,29 @@ describe("loop.store.ActiveRoomStore", function () {
);
});
it("should set the state to `GATHER`",
function() {
store.setupWindowData(new sharedActions.SetupWindowData({
windowId: "42",
type: "room",
roomToken: fakeToken
}));
it("should set the state to `GATHER`", function() {
store.setupWindowData(new sharedActions.SetupWindowData({
windowId: "42",
type: "room",
roomToken: fakeToken
}));
expect(store.getStoreState()).to.have.property(
"roomState", ROOM_STATES.GATHER);
});
expect(store.getStoreState()).to.have.property(
"roomState", ROOM_STATES.GATHER);
});
it("should dispatch an SetupRoomInfo action if the get is successful",
it("should store the room token and window id", function() {
store.setupWindowData(new sharedActions.SetupWindowData({
windowId: "42",
type: "room",
roomToken: fakeToken
}));
expect(store.getStoreState().windowId).eql("42");
expect(store.getStoreState().roomToken).eql(fakeToken);
});
it("should dispatch an UpdateRoomInfo action if the get is successful",
function() {
store.setupWindowData(new sharedActions.SetupWindowData({
windowId: "42",
@ -348,12 +358,12 @@ describe("loop.store.ActiveRoomStore", function () {
sinon.assert.calledTwice(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,
new sharedActions.SetupRoomInfo({
new sharedActions.UpdateRoomInfo({
roomContextUrls: undefined,
roomDescription: undefined,
participants: [],
roomToken: fakeToken,
roomName: fakeRoomData.decryptedContext.roomName,
roomState: ROOM_STATES.READY,
roomUrl: fakeRoomData.roomUrl,
socialShareProviders: []
}));
@ -551,8 +561,11 @@ describe("loop.store.ActiveRoomStore", function () {
store.fetchServerData(fetchServerAction);
var expectedData = _.extend({
roomContextUrls: roomContext.urls,
roomDescription: roomContext.description,
roomName: roomContext.roomName,
roomState: ROOM_STATES.READY
}, roomContext, expectedDetails);
}, expectedDetails);
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,
@ -586,47 +599,18 @@ describe("loop.store.ActiveRoomStore", function () {
});
});
describe("#setupRoomInfo", function() {
var fakeRoomInfo;
beforeEach(function() {
fakeRoomInfo = {
roomName: "Its a room",
roomToken: "fakeToken",
roomUrl: "http://invalid",
socialShareProviders: []
};
});
it("should set the state to READY", function() {
store.setupRoomInfo(new sharedActions.SetupRoomInfo(fakeRoomInfo));
expect(store._storeState.roomState).eql(ROOM_STATES.READY);
});
it("should save the room information", function() {
store.setupRoomInfo(new sharedActions.SetupRoomInfo(fakeRoomInfo));
var state = store.getStoreState();
expect(state.roomName).eql(fakeRoomInfo.roomName);
expect(state.roomToken).eql(fakeRoomInfo.roomToken);
expect(state.roomUrl).eql(fakeRoomInfo.roomUrl);
expect(state.socialShareProviders).eql([]);
});
});
describe("#updateRoomInfo", function() {
var fakeRoomInfo;
beforeEach(function() {
fakeRoomInfo = {
roomName: "Its a room",
roomUrl: "http://invalid",
urls: [{
roomContextUrls: [{
description: "fake site",
location: "http://invalid.com",
thumbnail: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
}]
}],
roomName: "Its a room",
roomUrl: "http://invalid"
};
});
@ -636,7 +620,7 @@ describe("loop.store.ActiveRoomStore", function () {
var state = store.getStoreState();
expect(state.roomName).eql(fakeRoomInfo.roomName);
expect(state.roomUrl).eql(fakeRoomInfo.roomUrl);
expect(state.roomContextUrls).eql(fakeRoomInfo.urls);
expect(state.roomContextUrls).eql(fakeRoomInfo.roomContextUrls);
});
});
@ -1602,11 +1586,10 @@ describe("loop.store.ActiveRoomStore", function () {
describe("Events", function() {
describe("update:{roomToken}", function() {
beforeEach(function() {
store.setupRoomInfo(new sharedActions.SetupRoomInfo({
roomName: "Its a room",
store.setupWindowData(new sharedActions.SetupWindowData({
roomToken: "fakeToken",
roomUrl: "http://invalid",
socialShareProviders: []
type: "room",
windowId: "42"
}));
});
@ -1667,11 +1650,11 @@ describe("loop.store.ActiveRoomStore", function () {
};
beforeEach(function() {
store.setupRoomInfo(new sharedActions.SetupRoomInfo(
_.extend(fakeRoomData, {
socialShareProviders: []
})
));
store.setupWindowData(new sharedActions.SetupWindowData({
roomToken: "fakeToken",
type: "room",
windowId: "42"
}));
});
it("should disconnect all room connections", function() {