1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 this.EXPORTED_SYMBOLS = [];
9 let Cc = Components.classes;
10 let Ci = Components.interfaces;
11 let Cu = Components.utils;
13 Cu.import("resource://gre/modules/Services.jsm");
14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
16 function handleRequest(aSubject, aTopic, aData) {
17 let { windowID, callID } = aSubject;
18 let constraints = aSubject.getConstraints();
19 let contentWindow = Services.wm.getOuterWindowWithId(windowID);
21 contentWindow.navigator.mozGetUserMediaDevices(
24 prompt(contentWindow, callID, constraints.audio,
25 constraints.video || constraints.picture,
29 denyRequest(callID, error);
33 function prompt(aWindow, aCallID, aAudioRequested, aVideoRequested, aDevices) {
34 let audioDevices = [];
35 let videoDevices = [];
36 for (let device of aDevices) {
37 device = device.QueryInterface(Ci.nsIMediaDevice);
38 switch (device.type) {
40 if (aAudioRequested) {
41 audioDevices.push(device);
46 if (aVideoRequested) {
47 videoDevices.push(device);
53 if (audioDevices.length == 0 && videoDevices.length == 0) {
59 videoDevices: videoDevices,
60 audioDevices: audioDevices,
63 aWindow.openDialog("chrome://webapprt/content/getUserMediaDialog.xul", "",
64 "chrome, dialog, modal", params).focus();
71 let allowedDevices = Cc["@mozilla.org/supports-array;1"].
72 createInstance(Ci.nsISupportsArray);
73 let videoIndex = params.out.video;
74 let audioIndex = params.out.audio;
76 if (videoIndex != -1) {
77 allowedDevices.AppendElement(videoDevices[videoIndex]);
80 if (audioIndex != -1) {
81 allowedDevices.AppendElement(audioDevices[audioIndex]);
84 if (allowedDevices.Count()) {
85 Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow",
92 function denyRequest(aCallID, aError) {
95 msg = Cc["@mozilla.org/supports-string;1"].
96 createInstance(Ci.nsISupportsString);
100 Services.obs.notifyObservers(msg, "getUserMedia:response:deny", aCallID);
103 Services.obs.addObserver(handleRequest, "getUserMedia:request", false);