Parcourir la source

Fire an optional JitsiMediaDevices.PERMISSION_PROMPT_IS_SHOWN event when browser shows user media permission prompt when calling createLocalTracks

dev1
tsareg il y a 9 ans
Parent
révision
714585de88
4 fichiers modifiés avec 55 ajouts et 26 suppressions
  1. 7
    0
      JitsiMediaDevices.js
  2. 11
    1
      JitsiMediaDevicesEvents.js
  3. 34
    3
      JitsiMeetJS.js
  4. 3
    22
      doc/API.md

+ 7
- 0
JitsiMediaDevices.js Voir le fichier

@@ -88,6 +88,13 @@ var JitsiMediaDevices = {
88 88
      */
89 89
     removeEventListener: function (event, handler) {
90 90
         eventEmitter.removeListener(event, handler);
91
+    },
92
+    /**
93
+     * Emits an event.
94
+     * @param {string} event - event name
95
+     */
96
+    emitEvent: function (event) {
97
+        eventEmitter.emit.apply(eventEmitter, arguments);
91 98
     }
92 99
 };
93 100
 

+ 11
- 1
JitsiMediaDevicesEvents.js Voir le fichier

@@ -11,7 +11,17 @@ var JitsiMediaDevicesEvents = {
11 11
      *  MediaDeviceInfo-like objects that are currently connected.
12 12
      *  @see https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo
13 13
      */
14
-    DEVICE_LIST_CHANGED: "mediaDevices.devicechange"
14
+    DEVICE_LIST_CHANGED: "mediaDevices.devicechange",
15
+    /**
16
+     * Indicates that the environment is currently showing permission prompt to
17
+     * access camera and/or microphone. The event provides the following
18
+     * parameters to its listeners:
19
+     *
20
+     * @param {'chrome'|'opera'|'firefox'|'iexplorer'|'safari'|'nwjs'
21
+     *      |'react-native'|'android'} environmentType - type of browser or
22
+     *      other execution environment.
23
+     */
24
+    PERMISSION_PROMPT_IS_SHOWN: "mediaDevices.permissionPromptIsShown"
15 25
 };
16 26
 
17 27
 module.exports = JitsiMediaDevicesEvents;

+ 34
- 3
JitsiMeetJS.js Voir le fichier

@@ -18,6 +18,11 @@ var Statistics = require("./modules/statistics/statistics");
18 18
 var Resolutions = require("./service/RTC/Resolutions");
19 19
 var ScriptUtil = require("./modules/util/ScriptUtil");
20 20
 var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
21
+var RTCBrowserType = require("./modules/RTC/RTCBrowserType");
22
+
23
+// The amount of time to wait until firing
24
+// JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN event
25
+var USER_MEDIA_PERMISSION_PROMPT_TIMEOUT = 500;
21 26
 
22 27
 function getLowerResolution(resolution) {
23 28
     if(!Resolutions[resolution])
@@ -99,13 +104,36 @@ var LibJitsiMeet = {
99 104
      * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
100 105
      * @param {string} options.cameraDeviceId
101 106
      * @param {string} options.micDeviceId
107
+     * @param {boolean} (firePermissionPromptIsShownEvent) - if event
108
+     *      JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
102 109
      * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
103 110
      *     A promise that returns an array of created JitsiTracks if resolved,
104 111
      *     or a JitsiConferenceError if rejected.
105 112
      */
106
-    createLocalTracks: function (options) {
107
-        return RTC.obtainAudioAndVideoPermissions(options || {}).then(
108
-            function(tracks) {
113
+    createLocalTracks: function (options, firePermissionPromptIsShownEvent) {
114
+        var promiseFulfilled = false;
115
+
116
+        if (firePermissionPromptIsShownEvent === true) {
117
+            window.setTimeout(function () {
118
+                if (!promiseFulfilled) {
119
+                    var browser = RTCBrowserType.getBrowserType()
120
+                        .split('rtc_browser.')[1];
121
+
122
+                    if (RTCBrowserType.isAndroid()) {
123
+                        browser = 'android';
124
+                    }
125
+
126
+                    JitsiMediaDevices.emitEvent(
127
+                        JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN,
128
+                        browser);
129
+                }
130
+            }, USER_MEDIA_PERMISSION_PROMPT_TIMEOUT);
131
+        }
132
+
133
+        return RTC.obtainAudioAndVideoPermissions(options || {})
134
+            .then(function(tracks) {
135
+                promiseFulfilled = true;
136
+
109 137
                 if(!RTC.options.disableAudioLevels)
110 138
                     for(var i = 0; i < tracks.length; i++) {
111 139
                         var track = tracks[i];
@@ -120,8 +148,11 @@ var LibJitsiMeet = {
120 148
                                 });
121 149
                         }
122 150
                     }
151
+
123 152
                 return tracks;
124 153
             }).catch(function (error) {
154
+                promiseFulfilled = true;
155
+
125 156
                 Statistics.sendGetUserMediaFailed(error);
126 157
 
127 158
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {

+ 3
- 22
doc/API.md Voir le fichier

@@ -60,7 +60,7 @@ The ```options``` parameter is JS object with the following properties:
60 60
 JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
61 61
 ```
62 62
 
63
-* ```JitsiMeetJS.createLocalTracks(options)``` - Creates the media tracks and returns them trough ```Promise``` object. If rejected, passes ```JitsiTrackError``` instance to catch block.
63
+* ```JitsiMeetJS.createLocalTracks(options, firePermissionPromptIsShownEvent)``` - Creates the media tracks and returns them trough ```Promise``` object. If rejected, passes ```JitsiTrackError``` instance to catch block.
64 64
     - options - JS object with configuration options for the local media tracks. You can change the following properties there:
65 65
         1. devices - array with the devices - "desktop", "video" and "audio" that will be passed to GUM. If that property is not set GUM will try to get all available devices.
66 66
         2. resolution - the prefered resolution for the local video.
@@ -69,6 +69,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
69 69
         5. minFps - the minimum frame rate for the video stream (passed to GUM)
70 70
         6. maxFps - the maximum frame rate for the video stream (passed to GUM)
71 71
         7. facingMode - facing mode for a camera (possible values - 'user', 'environment')
72
+    - firePermissionPromptIsShownEvent - optional boolean parameter. If set to ```true```, ```JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN``` will be fired when browser shows gUM permission prompt.
72 73
 
73 74
 * ```JitsiMeetJS.enumerateDevices(callback)``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.enumerateDevices(callback)``` instead.
74 75
 * ```JitsiMeetJS.isDeviceListAvailable()``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.isDeviceListAvailable()``` instead.
@@ -90,27 +91,6 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
90 91
     - ```addEventListener(event, handler)``` - attaches an event handler.
91 92
     - ```removeEventListener(event, handler)``` - removes an event handler.
92 93
 
93
-* ```JitsiMeetJS.environment``` - environment detection helper. Provides following methods and properties:
94
-    - ```RTC_BROWSER_CHROME```
95
-    - ```RTC_BROWSER_OPERA```
96
-    - ```RTC_BROWSER_FIREFOX```
97
-    - ```RTC_BROWSER_IEXPLORER```
98
-    - ```RTC_BROWSER_SAFARI```
99
-    - ```RTC_BROWSER_NWJS```
100
-    - ```RTC_BROWSER_REACT_NATIVE```
101
-    - ```getBrowserType()``` - gets current browser type.
102
-    - ```isChrome()``` - checks if current browser is Chrome.
103
-    - ```isOpera()``` - checks if current browser is Opera.
104
-    - ```isFirefox()``` - checks if current browser is Firefox.
105
-    - ```isIExplorer()``` - checks if current browser is Internet Explorer.
106
-    - ```isSafari()``` - checks if current browser is Safari.
107
-    - ```isNWJS()``` - checks if current environment is NWJS.
108
-    - ```isReactNative()``` - checks if current environment is React Native.
109
-    - ```isTemasysPluginUsed()``` - checks if Temasys RTC plugin is used.
110
-    - ```getFirefoxVersion()``` - returns Firefox version.
111
-    - ```getChromeVersion()``` - returns Chrome version.
112
-    - ```isAndroid()``` - checks whether the browser is running on an android device.
113
-
114 94
 * ```JitsiMeetJS.events``` - JS object that contains all events used by the API. You will need that JS object when you try to subscribe for connection or conference events.
115 95
     We have two event types - connection and conference. You can access the events with the following code ```JitsiMeetJS.events.<event_type>.<event_name>```.
116 96
     For example if you want to use the conference event that is fired when somebody leave conference you can use the following code - ```JitsiMeetJS.events.conference.USER_LEFT```.
@@ -154,6 +134,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
154 134
 
155 135
     4. mediaDevices
156 136
         - DEVICE_LIST_CHANGED - indicates that list of currently connected devices has changed (parameters - devices(MediaDeviceInfo[])).
137
+        - PERMISSION_PROMPT_IS_SHOWN - Indicates that the environment is currently showing permission prompt to access camera and/or microphone (parameters - environmentType ('chrome'|'opera'|'firefox'|'iexplorer'|'safari'|'nwjs'|'react-native'|'android').
157 138
 
158 139
 
159 140
 * ```JitsiMeetJS.errors``` - JS object that contains all errors used by the API. You can use that object to check the reported errors from the API

Chargement…
Annuler
Enregistrer