Skip to content

Commit 970d775

Browse files
tykus160avelad
andauthored
feat: Add Device API (#8210)
The goal is to simplify and abstract feature logic detection. Currently lots of places depend on various calls to `shaka.util.Platform` and mainteinance of this is hard & not easy to read. By introducing device API ideally rest of the player logic would look into device features instead of directly checking platform. Additionally we can more easily cache needed values, so we won't have to parse user agent several times anymore. --------- Co-authored-by: Álvaro Velad Galván <[email protected]>
1 parent 9ac3f51 commit 970d775

File tree

78 files changed

+2727
-1569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2727
-1569
lines changed

build/types/complete

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
+@text
1313
+@optionalText
1414
+@transmuxer
15+
+@devices
1516
+@ui

build/types/core

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
+../../lib/deprecate/enforcer.js
2121
+../../lib/deprecate/version.js
2222

23+
+../../lib/device/abstract_device.js
24+
+../../lib/device/apple_browser.js
25+
+../../lib/device/default_browser.js
26+
+../../lib/device/device_factory.js
27+
+../../lib/device/i_device.js
28+
2329
+../../lib/drm/drm_engine.js
2430
+../../lib/drm/drm_utils.js
2531
+../../lib/drm/fairplay.js
@@ -113,7 +119,6 @@
113119
+../../lib/util/object_utils.js
114120
+../../lib/util/operation_manager.js
115121
+../../lib/util/periods.js
116-
+../../lib/util/platform.js
117122
+../../lib/util/player_configuration.js
118123
+../../lib/util/pssh.js
119124
+../../lib/util/public_promise.js

build/types/devices

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Device
2+
3+
+../../lib/device/chromecast.js
4+
+../../lib/device/hisense.js
5+
+../../lib/device/playstation.js
6+
+../../lib/device/tizen.js
7+
+../../lib/device/vizio.js
8+
+../../lib/device/webkit_stb.js
9+
+../../lib/device/webos.js
10+
+../../lib/device/xbox.js

externs/xbox.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ chrome.webview.hostObjects.sync = {};
6161

6262
/** @const */
6363
chrome.webview.hostObjects.sync.Windows = Windows;
64+
65+
/**
66+
* Typedef for the module interface.
67+
*
68+
* @typedef {typeof Windows}
69+
*/
70+
var WinRT;

lib/ads/interstitial_ad_manager.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ goog.require('shaka.Player');
1212
goog.require('shaka.ads.InterstitialAd');
1313
goog.require('shaka.ads.InterstitialStaticAd');
1414
goog.require('shaka.ads.Utils');
15+
goog.require('shaka.device.DeviceFactory');
16+
goog.require('shaka.device.IDevice');
1517
goog.require('shaka.log');
1618
goog.require('shaka.media.PreloadManager');
1719
goog.require('shaka.net.NetworkingEngine');
@@ -21,7 +23,6 @@ goog.require('shaka.util.Error');
2123
goog.require('shaka.util.EventManager');
2224
goog.require('shaka.util.FakeEvent');
2325
goog.require('shaka.util.IReleasable');
24-
goog.require('shaka.util.Platform');
2526
goog.require('shaka.util.PublicPromise');
2627
goog.require('shaka.util.StringUtils');
2728
goog.require('shaka.util.Timer');
@@ -251,8 +252,7 @@ shaka.ads.InterstitialAdManager = class {
251252
this.baseVideo_, 'seeked', this.onSeeked_);
252253
this.eventManager_.listen(
253254
this.baseVideo_, 'ended', this.checkForInterstitials_);
254-
if ('requestVideoFrameCallback' in this.baseVideo_ &&
255-
!shaka.util.Platform.isSmartTV()) {
255+
if ('requestVideoFrameCallback' in this.baseVideo_ && !this.isSmartTV_()) {
256256
const baseVideo = /** @type {!HTMLVideoElement} */ (this.baseVideo_);
257257
const videoFrameCallback = (now, metadata) => {
258258
if (this.videoCallbackId_ == -1) {
@@ -1080,7 +1080,7 @@ shaka.ads.InterstitialAdManager = class {
10801080
const detachBasePlayerPromise = new shaka.util.PublicPromise();
10811081
const checkState = async (e) => {
10821082
if (e['state'] == 'detach') {
1083-
if (shaka.util.Platform.isSmartTV()) {
1083+
if (this.isSmartTV_()) {
10841084
await new Promise(
10851085
(resolve) => new shaka.util.Timer(resolve).tickAfter(0.1));
10861086
}
@@ -1747,6 +1747,20 @@ shaka.ads.InterstitialAdManager = class {
17471747
return Array.from(this.interstitials_);
17481748
}
17491749

1750+
/**
1751+
* @return {boolean}
1752+
* @private
1753+
*/
1754+
isSmartTV_() {
1755+
const device = shaka.device.DeviceFactory.getDevice();
1756+
const deviceType = device.getDeviceType();
1757+
if (deviceType == shaka.device.IDevice.DeviceType.TV ||
1758+
deviceType == shaka.device.IDevice.DeviceType.CONSOLE ||
1759+
deviceType == shaka.device.IDevice.DeviceType.CAST) {
1760+
return true;
1761+
}
1762+
return false;
1763+
}
17501764

17511765
/**
17521766
* @param {!shaka.extern.AdInterstitial} interstitial

lib/cast/cast_receiver.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ goog.provide('shaka.cast.CastReceiver');
99
goog.require('goog.asserts');
1010
goog.require('shaka.Player');
1111
goog.require('shaka.cast.CastUtils');
12+
goog.require('shaka.device.DeviceFactory');
13+
goog.require('shaka.device.IDevice');
1214
goog.require('shaka.log');
1315
goog.require('shaka.util.Error');
1416
goog.require('shaka.util.EventManager');
1517
goog.require('shaka.util.FakeEvent');
1618
goog.require('shaka.util.FakeEventTarget');
1719
goog.require('shaka.util.IDestroyable');
18-
goog.require('shaka.util.Platform');
1920
goog.require('shaka.util.Timer');
2021

2122

@@ -271,7 +272,9 @@ shaka.cast.CastReceiver = class extends shaka.util.FakeEventTarget {
271272
// browser is a Chromecast before starting the receiver manager. We
272273
// wouldn't do browser detection except for debugging, so only do this in
273274
// uncompiled mode.
274-
if (shaka.util.Platform.isChromecast()) {
275+
const device = shaka.device.DeviceFactory.getDevice();
276+
const deviceType = device.getDeviceType();
277+
if (deviceType === shaka.device.IDevice.DeviceType.CAST) {
275278
manager.start();
276279
}
277280
} else {

0 commit comments

Comments
 (0)