Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Simplify Apple detection #8035

Merged
merged 6 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/polyfill/media_capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ shaka.polyfill.MediaCapabilities = class {
shaka.util.Platform.isPS4() ||
shaka.util.Platform.isWebOS() ||
shaka.util.Platform.isTizen() ||
shaka.util.Platform.isEOS() ||
shaka.util.Platform.isHisense() ||
shaka.util.Platform.isComcastX1()) {
shaka.util.Platform.isWebkitSTB()) {
canUseNativeMCap = false;
}
if (canUseNativeMCap && navigator.mediaCapabilities) {
Expand Down
114 changes: 36 additions & 78 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,8 @@ shaka.util.Platform = class {
* @return {boolean}
*/
static isApple() {
return !!navigator.vendor && navigator.vendor.includes('Apple') &&
!shaka.util.Platform.isTizen() &&
!shaka.util.Platform.isEOS() &&
!shaka.util.Platform.isAPL() &&
!shaka.util.Platform.isAPP() &&
!shaka.util.Platform.isVirginMedia() &&
!shaka.util.Platform.isOrange() &&
!shaka.util.Platform.isPS4() &&
!shaka.util.Platform.isAmazonFireTV() &&
!shaka.util.Platform.isComcastX1() &&
!shaka.util.Platform.isZenterio() &&
!shaka.util.Platform.isSkyQ() &&
!shaka.util.Platform.isMultiChoice();
return shaka.util.Platform.isAppleVendor_() &&
(shaka.util.Platform.isMac() || shaka.util.Platform.isIOS());
}

/**
Expand Down Expand Up @@ -348,14 +337,6 @@ shaka.util.Platform = class {
shaka.util.Platform.userAgentContains_('VIDAA');
}

/**
* Check if the current platform is Virgin Media device.
* @return {boolean}
*/
static isVirginMedia() {
return shaka.util.Platform.userAgentContains_('VirginMedia');
}

/**
* Check if the current platform is Orange.
* @return {boolean}
Expand All @@ -372,16 +353,6 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('Sky_STB');
}

/**
* Check if the current platform is Amazon Fire TV.
* https://developer.amazon.com/docs/fire-tv/identify-amazon-fire-tv-devices.html
*
* @return {boolean}
*/
static isAmazonFireTV() {
return shaka.util.Platform.userAgentContains_('AFT');
}

/**
* Check if the current platform is Comcast X1.
* @return {boolean}
Expand All @@ -398,16 +369,6 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('DT_STB_BCM');
}

/**
* Check if the current platform is a MultiChoice STB.
* @return {boolean}
*/
static isMultiChoice() {
// cspell: ignore MDMP
return shaka.util.Platform.userAgentContains_('MDMP1001S') ||
shaka.util.Platform.userAgentContains_('PS5525IMC');
}

/**
* Returns a major version number for Safari, or Safari-based iOS browsers.
*
Expand Down Expand Up @@ -456,38 +417,11 @@ shaka.util.Platform = class {
}

/**
* Check if the current platform is an EOS set-top box.
*
* Guesses if the platform is an Apple mobile one (iOS, iPad, iPod).
* @return {boolean}
*/
static isEOS() {
return shaka.util.Platform.userAgentContains_('PC=EOS');
}

/**
* Check if the current platform is an APL set-top box.
*
* @return {boolean}
*/
static isAPL() {
return shaka.util.Platform.userAgentContains_('PC=APL');
}

/**
* Check if the current platform is an APPSTB set-top box.
* @return {boolean}
*/
static isAPP() {
return shaka.util.Platform.userAgentContains_('PC=APPSTB');
}

/**
* Guesses if the platform is a mobile one (iOS or Android).
*
* @return {boolean}
*/
static isMobile() {
if (/(?:iPhone|iPad|iPod|Android)/.test(navigator.userAgent)) {
static isIOS() {
if (/(?:iPhone|iPad|iPod)/.test(navigator.userAgent)) {
// This is Android, iOS, or iPad < 13.
return true;
}
Expand All @@ -505,7 +439,18 @@ shaka.util.Platform = class {
// As of January 2020, this is mainly used to adjust the default UI config
// for mobile devices, so it's low risk if something changes to break this
// detection.
return shaka.util.Platform.isApple() && navigator.maxTouchPoints > 1;
return shaka.util.Platform.isAppleVendor_() && navigator.maxTouchPoints > 1;
}

/**
* Guesses if the platform is a mobile one.
* @return {boolean}
*/
static isMobile() {
if (navigator.userAgentData) {
return navigator.userAgentData.mobile;
}
return shaka.util.Platform.isIOS() || shaka.util.Platform.isAndroid();
}

/**
Expand Down Expand Up @@ -540,6 +485,15 @@ shaka.util.Platform = class {
return true;
}

/**
* Checks is non-Apple STB based on Webkit.
* @return {boolean}
*/
static isWebkitSTB() {
return shaka.util.Platform.isAppleVendor_() &&
!shaka.util.Platform.isApple();
}

/**
* Return true if the platform is a Windows, regardless of the browser.
*
Expand Down Expand Up @@ -584,12 +538,8 @@ shaka.util.Platform = class {
const Platform = shaka.util.Platform;
if (Platform.isTizen() || Platform.isWebOS() ||
Platform.isXboxOne() || Platform.isPS4() ||
Platform.isPS5() || Platform.isAmazonFireTV() ||
Platform.isEOS() || Platform.isAPL() ||
Platform.isVirginMedia() || Platform.isOrange() ||
Platform.isComcastX1() || Platform.isChromecast() ||
Platform.isHisense() || Platform.isZenterio() ||
Platform.isAPP() || Platform.isMultiChoice()) {
Platform.isPS5() || Platform.isChromecast() ||
Platform.isHisense() || Platform.isWebkitSTB()) {
return true;
}
return false;
Expand All @@ -609,6 +559,14 @@ shaka.util.Platform = class {
return userAgent.includes(key);
}

/**
* @return {boolean}
* @private
*/
static isAppleVendor_() {
return (navigator.vendor || '').includes('Apple');
}

/**
* For canPlayType queries, we just need any instance.
*
Expand Down
Loading