Bug 1126334 - Hello Icon should change colour when screensharing is active. r=jaws

This commit is contained in:
Mark Banner
2015-02-10 09:37:44 +00:00
parent 5c0e86990f
commit fd95bcedb5
7 changed files with 105 additions and 5 deletions

View File

@@ -206,6 +206,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/Panel
let state = ""; let state = "";
if (MozLoopService.errors.size) { if (MozLoopService.errors.size) {
state = "error"; state = "error";
} else if (MozLoopService.screenShareActive) {
state = "action";
} else if (aReason == "login" && MozLoopService.userProfile) { } else if (aReason == "login" && MozLoopService.userProfile) {
state = "active"; state = "active";
} else if (MozLoopService.doNotDisturb) { } else if (MozLoopService.doNotDisturb) {

View File

@@ -747,6 +747,22 @@ function injectLoopAPI(targetWindow) {
UITour.notify(subject); UITour.notify(subject);
} }
}, },
/**
* Used to record the screen sharing state for a window so that it can
* be reflected on the toolbar button.
*
* @param {String} windowId The id of the conversation window the state
* is being changed for.
* @param {Boolean} active Whether or not screen sharing is now active.
*/
setScreenShareState: {
enumerable: true,
writable: true,
value: function(windowId, active) {
MozLoopService.setScreenShareState(windowId, active);
}
}
}; };
function onStatusChanged(aSubject, aTopic, aData) { function onStatusChanged(aSubject, aTopic, aData) {

View File

@@ -1046,6 +1046,7 @@ let gInitializeTimerFunc = (deferredInitialization) => {
*/ */
this.MozLoopService = { this.MozLoopService = {
_DNSService: gDNSService, _DNSService: gDNSService,
_activeScreenShares: [],
get channelIDs() { get channelIDs() {
// Channel ids that will be registered with the PushServer for notifications // Channel ids that will be registered with the PushServer for notifications
@@ -1654,5 +1655,33 @@ this.MozLoopService = {
addConversationContext: function(windowId, context) { addConversationContext: function(windowId, context) {
MozLoopServiceInternal.conversationContexts.set(windowId, context); MozLoopServiceInternal.conversationContexts.set(windowId, context);
},
/**
* Used to record the screen sharing state for a window so that it can
* be reflected on the toolbar button.
*
* @param {String} windowId The id of the conversation window the state
* is being changed for.
* @param {Boolean} active Whether or not screen sharing is now active.
*/
setScreenShareState: function(windowId, active) {
if (active) {
this._activeScreenShares.push(windowId);
} else {
var index = this._activeScreenShares.indexOf(windowId);
if (index != -1) {
this._activeScreenShares.splice(index, 1);
}
}
MozLoopServiceInternal.notifyStatusChanged();
},
/**
* Returns true if screen sharing is active in at least one window.
*/
get screenShareActive() {
return this._activeScreenShares.length > 0;
} }
}; };

View File

@@ -380,6 +380,10 @@ loop.store.ActiveRoomStore = (function() {
*/ */
screenSharingState: function(actionData) { screenSharingState: function(actionData) {
this.setStoreState({screenSharingState: actionData.state}); this.setStoreState({screenSharingState: actionData.state});
this._mozLoop.setScreenShareState(
this.getStoreState().windowId,
actionData.state === SCREEN_SHARE_STATES.ACTIVE);
}, },
/** /**
@@ -417,6 +421,13 @@ loop.store.ActiveRoomStore = (function() {
windowUnload: function() { windowUnload: function() {
this._leaveRoom(ROOM_STATES.CLOSING); this._leaveRoom(ROOM_STATES.CLOSING);
// If we're closing the window, then ensure the screensharing state
// is cleared. We don't do this on leave room, as we might still be
// sharing.
this._mozLoop.setScreenShareState(
this.getStoreState().windowId,
false);
if (!this._onUpdateListener) { if (!this._onUpdateListener) {
return; return;
} }

View File

@@ -268,9 +268,10 @@ loop.StandaloneMozLoop = (function(mozL10n) {
return localStorage.getItem(prefName); return localStorage.getItem(prefName);
}, },
// Dummy function to reflect those in the desktop mozLoop that we // Dummy functions to reflect those in the desktop mozLoop that we
// don't currently use. // don't currently use in standalone.
addConversationContext: function() {} addConversationContext: function() {},
setScreenShareState: function() {}
}; };
return StandaloneMozLoop; return StandaloneMozLoop;

View File

@@ -104,3 +104,11 @@ add_task(function* test_panelToggle_on_click() {
LoopUI.toolbarButton.node.click(); LoopUI.toolbarButton.node.click();
Assert.strictEqual(LoopUI.panel.state, "closed", "Panel should be closed"); Assert.strictEqual(LoopUI.panel.state, "closed", "Panel should be closed");
}); });
add_task(function* test_screen_share() {
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "", "Check button is in default state");
MozLoopService.setScreenShareState("1", true);
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "action", "Check button is in action state");
MozLoopService.setScreenShareState("1", false);
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "", "Check button is in default state");
});

View File

@@ -30,7 +30,8 @@ describe("loop.store.ActiveRoomStore", function () {
leave: sinon.stub(), leave: sinon.stub(),
on: sinon.stub(), on: sinon.stub(),
off: sinon.stub() off: sinon.stub()
} },
setScreenShareState: sinon.stub()
}; };
fakeSdkDriver = { fakeSdkDriver = {
@@ -648,6 +649,10 @@ describe("loop.store.ActiveRoomStore", function () {
}); });
describe("#screenSharingState", function() { describe("#screenSharingState", function() {
beforeEach(function() {
store.setStoreState({windowId: "1234"});
});
it("should save the state", function() { it("should save the state", function() {
store.screenSharingState(new sharedActions.ScreenSharingState({ store.screenSharingState(new sharedActions.ScreenSharingState({
state: SCREEN_SHARE_STATES.ACTIVE state: SCREEN_SHARE_STATES.ACTIVE
@@ -655,6 +660,24 @@ describe("loop.store.ActiveRoomStore", function () {
expect(store.getStoreState().screenSharingState).eql(SCREEN_SHARE_STATES.ACTIVE); expect(store.getStoreState().screenSharingState).eql(SCREEN_SHARE_STATES.ACTIVE);
}); });
it("should set screen sharing active when the state is active", function() {
store.screenSharingState(new sharedActions.ScreenSharingState({
state: SCREEN_SHARE_STATES.ACTIVE
}));
sinon.assert.calledOnce(fakeMozLoop.setScreenShareState);
sinon.assert.calledWithExactly(fakeMozLoop.setScreenShareState, "1234", true);
});
it("should set screen sharing inactive when the state is inactive", function() {
store.screenSharingState(new sharedActions.ScreenSharingState({
state: SCREEN_SHARE_STATES.INACTIVE
}));
sinon.assert.calledOnce(fakeMozLoop.setScreenShareState);
sinon.assert.calledWithExactly(fakeMozLoop.setScreenShareState, "1234", false);
});
}); });
describe("#receivingScreenShare", function() { describe("#receivingScreenShare", function() {
@@ -696,10 +719,20 @@ describe("loop.store.ActiveRoomStore", function () {
store.setStoreState({ store.setStoreState({
roomState: ROOM_STATES.JOINED, roomState: ROOM_STATES.JOINED,
roomToken: "fakeToken", roomToken: "fakeToken",
sessionToken: "1627384950" sessionToken: "1627384950",
windowId: "1234"
}); });
}); });
it("should set screen sharing inactive", function() {
store.screenSharingState(new sharedActions.ScreenSharingState({
state: SCREEN_SHARE_STATES.INACTIVE
}));
sinon.assert.calledOnce(fakeMozLoop.setScreenShareState);
sinon.assert.calledWithExactly(fakeMozLoop.setScreenShareState, "1234", false);
});
it("should reset the multiplexGum", function() { it("should reset the multiplexGum", function() {
store.windowUnload(); store.windowUnload();