Files
shaka-player/lib/device/hisense.js
T
Wojciech Tyczyński 970d7756ea 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 <ladvan91@hotmail.com>
2025-06-02 13:46:40 +02:00

101 lines
2.1 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.device.Hisense');
goog.require('shaka.device.AbstractDevice');
goog.require('shaka.device.DeviceFactory');
goog.require('shaka.device.IDevice');
goog.require('shaka.log');
/**
* @final
*/
shaka.device.Hisense = class extends shaka.device.AbstractDevice {
/**
* @override
*/
getVersion() {
return null;
}
/**
* @override
*/
getDeviceName() {
return 'Hisense';
}
/**
* @override
*/
getDeviceType() {
return shaka.device.IDevice.DeviceType.TV;
}
/**
* @override
*/
supportsMediaCapabilities() {
return false;
}
/**
* @override
*/
detectMaxHardwareResolution() {
const maxResolution = {width: 1920, height: 1080};
let supports4k = null;
if (window.Hisense_Get4KSupportState) {
try {
// eslint-disable-next-line new-cap
supports4k = window.Hisense_Get4KSupportState();
} catch (e) {
shaka.log.debug('Hisense: Failed to get 4K support state', e);
}
}
if (supports4k == null) {
// If API is not there or not working for whatever reason, fallback to
// user agent check, as it contains UHD or FHD info.
supports4k = navigator.userAgent.includes('UHD');
}
if (supports4k) {
maxResolution.width = 3840;
maxResolution.height = 2160;
}
return Promise.resolve(maxResolution);
}
/**
* @override
*/
adjustConfig(config) {
super.adjustConfig(config);
// Hisense has long hardware pipeline that respond slowly to seeking.
// Therefore we should not seek when we detect a stall on this platform.
// Instead, default stallSkip to 0 to force the stall detector to pause
// and play instead.
config.streaming.stallSkip = 0;
return config;
}
/**
* @return {boolean}
* @private
*/
static isHisense_() {
return navigator.userAgent.includes('Hisense') ||
navigator.userAgent.includes('VIDAA');
}
};
if (shaka.device.Hisense.isHisense_()) {
shaka.device.DeviceFactory.registerDeviceFactory(
() => new shaka.device.Hisense());
}