Bug 1097749 - Standalone rooms should display the room name once the room has been joined. r=nperriault

a=kwierso for the CLOSED TREE
This commit is contained in:
Mark Banner
2014-11-25 23:46:43 +00:00
parent 43a5e2cdf8
commit a65d69164f
4 changed files with 128 additions and 1 deletions

View File

@@ -304,6 +304,21 @@ loop.store.ActiveRoomStore = (function() {
this._setRefreshTimeout(actionData.expires);
this._sdkDriver.connectSession(actionData);
// If we haven't got a room name yet, go and get one. We typically
// need to do this in the case of the standalone window.
// XXX When bug 1103331 lands this can be moved to earlier.
if (!this._storeState.roomName) {
this._mozLoop.rooms.get(this._storeState.roomToken,
function(err, result) {
if (err) {
console.error("Failed to get room data:", err);
return;
}
this.dispatcher.dispatch(new sharedActions.UpdateRoomInfo(result));
}.bind(this));
}
},
/**

View File

@@ -68,6 +68,44 @@ loop.StandaloneMozLoop = (function(mozL10n) {
};
StandaloneMozLoopRooms.prototype = {
/**
* Request information about a specific room from the server.
*
* @param {String} roomToken Room identifier
* @param {Function} callback Function that will be invoked once the operation
* finished. The first argument passed will be an
* `Error` object or `null`. The second argument will
* be the list of rooms, if it was fetched successfully.
*/
get: function(roomToken, callback) {
var req = $.ajax({
url: this._baseServerUrl + "/rooms/" + roomToken,
method: "GET",
contentType: "application/json",
beforeSend: function(xhr) {
if (this.sessionToken) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(this.sessionToken));
}
}.bind(this)
});
req.done(function(responseData) {
try {
// We currently only require things we need rather than everything possible.
callback(null, validate(responseData, {
roomName: String,
roomOwner: String,
roomUrl: String
}));
} catch (err) {
console.error("Error requesting call info", err.message);
callback(err);
}
}.bind(this));
req.fail(failureHandler.bind(this, callback));
},
/**
* Internal function to actually perform a post to a room.
*
@@ -115,6 +153,16 @@ loop.StandaloneMozLoop = (function(mozL10n) {
* `Error` object or `null`.
*/
join: function(roomToken, callback) {
function callbackWrapper(err, result) {
// XXX Save the sessionToken for purposes of get.
// When bug 1103331 this can probably be removed.
if (result) {
this.sessionToken = result.sessionToken;
}
callback(err, result);
}
this._postToRoom(roomToken, null, {
action: "join",
displayName: mozL10n.get("rooms_display_name_guest"),
@@ -124,7 +172,7 @@ loop.StandaloneMozLoop = (function(mozL10n) {
sessionId: String,
sessionToken: String,
expires: Number
}, callback);
}, callbackWrapper.bind(this));
},
/**

View File

@@ -384,6 +384,34 @@ describe("loop.store.ActiveRoomStore", function () {
actionData);
});
it("should call mozLoop.rooms.get to get the room data if the roomName" +
"is not known", function() {
store.setStoreState({roomName: undefined});
store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData));
sinon.assert.calledOnce(fakeMozLoop.rooms.get);
});
it("should dispatch UpdateRoomInfo if mozLoop.rooms.get is successful",
function() {
var roomDetails = {
roomName: "fakeName",
roomUrl: "http://invalid",
roomOwner: "gavin"
};
fakeMozLoop.rooms.get.callsArgWith(1, null, roomDetails);
store.setStoreState({roomName: undefined});
store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData));
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,
new sharedActions.UpdateRoomInfo(roomDetails));
});
it("should call mozLoop.rooms.refreshMembership before the expiresTime",
function() {
store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData));

View File

@@ -76,6 +76,42 @@ describe("loop.StandaloneMozLoop", function() {
});
});
describe("#rooms.get", function() {
it("should GET to the server", function() {
mozLoop.rooms.get("fakeToken", callback);
expect(requests).to.have.length.of(1);
expect(requests[0].url).eql(fakeBaseServerUrl + "/rooms/fakeToken");
expect(requests[0].method).eql("GET");
});
it("should call the callback with success parameters", function() {
mozLoop.rooms.get("fakeToken", callback);
var roomDetails = {
roomName: "fakeName",
roomUrl: "http://invalid",
roomOwner: "gavin"
};
requests[0].respond(200, {"Content-Type": "application/json"},
JSON.stringify(roomDetails));
sinon.assert.calledOnce(callback);
sinon.assert.calledWithExactly(callback, null, roomDetails);
});
it("should call the callback with failure parameters", function() {
mozLoop.rooms.get("fakeToken", callback);
requests[0].respond(401, {"Content-Type": "application/json"},
JSON.stringify(fakeServerErrorDescription));
sinon.assert.calledWithMatch(callback, sinon.match(function(err) {
return /HTTP 401 Unauthorized/.test(err.message);
}));
});
});
describe("#rooms.join", function() {
it("should POST to the server", function() {
mozLoop.rooms.join("fakeToken", callback);