File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import { AudioZonesSystem } from "./audio-zones-system";
3030import { GainSystem } from "./audio-gain-system" ;
3131import { EnvironmentSystem } from "./environment-system" ;
3232import { NameTagVisibilitySystem } from "./name-tag-visibility-system" ;
33+ import { MediaPDFOculusFix } from "./media-pdf-oculus-fix" ;
3334
3435// new world
3536import { networkReceiveSystem } from "../bit-systems/network-receive-system" ;
@@ -136,6 +137,7 @@ AFRAME.registerSystem("hubs-systems", {
136137 this . drawingMenuSystem = new DrawingMenuSystem ( this . el ) ;
137138 this . characterController = new CharacterControllerSystem ( this . el ) ;
138139 this . waypointSystem = new WaypointSystem ( this . el , this . characterController ) ;
140+ this . mediaPDFOculusFix = new MediaPDFOculusFix ( this . el ) ;
139141 this . cursorPoseTrackingSystem = new CursorPoseTrackingSystem ( ) ;
140142 this . menuAnimationSystem = new MenuAnimationSystem ( ) ;
141143 this . audioSettingsSystem = new AudioSettingsSystem ( this . el ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ PDFjs which is used to render pdfs depends on the window.requestAnimationFrame function.
3+ This is not called when in mobileVR.
4+ This system replaces the function with the requestAnimationFrame of the xrSession.
5+ It restores window.requestAnimationFrame when the user leaves xr.
6+ */
7+ export class MediaPDFOculusFix {
8+ constructor ( sceneEl ) {
9+ // PC VR calls window.requestAnimationFrame even in VR mode
10+ if ( AFRAME . utils . device . isMobileVR ( ) ) {
11+ this . requestAnimationFrameOriginal = window . requestAnimationFrame ;
12+ this . cancelAnimationFrameOriginal = window . cancelAnimationFrame ;
13+ sceneEl . addEventListener ( "enter-vr" , ( ) => {
14+ console . debug ( `PDF: monkey-patching window.requestAnimationFrame:` , window . requestAnimationFrame ) ;
15+ const { xrSession } = sceneEl ;
16+ window . requestAnimationFrame = callback => {
17+ return xrSession ?. requestAnimationFrame ( callback ) ;
18+ } ;
19+ window . cancelAnimationFrame = handle => {
20+ return xrSession ?. cancelAnimationFrame ( handle ) ;
21+ } ;
22+ } ) ;
23+ sceneEl . addEventListener ( "exit-vr" , ( ) => {
24+ console . debug ( `PDF: removing window.requestAnimationFrame monkey-patch` , this . requestAnimationFrameOriginal ) ;
25+ window . requestAnimationFrame = this . requestAnimationFrameOriginal ;
26+ window . cancelAnimationFrame = this . cancelAnimationFrameOriginal ;
27+ } ) ;
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ declare module "aframe" {
5252 drawingMenuSystem : DrawingMenuSystem ;
5353 characterController : CharacterControllerSystem ;
5454 waypointSystem : WaypointSystem ;
55+ mediaPDFOculusFix : MediaPDFOculusFix ;
5556 cursorPoseTrackingSystem : CursorPoseTrackingSystem ;
5657 menuAnimationSystem : MenuAnimationSystem ;
5758 audioSettingsSystem : AudioSettingsSystem ;
You can’t perform that action at this time.
0 commit comments