ソースを参照

feat: add 'disableDesktopSharing' option (#548)

* feat: add 'disableDesktopSharing' option

* ref(ScreenObtainer): simplify init
dev1
Paweł Domas 8年前
コミット
a6abae2e61
2個のファイルの変更91行の追加56行の削除
  1. 19
    18
      doc/API.md
  2. 72
    38
      modules/RTC/ScreenObtainer.js

+ 19
- 18
doc/API.md ファイルの表示

@@ -38,24 +38,25 @@ You can access the following methods and objects trough ```JitsiMeetJS``` object
38 38
 
39 39
 *  ```JitsiMeetJS.init(options)``` - this method initialized Jitsi Meet API.
40 40
 The ```options``` parameter is JS object with the following properties:
41
-    1. useIPv6 - boolean property
42
-    2. desktopSharingChromeExtId - The ID of the jidesha extension for Chrome. Example: 'mbocklcggfhnbahlnepmldehdhpjfcjp'
43
-    3. desktopSharingChromeDisabled - Boolean. Whether desktop sharing should be disabled on Chrome. Example: false.
44
-    4. desktopSharingChromeSources - Array of strings with the media sources to use when using screen sharing with the Chrome extension. Example: ['screen', 'window']
45
-    5. desktopSharingChromeMinExtVersion - Required version of Chrome extension. Example: '0.1'
46
-    6. desktopSharingFirefoxExtId - The ID of the jidesha extension for Firefox. If null, we assume that no extension is required.
47
-    7. desktopSharingFirefoxDisabled - Boolean. Whether desktop sharing should be disabled on Firefox. Example: false.
48
-    8. desktopSharingFirefoxMaxVersionExtRequired - The maximum version of Firefox which requires a jidesha extension. Example: if set to 41, we will require the extension for Firefox versions up to and including 41. On Firefox 42 and higher, we will run without the extension. If set to -1, an extension will be required for all versions of Firefox.
49
-    9. desktopSharingFirefoxExtensionURL - The URL to the Firefox extension for desktop sharing. "null" if no extension is required.
50
-    10. disableAudioLevels - boolean property. Enables/disables audio levels.
51
-    11. disableSimulcast - boolean property. Enables/disables simulcast.
52
-    12. enableWindowOnErrorHandler - boolean property (default false). Enables/disables attaching global onerror handler (window.onerror).
53
-    13. disableThirdPartyRequests - if true - callstats will be disabled and the callstats API won't be included.
54
-    14. enableAnalyticsLogging - boolean property (default false). Enables/disables analytics logging.
55
-    15. callStatsCustomScriptUrl - (optional) custom url to access callstats client script
56
-    16. callStatsConfIDNamespace - (optional) a namespace to prepend the callstats conference ID with. Defaults to the window.location.hostname
57
-    17. disableRtx - (optional) boolean property (default to false).  Enables/disable the use of RTX.
58
-    18. preferH264 - (optional) boolean property (default to false).  Enables/disable preferring the first instance of an h264 codec in an offer by moving it to the front of the codec list.
41
+    - `useIPv6` - boolean property
42
+    - `disableDesktopSharing` - Boolean. When set to true disables desktop sharing on all browsers. 
43
+    - `desktopSharingChromeExtId` - The ID of the jidesha extension for Chrome. Example: 'mbocklcggfhnbahlnepmldehdhpjfcjp'
44
+    - `desktopSharingChromeDisabled` - Boolean. Whether desktop sharing should be disabled on Chrome. Example: false.
45
+    - `desktopSharingChromeSources` - Array of strings with the media sources to use when using screen sharing with the Chrome extension. Example: ['screen', 'window']
46
+    - `desktopSharingChromeMinExtVersion` - Required version of Chrome extension. Example: '0.1'
47
+    - `desktopSharingFirefoxExtId` - The ID of the jidesha extension for Firefox. If null, we assume that no extension is required.
48
+    - `desktopSharingFirefoxDisabled` - Boolean. Whether desktop sharing should be disabled on Firefox. Example: false.
49
+    - `desktopSharingFirefoxMaxVersionExtRequired` - The maximum version of Firefox which requires a jidesha extension. Example: if set to 41, we will require the extension for Firefox versions up to and including 41. On Firefox 42 and higher, we will run without the extension. If set to -1, an extension will be required for all versions of Firefox.
50
+    - `desktopSharingFirefoxExtensionURL` - The URL to the Firefox extension for desktop sharing. "null" if no extension is required.
51
+    - `disableAudioLevels` - boolean property. Enables/disables audio levels.
52
+    - `disableSimulcast` - boolean property. Enables/disables simulcast.
53
+    - `enableWindowOnErrorHandler` - boolean property (default false). Enables/disables attaching global onerror handler (window.onerror).
54
+    - `disableThirdPartyRequests` - if true - callstats will be disabled and the callstats API won't be included.
55
+    - `enableAnalyticsLogging` - boolean property (default false). Enables/disables analytics logging.
56
+    - `callStatsCustomScriptUrl` - (optional) custom url to access callstats client script
57
+    - `callStatsConfIDNamespace` - (optional) a namespace to prepend the callstats conference ID with. Defaults to the window.location.hostname
58
+    - `disableRtx` - (optional) boolean property (default to false).  Enables/disable the use of RTX.
59
+    - `preferH264` - (optional) boolean property (default to false).  Enables/disable preferring the first instance of an h264 codec in an offer by moving it to the front of the codec list.
59 60
 
60 61
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
61 62
 

+ 72
- 38
modules/RTC/ScreenObtainer.js ファイルの表示

@@ -66,29 +66,53 @@ const ScreenObtainer = {
66 66
      * Initializes the function used to obtain a screen capture
67 67
      * (this.obtainStream).
68 68
      *
69
-     * @param options {object}
70
-     * @param gum {Function} GUM method
69
+     * @param {object} options
70
+     * @param {boolean} [options.disableDesktopSharing]
71
+     * @param {boolean} [options.desktopSharingChromeDisabled]
72
+     * @param {boolean} [options.desktopSharingChromeExtId]
73
+     * @param {boolean} [options.desktopSharingFirefoxDisabled]
74
+     * @param {boolean} [options.desktopSharingFirefoxExtId] (deprecated)
75
+     * @param {Function} gum GUM method
71 76
      */
72
-    init(options, gum) {
73
-        let obtainDesktopStream = null;
74
-
77
+    init(options = {
78
+        disableDesktopSharing: false,
79
+        desktopSharingChromeDisabled: false,
80
+        desktopSharingChromeExtId: null,
81
+        desktopSharingFirefoxDisabled: false,
82
+        desktopSharingFirefoxExtId: null
83
+    }, gum) {
75 84
         // eslint-disable-next-line no-param-reassign
76 85
         this.options = options = options || {};
77 86
         gumFunction = gum;
78 87
 
79
-        if (RTCBrowserType.isFirefox()) {
80
-            initFirefoxExtensionDetection(options);
88
+        this.obtainStream
89
+            = this.options.disableDesktopSharing
90
+                ? null : this._createObtainStreamMethod(options);
91
+
92
+        if (!this.obtainStream) {
93
+            logger.info('Desktop sharing disabled');
81 94
         }
95
+    },
82 96
 
97
+    /**
98
+     * Returns a method which will be used to obtain the screen sharing stream
99
+     * (based on the browser type).
100
+     *
101
+     * @param {object} options passed from {@link init} - check description
102
+     * there
103
+     * @returns {Function}
104
+     * @private
105
+     */
106
+    _createObtainStreamMethod(options) {
83 107
         if (RTCBrowserType.isNWJS()) {
84
-            obtainDesktopStream = (_, onSuccess, onFailure) => {
108
+            return (_, onSuccess, onFailure) => {
85 109
                 window.JitsiMeetNW.obtainDesktopStream(
86 110
                     onSuccess,
87 111
                     (error, constraints) => {
88 112
                         let jitsiError;
89 113
 
90 114
                         // FIXME:
91
-                        // This is very very durty fix for recognising that the
115
+                        // This is very very dirty fix for recognising that the
92 116
                         // user have clicked the cancel button from the Desktop
93 117
                         // sharing pick window. The proper solution would be to
94 118
                         // detect this in the NWJS application by checking the
@@ -116,57 +140,67 @@ const ScreenObtainer = {
116 140
                     });
117 141
             };
118 142
         } else if (RTCBrowserType.isElectron()) {
119
-            obtainDesktopStream = this.obtainScreenOnElectron;
143
+            return this.obtainScreenOnElectron;
120 144
         } else if (RTCBrowserType.isTemasysPluginUsed()) {
121 145
             // XXX Don't require Temasys unless it's to be used because it
122 146
             // doesn't run on React Native, for example.
123 147
             const plugin
124 148
                 = require('./adapter.screenshare').WebRTCPlugin.plugin;
125 149
 
126
-            if (plugin.HasScreensharingFeature) {
127
-                if (plugin.isScreensharingAvailable) {
128
-                    obtainDesktopStream = obtainWebRTCScreen;
129
-                    logger.info('Using Temasys plugin for desktop sharing');
130
-                } else {
131
-                    logger.info(
132
-                        'Screensharing not available with Temasys plugin on'
133
-                            + ' this site');
134
-                }
135
-            } else {
136
-                logger.info(
150
+            if (!plugin.HasScreensharingFeature) {
151
+                logger.warn(
137 152
                     'Screensharing not supported by this plugin version');
153
+
154
+                return null;
155
+            } else if (!plugin.isScreensharingAvailable) {
156
+                logger.warn(
157
+                    'Screensharing not available with Temasys plugin on'
158
+                        + ' this site');
159
+
160
+                return null;
138 161
             }
162
+
163
+            logger.info('Using Temasys plugin for desktop sharing');
164
+
165
+            return obtainWebRTCScreen;
139 166
         } else if (RTCBrowserType.isChrome()) {
140
-            if (options.desktopSharingChromeDisabled
167
+            if (RTCBrowserType.getChromeVersion() < 34) {
168
+                logger.info('Chrome extension not supported until ver 34');
169
+
170
+                return null;
171
+            } else if (options.desktopSharingChromeDisabled
141 172
                 || options.desktopSharingChromeMethod === false
142 173
                 || !options.desktopSharingChromeExtId) {
174
+
143 175
                 // TODO: desktopSharingChromeMethod is deprecated, remove.
144
-                obtainDesktopStream = null;
145
-            } else if (RTCBrowserType.getChromeVersion() >= 34) {
146
-                obtainDesktopStream
147
-                    = this.obtainScreenFromExtension;
148
-                logger.info('Using Chrome extension for desktop sharing');
149
-                initChromeExtension(options);
150
-            } else {
151
-                logger.info('Chrome extension not supported until ver 34');
176
+                return null;
152 177
             }
178
+
179
+            logger.info('Using Chrome extension for desktop sharing');
180
+            initChromeExtension(options);
181
+
182
+            return this.obtainScreenFromExtension;
153 183
         } else if (RTCBrowserType.isFirefox()) {
154 184
             if (options.desktopSharingFirefoxDisabled) {
155
-                obtainDesktopStream = null;
185
+                return null;
156 186
             } else if (window.location.protocol === 'http:') {
157 187
                 logger.log('Screen sharing is not supported over HTTP. '
158 188
                     + 'Use of HTTPS is required.');
159
-                obtainDesktopStream = null;
160
-            } else {
161
-                obtainDesktopStream = this.obtainScreenOnFirefox;
189
+
190
+                return null;
162 191
             }
163
-        }
164 192
 
165
-        if (!obtainDesktopStream) {
166
-            logger.info('Desktop sharing disabled');
193
+            initFirefoxExtensionDetection(options);
194
+
195
+            return this.obtainScreenOnFirefox;
167 196
         }
168 197
 
169
-        this.obtainStream = obtainDesktopStream;
198
+        logger.warn(
199
+            'Screen sharing not supported by the current browser: ',
200
+            RTCBrowserType.getBrowserType(),
201
+            RTCBrowserType.getBrowserName());
202
+
203
+        return null;
170 204
     },
171 205
 
172 206
     /**

読み込み中…
キャンセル
保存