Browse Source

Session: make non-existent primary sources acceptable

customisations
alemart 10 months ago
parent
commit
666086e08f
1 changed files with 14 additions and 17 deletions
  1. 14
    17
      src/core/session.ts

+ 14
- 17
src/core/session.ts View File

110
     private readonly _viewport: Viewport;
110
     private readonly _viewport: Viewport;
111
 
111
 
112
     /** Primary source of data */
112
     /** Primary source of data */
113
-    private readonly _primarySource: VideoSource | CanvasSource;
113
+    private readonly _primarySource: Nullable<VideoSource | CanvasSource>;
114
 
114
 
115
     /** Time Manager */
115
     /** Time Manager */
116
     private _time: TimeManager;
116
     private _time: TimeManager;
171
 
171
 
172
         // setup the viewport
172
         // setup the viewport
173
         this._viewport = viewport;
173
         this._viewport = viewport;
174
-        this._viewport._init(() => this._media.size, mode);
174
+        if(this._primarySource !== null)
175
+            this._viewport._init(() => this._primarySource!._data.size, mode);
176
+        else
177
+            this._viewport._init(() => Utils.resolution('sm', window.innerWidth / window.innerHeight), mode);
175
 
178
 
176
         // setup the main loop
179
         // setup the main loop
177
         this._setupUpdateLoop();
180
         this._setupUpdateLoop();
486
     /**
489
     /**
487
      * Find the primary source of data (generally a camera stream)
490
      * Find the primary source of data (generally a camera stream)
488
      * @param sources
491
      * @param sources
489
-     * @returns the primary source
492
+     * @returns the primary source, or null if there isn't any
490
      */
493
      */
491
-    private _findPrimarySource(sources: Source[]): VideoSource | CanvasSource
494
+    private _findPrimarySource(sources: Source[]): Nullable<VideoSource | CanvasSource>
492
     {
495
     {
493
         // prefer video sources
496
         // prefer video sources
494
         for(let i = 0; i < sources.length; i++) {
497
         for(let i = 0; i < sources.length; i++) {
500
                 return sources[i] as CanvasSource;
503
                 return sources[i] as CanvasSource;
501
         }
504
         }
502
 
505
 
503
-        // this shouldn't happen
504
-        throw new IllegalOperationError(`No primary source of data was found!`);
505
-    }
506
-
507
-    /**
508
-     * The media of the primary source of data
509
-     */
510
-    private get _media(): SpeedyMedia
511
-    {
512
-        return this._primarySource._data;
506
+        // emit warning
507
+        Utils.warning(`No primary source of data was found!`);
508
+        return null;
513
     }
509
     }
514
 
510
 
515
     /**
511
     /**
533
      */
529
      */
534
     private _renderUserMedia(): void
530
     private _renderUserMedia(): void
535
     {
531
     {
532
+        const media = this._primarySource?._data;
536
         const canvas = this._viewport._backgroundCanvas;
533
         const canvas = this._viewport._backgroundCanvas;
537
         const ctx = canvas.getContext('2d', { alpha: false });
534
         const ctx = canvas.getContext('2d', { alpha: false });
538
-        
539
-        if(ctx && this._media.type != 'data') {
535
+
536
+        if(ctx && media && media.type != 'data') {
540
             ctx.imageSmoothingEnabled = false;
537
             ctx.imageSmoothingEnabled = false;
541
 
538
 
542
             // draw user media
539
             // draw user media
543
-            const image = this._media.source as CanvasImageSource;
540
+            const image = media.source as CanvasImageSource;
544
             ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
541
             ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
545
 
542
 
546
             // render output image(s)
543
             // render output image(s)

Loading…
Cancel
Save