HelioWebXRPolyfill.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @author mvilledieu / http://github.com/mvilledieu
  3. */
  4. if ( /(Helio)/g.test( navigator.userAgent ) && 'xr' in navigator ) {
  5. console.log( "Helio WebXR Polyfill (Lumin 0.98.0)" );
  6. if ( 'isSessionSupported' in navigator.xr ) {
  7. const tempIsSessionSupported = navigator.xr.isSessionSupported.bind( navigator.xr );
  8. navigator.xr.isSessionSupported = function ( /*sessionType*/ ) {
  9. // Force using immersive-ar
  10. return tempIsSessionSupported( 'immersive-ar' );
  11. };
  12. }
  13. if ( 'isSessionSupported' in navigator.xr && 'requestSession' in navigator.xr ) {
  14. const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr );
  15. navigator.xr.requestSession = function ( /*sessionType*/ ) {
  16. return new Promise( function ( resolve, reject ) {
  17. var sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor' ] };
  18. tempRequestSession( 'immersive-ar', sessionInit ).then( function ( session ) {
  19. resolve( session );
  20. } ).catch( function ( error ) {
  21. return reject( error );
  22. } );
  23. } );
  24. };
  25. }
  26. }