Procházet zdrojové kódy

fix(SS): implement interval to check the status of the ext after install

dev1
hristoterezov před 9 roky
rodič
revize
8fe23a63bc
1 změnil soubory, kde provedl 53 přidání a 21 odebrání
  1. 53
    21
      modules/RTC/ScreenObtainer.js

+ 53
- 21
modules/RTC/ScreenObtainer.js Zobrazit soubor

226
      * 'desktop' stream for returned stream token.
226
      * 'desktop' stream for returned stream token.
227
      */
227
      */
228
     obtainScreenFromExtension: function(options, streamCallback, failCallback) {
228
     obtainScreenFromExtension: function(options, streamCallback, failCallback) {
229
-        var self = this;
230
         if (chromeExtInstalled) {
229
         if (chromeExtInstalled) {
231
             doGetStreamFromExtension(this.options, streamCallback,
230
             doGetStreamFromExtension(this.options, streamCallback,
232
                 failCallback);
231
                 failCallback);
240
             try {
239
             try {
241
                 chrome.webstore.install(
240
                 chrome.webstore.install(
242
                     getWebStoreInstallUrl(this.options),
241
                     getWebStoreInstallUrl(this.options),
243
-                    function (arg) {
242
+                    (arg) => {
244
                         logger.log("Extension installed successfully", arg);
243
                         logger.log("Extension installed successfully", arg);
245
                         chromeExtInstalled = true;
244
                         chromeExtInstalled = true;
246
                         // We need to give a moment for the endpoint to become
245
                         // We need to give a moment for the endpoint to become
247
                         // available
246
                         // available
248
-                        window.setTimeout(function () {
249
-                            doGetStreamFromExtension(self.options,
250
-                                streamCallback, failCallback);
251
-                        }, 2000);
247
+                        waitForExtensionAfterInstall(this.options, 200, 10)
248
+                            .then(() => {
249
+                                doGetStreamFromExtension(this.options,
250
+                                    streamCallback, failCallback);
251
+                            }).catch(() => {
252
+                                // options param is {} because we won't do
253
+                                // external install in this case.
254
+                                this.handleExtensionInstallationError({},
255
+                                    streamCallback, failCallback);
256
+                            });
252
                     },
257
                     },
253
                     this.handleExtensionInstallationError.bind(this,
258
                     this.handleExtensionInstallationError.bind(this,
254
                         options, streamCallback, failCallback)
259
                         options, streamCallback, failCallback)
287
                 JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR));
292
                 JitsiTrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR));
288
             return;
293
             return;
289
         }
294
         }
290
-        var self = this;
291
-        window.setTimeout(function () {
292
-            checkChromeExtInstalled(function (installed, updateRequired) {
293
-                chromeExtInstalled = installed;
294
-                chromeExtUpdateRequired = updateRequired;
295
-                if(installed) {
296
-                    options.listener("extensionFound");
297
-                    self.obtainScreenFromExtension(options,
298
-                        streamCallback, failCallback);
299
-                } else {
300
-                    self.checkForChromeExtensionOnInterval(options,
301
-                        streamCallback, failCallback);
302
-                }
303
-            }, self.options);
304
-        }, options.interval);
295
+        waitForExtensionAfterInstall(this.options, options.interval, 1)
296
+            .then(() => {
297
+                chromeExtInstalled = true;
298
+                options.listener("extensionFound");
299
+                this.obtainScreenFromExtension(options,
300
+                    streamCallback, failCallback);
301
+            }).catch(() => {
302
+                this.checkForChromeExtensionOnInterval(options,
303
+                    streamCallback, failCallback);
304
+            });
305
     }
305
     }
306
 };
306
 };
307
 
307
 
487
     }, options);
487
     }, options);
488
 }
488
 }
489
 
489
 
490
+/**
491
+ * Checks "retries" times on every "waitInterval"ms whether the ext is alive.
492
+ * @param {Object} options the options passed to ScreanObtainer.obtainStream
493
+ * @param {int} waitInterval the number of ms between retries
494
+ * @param {int} retries the number of retries
495
+ * @returns {Promise} returns promise that will be resolved when the extension
496
+ * is alive and rejected if the extension is not alive even after "retries"
497
+ * checks
498
+ */
499
+function waitForExtensionAfterInstall(options, waitInterval, retries) {
500
+    if(retries === 0) {
501
+        return Promise.reject();
502
+    }
503
+    return new Promise((resolve, reject) => {
504
+        let currentRetries = retries;
505
+        let interval = window.setInterval(() => {
506
+            checkChromeExtInstalled( (installed) => {
507
+                if(installed) {
508
+                    window.clearInterval(interval);
509
+                    resolve();
510
+                } else {
511
+                    currentRetries--;
512
+                    if(currentRetries === 0) {
513
+                        reject();
514
+                        window.clearInterval(interval);
515
+                    }
516
+                }
517
+            }, options);
518
+        }, waitInterval);
519
+    });
520
+}
521
+
490
 /**
522
 /**
491
  * Starts the detection of an installed jidesha extension for firefox.
523
  * Starts the detection of an installed jidesha extension for firefox.
492
  * @param options supports "desktopSharingFirefoxDisabled",
524
  * @param options supports "desktopSharingFirefoxDisabled",

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