Browse Source

Add constants for clarity

customisations
alemart 2 months ago
parent
commit
1ea7d7c4a4
1 changed files with 13 additions and 8 deletions
  1. 13
    8
      src/core/viewport.ts

+ 13
- 8
src/core/viewport.ts View File

109
 /** Time in ms used to throttle the resize callback of the window */
109
 /** Time in ms used to throttle the resize callback of the window */
110
 const RESIZE_THROTTLE_DELAY = 100;
110
 const RESIZE_THROTTLE_DELAY = 100;
111
 
111
 
112
+/** Duration in ms of the polling after a change of orientation */
113
+const ORIENTATION_POLLING_DURATION = 500; // 500 ms for iOS
114
+
115
+/** Number of cycles of the polling */
116
+const ORIENTATION_POLLING_CYCLES = 5; // the more cycles, the quicker a cycle is
117
+
112
 
118
 
113
 
119
 
114
 
120
 
614
     }
620
     }
615
 
621
 
616
     /**
622
     /**
617
-     * Called when a change of screen orientation is detected
623
+     * Called when a change of device orientation is detected
618
      */
624
      */
619
     private async _onOrientationChange(): Promise<void>
625
     private async _onOrientationChange(): Promise<void>
620
     {
626
     {
644
 
650
 
645
         */
651
         */
646
 
652
 
647
-        const MAX_ATTEMPTS = 3; //5;
648
         const canvas = this._viewport._backgroundCanvas;
653
         const canvas = this._viewport._backgroundCanvas;
649
 
654
 
650
-        for(let i = 0; i < MAX_ATTEMPTS; i++) {
655
+        // this is polling
656
+        for(let i = 0; i < ORIENTATION_POLLING_CYCLES; i++) {
651
 
657
 
652
-            // this is polling
653
-            await Utils.wait(RESIZE_THROTTLE_DELAY);
658
+            await Utils.wait(ORIENTATION_POLLING_DURATION / ORIENTATION_POLLING_CYCLES);
654
 
659
 
655
-            // After one delay, this._viewport.aspectRatio will likely be
656
-            // correct, but the canvas will not reflect that if, instants ago,
660
+            // After the camera feed is rotated, this._viewport.aspectRatio will
661
+            // be correct, but the canvas will not reflect that if, instants ago,
657
             // it was resized using the previous aspect ratio of the media.
662
             // it was resized using the previous aspect ratio of the media.
658
             const a = canvas.width / canvas.height;
663
             const a = canvas.width / canvas.height;
659
             const b = this._aspectRatioOfScreen();
664
             const b = this._aspectRatioOfScreen();
684
 
689
 
685
         If so, increasing the throttling will likely make the camera feed be
690
         If so, increasing the throttling will likely make the camera feed be
686
         rotated first, but then the user will more easily notice the delay.
691
         rotated first, but then the user will more easily notice the delay.
687
-        Increasing MAX_ATTEMPTS is a simple alternative that makes this
692
+        Increasing the polling time is a simple alternative that makes this
688
         callback be executed after the video rotation, which is what we want.
693
         callback be executed after the video rotation, which is what we want.
689
         About listening to video resize: the Viewport doesn't know about it
694
         About listening to video resize: the Viewport doesn't know about it
690
         and has no access to the source of data. The Session does, however.
695
         and has no access to the source of data. The Session does, however.

Loading…
Cancel
Save