Procházet zdrojové kódy

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

master
tsareg před 9 roky
rodič
revize
714585de88
4 změnil soubory, kde provedl 55 přidání a 26 odebrání
  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 Zobrazit soubor

88
      */
88
      */
89
     removeEventListener: function (event, handler) {
89
     removeEventListener: function (event, handler) {
90
         eventEmitter.removeListener(event, handler);
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 Zobrazit soubor

11
      *  MediaDeviceInfo-like objects that are currently connected.
11
      *  MediaDeviceInfo-like objects that are currently connected.
12
      *  @see https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo
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
 module.exports = JitsiMediaDevicesEvents;
27
 module.exports = JitsiMediaDevicesEvents;

+ 34
- 3
JitsiMeetJS.js Zobrazit soubor

18
 var Resolutions = require("./service/RTC/Resolutions");
18
 var Resolutions = require("./service/RTC/Resolutions");
19
 var ScriptUtil = require("./modules/util/ScriptUtil");
19
 var ScriptUtil = require("./modules/util/ScriptUtil");
20
 var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
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
 function getLowerResolution(resolution) {
27
 function getLowerResolution(resolution) {
23
     if(!Resolutions[resolution])
28
     if(!Resolutions[resolution])
99
      * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
104
      * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
100
      * @param {string} options.cameraDeviceId
105
      * @param {string} options.cameraDeviceId
101
      * @param {string} options.micDeviceId
106
      * @param {string} options.micDeviceId
107
+     * @param {boolean} (firePermissionPromptIsShownEvent) - if event
108
+     *      JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
102
      * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
109
      * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
103
      *     A promise that returns an array of created JitsiTracks if resolved,
110
      *     A promise that returns an array of created JitsiTracks if resolved,
104
      *     or a JitsiConferenceError if rejected.
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
                 if(!RTC.options.disableAudioLevels)
137
                 if(!RTC.options.disableAudioLevels)
110
                     for(var i = 0; i < tracks.length; i++) {
138
                     for(var i = 0; i < tracks.length; i++) {
111
                         var track = tracks[i];
139
                         var track = tracks[i];
120
                                 });
148
                                 });
121
                         }
149
                         }
122
                     }
150
                     }
151
+
123
                 return tracks;
152
                 return tracks;
124
             }).catch(function (error) {
153
             }).catch(function (error) {
154
+                promiseFulfilled = true;
155
+
125
                 Statistics.sendGetUserMediaFailed(error);
156
                 Statistics.sendGetUserMediaFailed(error);
126
 
157
 
127
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
158
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {

+ 3
- 22
doc/API.md Zobrazit soubor

60
 JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
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
     - options - JS object with configuration options for the local media tracks. You can change the following properties there:
64
     - options - JS object with configuration options for the local media tracks. You can change the following properties there:
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.
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
         2. resolution - the prefered resolution for the local video.
66
         2. resolution - the prefered resolution for the local video.
69
         5. minFps - the minimum frame rate for the video stream (passed to GUM)
69
         5. minFps - the minimum frame rate for the video stream (passed to GUM)
70
         6. maxFps - the maximum frame rate for the video stream (passed to GUM)
70
         6. maxFps - the maximum frame rate for the video stream (passed to GUM)
71
         7. facingMode - facing mode for a camera (possible values - 'user', 'environment')
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
 * ```JitsiMeetJS.enumerateDevices(callback)``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.enumerateDevices(callback)``` instead.
74
 * ```JitsiMeetJS.enumerateDevices(callback)``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.enumerateDevices(callback)``` instead.
74
 * ```JitsiMeetJS.isDeviceListAvailable()``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.isDeviceListAvailable()``` instead.
75
 * ```JitsiMeetJS.isDeviceListAvailable()``` - __DEPRECATED__. Use ```JitsiMeetJS.mediaDevices.isDeviceListAvailable()``` instead.
90
     - ```addEventListener(event, handler)``` - attaches an event handler.
91
     - ```addEventListener(event, handler)``` - attaches an event handler.
91
     - ```removeEventListener(event, handler)``` - removes an event handler.
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
 * ```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.
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
     We have two event types - connection and conference. You can access the events with the following code ```JitsiMeetJS.events.<event_type>.<event_name>```.
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
     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```.
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
 
134
 
155
     4. mediaDevices
135
     4. mediaDevices
156
         - DEVICE_LIST_CHANGED - indicates that list of currently connected devices has changed (parameters - devices(MediaDeviceInfo[])).
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
 * ```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
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

Načítá se…
Zrušit
Uložit