From 9b3adadc7db8b1df8b08031cedfd0033c7f8e3b6 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 19 Jul 2023 12:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9ios=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 3 --- src/lib/env.js | 40 ++++++++++++++++++++++++++++------------ src/lib/polyfill.js | 13 +++++++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 618cce0..3754a43 100644 --- a/index.html +++ b/index.html @@ -11,9 +11,6 @@ - {{#if process.env.NODE_ENV === 'development' }} - - {{#/if}}
diff --git a/src/lib/env.js b/src/lib/env.js index 5422c2c..b846eca 100644 --- a/src/lib/env.js +++ b/src/lib/env.js @@ -22,6 +22,9 @@ export const IS_IOS = UA.includes('iphone') || UA.includes('ipad') || UA.includes('ipod') export const IS_MOBILE = IS_ANDROID || IS_IOS || UA.includes('mobile') +const IS_MIUI = IS_ANDROID && (UA.includes('miui') || UA.includes('xiaomi')) +const IS_WECHAT = UA.includes('micromessenger') + const OS_NAME = IS_ANDROID ? 'Android' : IS_IOS @@ -36,9 +39,11 @@ const OS_NAME = IS_ANDROID const OS_VERSION = IS_ANDROID ? UA.match(/android ([\d\.]*?);/)[1] : '' /* 浏览器 */ -export const IS_CHROME = !!window.chrome +export const IS_CHROME = !!window.chrome || (IS_IOS && UA.includes('crios')) export const IS_FIREFOX = 'MozAppearance' in document.documentElement.style -export const IS_SAFARI = (IS_MACOS || IS_IOS) && !!window.safari +export const IS_SAFARI = + (IS_MACOS && !!window.safari) || + (IS_IOS && !IS_CHROME && !IS_FIREFOX && !IS_WECHAT) /* 浏览器名称 */ const BROWSER_NAME = IS_SAFARI @@ -47,21 +52,32 @@ const BROWSER_NAME = IS_SAFARI ? 'Chrome' : IS_FIREFOX ? 'Firefox' + : IS_MIUI + ? 'MiBrowser' + : IS_WECHAT + ? 'WeChat Browser' + : IS_ANDROID + ? 'Android Browser' : 'Unknow' /* 浏览器版本 */ const GENERAL_VERSION = UA.match(/version\/([\d\.]*?) /) || UNKNOW_MATCH -const CHROME_VERSION = UA.match(/chrome\/([\d\.]*?) /) || UNKNOW_MATCH -const IPAD_WEBKIT_VERSION = UA.match(/crios\/([\d\.]*?) /) || GENERAL_VERSION -const FIREFOX_VERSION = UA.match(/firefox\/([\d\.]*)/) || UNKNOW_MATCH +const CHROME_VERSION = UA.match(/chrome\/([\d\.]*?) /) || GENERAL_VERSION +const IOS_CHROME_VERSION = UA.match(/crios\/([\d\.]*?) /) || GENERAL_VERSION +const FIREFOX_VERSION = UA.match(/firefox\/([\d\.]*)/) || GENERAL_VERSION +const WECHAT_VERSOIN = + UA.match(/micromessenger\/([\d\.]*?)\(/) || GENERAL_VERSION -const BROWSER_VERSION = IS_IOS - ? IPAD_WEBKIT_VERSION[1] - : IS_CHROME - ? CHROME_VERSION[1] - : IS_FIREFOX - ? FIREFOX_VERSION[1] - : GENERAL_VERSION[1] +const BROWSER_VERSION = + IS_IOS && !IS_WECHAT + ? IOS_CHROME_VERSION[1] + : IS_CHROME || IS_ANDROID + ? CHROME_VERSION[1] + : IS_FIREFOX + ? FIREFOX_VERSION[1] + : IS_WECHAT + ? WECHAT_VERSOIN[1] + : GENERAL_VERSION[1] // 是否支持 Import assertions export const SUPPORT_ASSERTIONS = IS_CHROME diff --git a/src/lib/polyfill.js b/src/lib/polyfill.js index f505314..2ba23e9 100644 --- a/src/lib/polyfill.js +++ b/src/lib/polyfill.js @@ -11,3 +11,16 @@ if (!Array.prototype.sum) { } }) } + +if (!window.MediaSource) { + window.MediaSource = { + isTypeSupported(type) { + let ctx = document.createElement('video') + let res = ctx.canPlayType(type) + if (res === 'maybe' || res === 'probably') { + return true + } + return false + } + } +}