Skip to content

Commit

Permalink
Bug 1643027 - Add GlobalMuteListener to WebRTCChild for globally muti…
Browse files Browse the repository at this point in the history
…ng the microphone and camera. r=pbz

This listens to state changes set via SharedData. Those state changes are executed by
front-end code in a later patch in this series.

Depends on D87129

Differential Revision: https://phabricator.services.mozilla.com/D86719
  • Loading branch information
mikeconley committed Aug 27, 2020
1 parent edfce94 commit 01fa52e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions browser/actors/WebRTCChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,58 @@ XPCOMUtils.defineLazyServiceGetter(

const kBrowserURL = AppConstants.BROWSER_CHROME_URL;

/**
* GlobalMuteListener is a process-global object that listens for changes to
* the global mute state of the camera and microphone. When it notices a
* change in that state, it tells the underlying platform code to mute or
* unmute those devices.
*/
const GlobalMuteListener = {
_initted: false,

/**
* Initializes the listener if it hasn't been already. This will also
* ensure that the microphone and camera are initially in the right
* muting state.
*/
init() {
if (!this._initted) {
Services.cpmm.sharedData.addEventListener("change", this);
this._updateCameraMuteState();
this._updateMicrophoneMuteState();
this._initted = true;
}
},

handleEvent(event) {
if (event.changedKeys.includes("WebRTC:GlobalCameraMute")) {
this._updateCameraMuteState();
}
if (event.changedKeys.includes("WebRTC:GlobalMicrophoneMute")) {
this._updateMicrophoneMuteState();
}
},

_updateCameraMuteState() {
let shouldMute = Services.cpmm.sharedData.get("WebRTC:GlobalCameraMute");
let topic = shouldMute
? "getUserMedia:muteVideo"
: "getUserMedia:unmuteVideo";
Services.obs.notifyObservers(null, topic);
},

_updateMicrophoneMuteState() {
let shouldMute = Services.cpmm.sharedData.get(
"WebRTC:GlobalMicrophoneMute"
);
let topic = shouldMute
? "getUserMedia:muteAudio"
: "getUserMedia:unmuteAudio";

Services.obs.notifyObservers(null, topic);
},
};

class WebRTCChild extends JSWindowActorChild {
actorCreated() {
// The user might request that DOM notifications be silenced
Expand Down Expand Up @@ -205,6 +257,13 @@ function handleGUMStop(aSubject, aTopic, aData) {
}

function handleGUMRequest(aSubject, aTopic, aData) {
// Now that a getUserMedia request has been created, we should check
// to see if we're supposed to have any devices muted. This needs
// to occur after the getUserMedia request is made, since the global
// mute state is associated with the GetUserMediaWindowListener, which
// is only created after a getUserMedia request.
GlobalMuteListener.init();

let constraints = aSubject.getConstraints();
let secure = aSubject.isSecure;
let isHandlingUserInput = aSubject.isHandlingUserInput;
Expand Down

0 comments on commit 01fa52e

Please sign in to comment.