Ver código fonte

fix(JitsiMeetJS): Preserve JitsiMeetJS namespace if it's already created

master
hristoterezov 7 anos atrás
pai
commit
fa24ac5289
1 arquivos alterados com 59 adições e 24 exclusões
  1. 59
    24
      JitsiMeetJS.js

+ 59
- 24
JitsiMeetJS.js Ver arquivo

@@ -33,17 +33,19 @@ import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
33 33
 
34 34
 const logger = Logger.getLogger(__filename);
35 35
 
36
-// The amount of time to wait until firing
37
-// JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN event
36
+/**
37
+ * The amount of time to wait until firing
38
+ * {@link JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN} event.
39
+ */
38 40
 const USER_MEDIA_PERMISSION_PROMPT_TIMEOUT = 1000;
39 41
 
40 42
 /**
41
- * Gets the next lowest desirable resolution to try for a camera.  If the given
42
- * resolution is already the lowest acceptable resolution, returns null.
43
+ * Gets the next lowest desirable resolution to try for a camera. If the given
44
+ * resolution is already the lowest acceptable resolution, returns {@code null}.
43 45
  *
44 46
  * @param resolution the current resolution
45
- * @return the next lowest resolution from the given one, or null if it is
46
- * already the lowest acceptable resolution.
47
+ * @return the next lowest resolution from the given one, or {@code null} if it
48
+ * is already the lowest acceptable resolution.
47 49
  */
48 50
 function getLowerResolution(resolution) {
49 51
     if (!Resolutions[resolution]) {
@@ -70,9 +72,8 @@ function getLowerResolution(resolution) {
70 72
 }
71 73
 
72 74
 /**
73
- * Extracts from an 'options' objects with a specific format
74
- * (TODO what IS the format?) the attributes which are to be logged in analytics
75
- * events.
75
+ * Extracts from an 'options' objects with a specific format (TODO what IS the
76
+ * format?) the attributes which are to be logged in analytics events.
76 77
  *
77 78
  * @param options gum options (???)
78 79
  * @returns {*} the attributes to attach to analytics events.
@@ -95,9 +96,36 @@ function getAnalyticsAttributesFromOptions(options) {
95 96
 }
96 97
 
97 98
 /**
98
- * The public API of the Jitsi Meet library (a.k.a. JitsiMeetJS).
99
+ * Tries to deal with the following problem: {@code JitsiMeetJS} is not only
100
+ * this module, it's also a global (i.e. attached to {@code window}) namespace
101
+ * for all globals of the projects in the Jitsi Meet family. If lib-jitsi-meet
102
+ * is loaded through an HTML {@code script} tag, {@code JitsiMeetJS} will
103
+ * automatically be attached to {@code window} by webpack. Unfortunately,
104
+ * webpack's source code does not check whether the global variable has already
105
+ * been assigned and overwrites it. Which is OK for the module
106
+ * {@code JitsiMeetJS} but is not OK for the namespace {@code JitsiMeetJS}
107
+ * because it may already contain the values of other projects in the Jitsi Meet
108
+ * family. The solution offered here works around webpack by merging all
109
+ * existing values of the namespace {@code JitsiMeetJS} into the module
110
+ * {@code JitsiMeetJS}.
111
+ *
112
+ * @param {Object} module - The module {@code JitsiMeetJS} (which will be
113
+ * exported and may be attached to {@code window} by webpack later on).
114
+ * @private
115
+ * @returns {Object} - A {@code JitsiMeetJS} module which contains all existing
116
+ * value of the namespace {@code JitsiMeetJS} (if any).
117
+ */
118
+function _mergeNamespaceAndModule(module) {
119
+    return (
120
+        typeof window.JitsiMeetJS === 'object'
121
+            ? Object.assign({}, window.JitsiMeetJS, module)
122
+            : module);
123
+}
124
+
125
+/**
126
+ * The public API of the Jitsi Meet library (a.k.a. {@code JitsiMeetJS}).
99 127
  */
100
-export default {
128
+export default _mergeNamespaceAndModule({
101 129
 
102 130
     version: '{#COMMIT_HASH#}',
103 131
 
@@ -147,8 +175,8 @@ export default {
147 175
                 this.getGlobalOnErrorHandler.bind(this));
148 176
         }
149 177
 
150
-        // Log deployment-specific information, if available.
151
-        // Defined outside the application by individual deployments
178
+        // Log deployment-specific information, if available. Defined outside
179
+        // the application by individual deployments
152 180
         const aprops = options.deploymentInfo;
153 181
 
154 182
         if (aprops && Object.keys(aprops).length > 0) {
@@ -179,6 +207,7 @@ export default {
179 207
 
180 208
     /**
181 209
      * Returns whether the desktop sharing is enabled or not.
210
+     *
182 211
      * @returns {boolean}
183 212
      */
184 213
     isDesktopSharingEnabled() {
@@ -190,6 +219,7 @@ export default {
190 219
 
191 220
     /**
192 221
      * Sets the log level to the <tt>Logger</tt> instance with given id.
222
+     *
193 223
      * @param {Logger.levels} level the logging level to be set
194 224
      * @param {string} id the logger id to which new logging level will be set.
195 225
      * Usually it's the name of the JavaScript source file including the path
@@ -201,6 +231,7 @@ export default {
201 231
 
202 232
     /**
203 233
      * Registers new global logger transport to the library logging framework.
234
+     *
204 235
      * @param globalTransport
205 236
      * @see Logger.addGlobalTransport
206 237
      */
@@ -210,6 +241,7 @@ export default {
210 241
 
211 242
     /**
212 243
      * Removes global logging transport from the library logging framework.
244
+     *
213 245
      * @param globalTransport
214 246
      * @see Logger.removeGlobalTransport
215 247
      */
@@ -219,6 +251,7 @@ export default {
219 251
 
220 252
     /**
221 253
      * Creates the media tracks and returns them trough the callback.
254
+     *
222 255
      * @param options Object with properties / settings specifying the tracks
223 256
      * which should be created. should be created or some additional
224 257
      * configurations about resolution for example.
@@ -253,12 +286,12 @@ export default {
253 286
      * will finish the execution with rejected Promise.
254 287
      *
255 288
      * @param {boolean} (firePermissionPromptIsShownEvent) - if event
256
-     *      JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
289
+     * JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
257 290
      * @param originalOptions - internal use only, to be able to store the
258 291
      * originally requested options.
259
-     * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
260
-     *     A promise that returns an array of created JitsiTracks if resolved,
261
-     *     or a JitsiConferenceError if rejected.
292
+     * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>} A promise
293
+     * that returns an array of created JitsiTracks if resolved, or a
294
+     * JitsiConferenceError if rejected.
262 295
      */
263 296
     createLocalTracks(
264 297
             options = {}, firePermissionPromptIsShownEvent, originalOptions) {
@@ -353,9 +386,8 @@ export default {
353 386
                             originalOptions || Object.assign({}, options));
354 387
                     }
355 388
 
356
-                    // we tried everything, if there is a mandatory
357
-                    // device id, remove it and let gum find a device to
358
-                    // use
389
+                    // We tried everything. If there is a mandatory device id,
390
+                    // remove it and let gum find a device to use.
359 391
                     if (originalOptions
360 392
                         && error.gum.constraints
361 393
                         && error.gum.constraints.video
@@ -422,6 +454,7 @@ export default {
422 454
 
423 455
     /**
424 456
      * Checks if its possible to enumerate available cameras/microphones.
457
+     *
425 458
      * @returns {Promise<boolean>} a Promise which will be resolved only once
426 459
      * the WebRTC stack is ready, either with true if the device listing is
427 460
      * available available or with false otherwise.
@@ -437,9 +470,10 @@ export default {
437 470
     /**
438 471
      * Returns true if changing the input (camera / microphone) or output
439 472
      * (audio) device is supported and false if not.
440
-     * @params {string} [deviceType] - type of device to change. Default is
441
-     *      undefined or 'input', 'output' - for audio output device change.
442
-     * @returns {boolean} true if available, false otherwise.
473
+     *
474
+     * @param {string} [deviceType] - type of device to change. Default is
475
+     * {@code undefined} or 'input', 'output' - for audio output device change.
476
+     * @returns {boolean} {@code true} if available; {@code false}, otherwise.
443 477
      * @deprecated use JitsiMeetJS.mediaDevices.isDeviceChangeAvailable instead
444 478
      */
445 479
     isDeviceChangeAvailable(deviceType) {
@@ -472,6 +506,7 @@ export default {
472 506
 
473 507
     /**
474 508
      * Executes callback with list of media devices connected.
509
+     *
475 510
      * @param {function} callback
476 511
      * @deprecated use JitsiMeetJS.mediaDevices.enumerateDevices instead
477 512
      */
@@ -511,4 +546,4 @@ export default {
511 546
         ScriptUtil,
512 547
         browser
513 548
     }
514
-};
549
+});

Carregando…
Cancelar
Salvar