浏览代码

feat(ScreenObtainer) initialize support only once

master
Saúl Ibarra Corretgé 6 个月前
父节点
当前提交
18f1f7ca16
共有 1 个文件被更改,包括 20 次插入22 次删除
  1. 20
    22
      modules/RTC/ScreenObtainer.js

+ 20
- 22
modules/RTC/ScreenObtainer.js 查看文件

13
 /**
13
 /**
14
  * Handles obtaining a stream from a screen capture on different browsers.
14
  * Handles obtaining a stream from a screen capture on different browsers.
15
  */
15
  */
16
-const ScreenObtainer = {
16
+class ScreenObtainer {
17
+
17
     /**
18
     /**
18
-     * If not <tt>null</tt> it means that the initialization process is still in
19
-     * progress. It is used to make desktop stream request wait and continue
20
-     * after it's done.
21
-     * {@type Promise|null}
19
+     *
22
      */
20
      */
23
-
24
-    obtainStream: null,
21
+    constructor() {
22
+        this.obtainStream = this._createObtainStreamMethod();
23
+        this.options = {};
24
+        this._electronSkipDisplayMedia = false;
25
+    }
25
 
26
 
26
     /**
27
     /**
27
      * Initializes the function used to obtain a screen capture
28
      * Initializes the function used to obtain a screen capture
31
      */
32
      */
32
     init(options = {}) {
33
     init(options = {}) {
33
         this.options = options;
34
         this.options = options;
34
-        this.obtainStream = this._createObtainStreamMethod();
35
 
35
 
36
         if (!this.obtainStream) {
36
         if (!this.obtainStream) {
37
-            logger.info('Desktop sharing disabled');
37
+            logger.warn('Desktop sharing not supported');
38
         }
38
         }
39
-
40
-        this._electronSkipDisplayMedia = false;
41
-    },
39
+    }
42
 
40
 
43
     /**
41
     /**
44
      * Returns a method which will be used to obtain the screen sharing stream
42
      * Returns a method which will be used to obtain the screen sharing stream
57
         } else if (supportsGetDisplayMedia) {
55
         } else if (supportsGetDisplayMedia) {
58
             return this.obtainScreenFromGetDisplayMedia;
56
             return this.obtainScreenFromGetDisplayMedia;
59
         }
57
         }
60
-        logger.info('Screen sharing not supported on ', browser.getName());
58
+        logger.warn('Screen sharing not supported on ', browser.getName());
61
 
59
 
62
         return null;
60
         return null;
63
-    },
61
+    }
64
 
62
 
65
     /**
63
     /**
66
      * Gets the appropriate constraints for audio sharing.
64
      * Gets the appropriate constraints for audio sharing.
77
         } : true;
75
         } : true;
78
 
76
 
79
         return audio;
77
         return audio;
80
-    },
78
+    }
81
 
79
 
82
     /**
80
     /**
83
      * Checks whether obtaining a screen capture is supported in the current
81
      * Checks whether obtaining a screen capture is supported in the current
86
      */
84
      */
87
     isSupported() {
85
     isSupported() {
88
         return this.obtainStream !== null;
86
         return this.obtainStream !== null;
89
-    },
87
+    }
90
 
88
 
91
     /**
89
     /**
92
      * Obtains a screen capture stream on Electron.
90
      * Obtains a screen capture stream on Electron.
190
         } else {
188
         } else {
191
             onFailure(new JitsiTrackError(JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_NOT_FOUND));
189
             onFailure(new JitsiTrackError(JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_NOT_FOUND));
192
         }
190
         }
193
-    },
191
+    }
194
 
192
 
195
     /**
193
     /**
196
      * Obtains a screen capture stream using getDisplayMedia.
194
      * Obtains a screen capture stream using getDisplayMedia.
349
                     errorCallback(new JitsiTrackError(JitsiTrackErrors.SCREENSHARING_USER_CANCELED));
347
                     errorCallback(new JitsiTrackError(JitsiTrackErrors.SCREENSHARING_USER_CANCELED));
350
                 }
348
                 }
351
             });
349
             });
352
-    },
350
+    }
353
 
351
 
354
     /**
352
     /**
355
      * Obtains a screen capture stream using getDisplayMedia.
353
      * Obtains a screen capture stream using getDisplayMedia.
371
                 errorCallback(new JitsiTrackError(JitsiTrackErrors
369
                 errorCallback(new JitsiTrackError(JitsiTrackErrors
372
                     .SCREENSHARING_USER_CANCELED));
370
                     .SCREENSHARING_USER_CANCELED));
373
             });
371
             });
374
-    },
372
+    }
375
 
373
 
376
     /** Sets the contentHint on the transmitted MediaStreamTrack to indicate charaterstics in the video stream, which
374
     /** Sets the contentHint on the transmitted MediaStreamTrack to indicate charaterstics in the video stream, which
377
      * informs RTCPeerConnection on how to encode the track (to prefer motion or individual frame detail).
375
      * informs RTCPeerConnection on how to encode the track (to prefer motion or individual frame detail).
389
         } else {
387
         } else {
390
             logger.warn('MediaStreamTrack contentHint attribute not supported');
388
             logger.warn('MediaStreamTrack contentHint attribute not supported');
391
         }
389
         }
392
-    },
390
+    }
393
 
391
 
394
     /**
392
     /**
395
      * Sets the max frame rate to be used for a desktop track capture.
393
      * Sets the max frame rate to be used for a desktop track capture.
405
             max: maxFps
403
             max: maxFps
406
         };
404
         };
407
     }
405
     }
408
-};
406
+}
409
 
407
 
410
-export default ScreenObtainer;
408
+export default new ScreenObtainer();

正在加载...
取消
保存