Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #455 from crdlc/bug-1120905
Browse files Browse the repository at this point in the history
Bug 1120905 - [Loop] When Loop is opened in foreground and headset is co...
  • Loading branch information
Cristian Rodriguez committed Jan 16, 2015
2 parents 1282a64 + c011d66 commit 8d80b1d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/js/helpers/room/room_controller.js
Expand Up @@ -22,6 +22,20 @@
frontCamera: false
};

var acm = navigator.mozAudioChannelManager;

function onHeadPhonesChange() {
RoomUI.headphonesPresent = RoomController.headphonesPresent;
}

function handleHeadPhonesChange() {
acm && acm.addEventListener('headphoneschange', onHeadPhonesChange);
}

function removeHeadPhonesChangeHandler() {
acm && acm.removeEventListener('headphoneschange', onHeadPhonesChange);
}

function showError(errorMessage) {
errorMessage = errorMessage || 'genericServerError';
Loader.getErrorScreen().then(ErrorScreen => {
Expand Down Expand Up @@ -232,6 +246,7 @@

Loader.getRoomUI().then((RoomUI) => {
RoomUI.show(params).then(() => {
handleHeadPhonesChange();

params.localTargetElement = RoomUI.localTargetElement;
params.remoteTargetElement = RoomUI.remoteTargetElement;
Expand Down Expand Up @@ -352,6 +367,7 @@
currentToken = null;
document.removeEventListener('visibilitychange',
backgroundModeHandler);
removeHeadPhonesChangeHandler();
RoomUI.hide();
window.clearTimeout(refreshTimeOut);
Rooms.leave(params.token);
Expand All @@ -366,7 +382,7 @@
currentToken = null;
document.removeEventListener('visibilitychange',
backgroundModeHandler);

removeHeadPhonesChangeHandler();
shouldRate ? rate(RoomUI.hide) : RoomUI.hide();
};

Expand All @@ -375,7 +391,7 @@
};

RoomUI.onSwitchSpeaker = function() {
roomManager.forceSpeaker(!roomManager.isSpeakerEnabled);
roomManager.forceSpeaker(RoomUI.isSpeakerEnabled);
};

RoomUI.onToggleVideo = function() {
Expand All @@ -396,6 +412,7 @@
debug && console.log('Error while joining room');
currentToken = null;
isConnected = false;
removeHeadPhonesChangeHandler();
RoomUI.hide();
// See https://docs.services.mozilla.com/loop/apis.html
if (error) {
Expand All @@ -419,6 +436,9 @@
if (isConnected && currentToken && (currentToken === token)) {
RoomUI.updateParticipant(name, account);
}
},
get headphonesPresent() {
return acm && acm.headphones;
}
};

Expand Down
28 changes: 28 additions & 0 deletions app/js/screens/room/room_ui.js
Expand Up @@ -54,6 +54,27 @@
}
}

function setHeadphonesPresent(status) {
var headphonesPresent = !!status;
// What we should do on a headphone change is:
// Removal (!headphonesPresent)
// - If the communication is audio, removing the headphones should leave
// the speaker on the same status it was.
// - If the communication is video, removing the headphones should turn ON
// the speaker
// Insertion (headphonesPresent)
// - If the communication is audio, then inserting the headphones should
// disable the speaker if it was enabled.
// - If the communication is video, then inserting the headphones should
// disable the speaker if it was enabled.
if ((!headphonesPresent && isVideoEnabled && !isSpeakerEnabled) ||
(headphonesPresent && isSpeakerEnabled)) {
// According to the previous description, in those two cases we have
// to change the speaker status
switchSpeakerButtonClicked();
}
}

function render(params) {
if (!localVideoContainer) {
panel = document.getElementById('room-ui');
Expand Down Expand Up @@ -215,6 +236,9 @@
// Set picked camera to perform proper UI rotation
panel.dataset.isFrontCamera = params.frontCamera;

// Set the initial headphone state (and modify the speaker state
// accordingly)
setHeadphonesPresent(RoomController.headphonesPresent);
updateButtonStatus();
RoomUI.setWaiting();
}
Expand Down Expand Up @@ -361,6 +385,10 @@
});
},

set headphonesPresent(status) {
setHeadphonesPresent(status);
},

hide: hide
};

Expand Down

0 comments on commit 8d80b1d

Please sign in to comment.