Replace IS_IOS and IS_ANDROID with platform

This commit is contained in:
infinite-persistence 2022-04-14 20:04:22 +08:00 committed by Thomas Zarebczan
parent c4d11c6c48
commit 49db1fe83b
3 changed files with 10 additions and 18 deletions

View file

@ -23,6 +23,7 @@ import recsys from './plugins/videojs-recsys/plugin';
// import runAds from './ads'; // import runAds from './ads';
import videojs from 'video.js'; import videojs from 'video.js';
import { useIsMobile } from 'effects/use-screensize'; import { useIsMobile } from 'effects/use-screensize';
import { platform } from 'util/platform';
const canAutoplay = require('./plugins/canAutoplay'); const canAutoplay = require('./plugins/canAutoplay');
@ -98,12 +99,7 @@ type Props = {
}; };
const videoPlaybackRates = [0.25, 0.5, 0.75, 1, 1.1, 1.25, 1.5, 1.75, 2]; const videoPlaybackRates = [0.25, 0.5, 0.75, 1, 1.1, 1.25, 1.5, 1.75, 2];
const IS_IOS = platform.isIOS();
const IS_IOS =
(/iPad|iPhone|iPod/.test(navigator.platform) ||
// for iOS 13+ , platform is MacIntel, so use this to test
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream;
if (!Object.keys(videojs.getPlugins()).includes('eventTracking')) { if (!Object.keys(videojs.getPlugins()).includes('eventTracking')) {
videojs.registerPlugin('eventTracking', eventTracking); videojs.registerPlugin('eventTracking', eventTracking);

View file

@ -167,7 +167,12 @@ export const platform = {
// ************************************************************************** // **************************************************************************
isIOS: function () { isIOS: function () {
return this.userAgent().match(/iPhone|iPad|iPod/i) != null; return (
(/iPad|iPhone|iPod/.test(navigator.platform) ||
// for iOS 13+ , platform is MacIntel, so use this to test
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream
);
}, },
isAndroid: function () { isAndroid: function () {

View file

@ -5,6 +5,7 @@ import React, { useEffect } from 'react';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
import Button from 'component/button'; import Button from 'component/button';
import classnames from 'classnames'; import classnames from 'classnames';
import { platform } from 'util/platform';
// prettier-ignore // prettier-ignore
const AD_CONFIGS = Object.freeze({ const AD_CONFIGS = Object.freeze({
@ -22,16 +23,6 @@ const AD_CONFIGS = Object.freeze({
}, },
}); });
const IS_IOS =
(/iPad|iPhone|iPod/.test(navigator.platform) ||
// for iOS 13+ , platform is MacIntel, so use this to test
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream;
const IS_ANDROID = /Android/i.test(navigator.userAgent);
// const IS_FIREFOX = /Firefox/i.test(navigator.userAgent);
// const isFirefoxAndroid = IS_ANDROID && IS_FIREFOX;
// Internal use only. One-time update flag. // Internal use only. One-time update flag.
let ad_blocker_detected; let ad_blocker_detected;
@ -55,7 +46,7 @@ function Ads(props: Props) {
const { type = 'video', tileLayout, small, userHasPremiumPlus, className, doSetAdBlockerFound } = props; const { type = 'video', tileLayout, small, userHasPremiumPlus, className, doSetAdBlockerFound } = props;
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility()); const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
const mobileAds = IS_ANDROID || IS_IOS; const mobileAds = platform.isAndroid() || platform.isIOS();
// this is populated from app based on location // this is populated from app based on location
const isInEu = localStorage.getItem('gdprRequired') === 'true'; const isInEu = localStorage.getItem('gdprRequired') === 'true';