features.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2021-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. export const PluginFeatureDetection = {
  8. get preferWebGl1() {
  9. if (typeof navigator === 'undefined' || typeof window === 'undefined') return false;
  10. // WebGL2 isn't working in MacOS 12.0.1 Safari 15.1, 15.2. It is working in Safari 15.4 tech preview, so disabling all versions before that.
  11. // prefer webgl 1 based on the userAgent substring
  12. const unpportedSafariVersions = [
  13. 'Version/15.1 Safari',
  14. 'Version/15.2 Safari',
  15. 'Version/15.3 Safari',
  16. ];
  17. if (unpportedSafariVersions.some(v => navigator.userAgent.indexOf(v) > 0)) {
  18. return true;
  19. }
  20. // Check for iOS device which enabled WebGL2 recently but it doesn't seem
  21. // to be full up to speed yet.
  22. // adapted from https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
  23. const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
  24. const isAppleDevice = navigator.userAgent.includes('Macintosh');
  25. const isTouchScreen = navigator.maxTouchPoints >= 4; // true for iOS 13 (and hopefully beyond)
  26. return !(window as any).MSStream && (isIOS || (isAppleDevice && isTouchScreen));
  27. },
  28. };