Source: lib/device/webkit_stb.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2025 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.device.WebKitSTB');
  7. goog.require('shaka.device.AbstractDevice');
  8. goog.require('shaka.device.DeviceFactory');
  9. goog.require('shaka.device.IDevice');
  10. goog.require('shaka.util.Lazy');
  11. /**
  12. * @final
  13. */
  14. shaka.device.WebKitSTB = class extends shaka.device.AbstractDevice {
  15. constructor() {
  16. super();
  17. /**
  18. * SkyQ STB
  19. *
  20. * @private {!shaka.util.Lazy<boolean>}
  21. */
  22. this.isSkyQ_ = new shaka.util.Lazy(() => {
  23. return navigator.userAgent.includes('DT_STB_BCM') ||
  24. navigator.userAgent.includes('Sky_STB');
  25. });
  26. /**
  27. * Orange STB
  28. *
  29. * @private {!shaka.util.Lazy<boolean>}
  30. */
  31. this.isOrange_ = new shaka.util.Lazy(() => {
  32. return navigator.userAgent.includes('SOPOpenBrowser');
  33. });
  34. /** @private {!shaka.util.Lazy<?number>} */
  35. this.version_ = new shaka.util.Lazy(() => {
  36. if (navigator.userAgent.includes('DT_STB_BCM')) {
  37. return 11;
  38. }
  39. // This works for iOS Safari and desktop Safari, which contain something
  40. // like "Version/13.0" indicating the major Safari or iOS version.
  41. let match = navigator.userAgent.match(/Version\/(\d+)/);
  42. if (match) {
  43. return parseInt(match[1], /* base= */ 10);
  44. }
  45. // This works for all other browsers on iOS, which contain something like
  46. // "OS 13_3" indicating the major & minor iOS version.
  47. match = navigator.userAgent.match(/OS (\d+)(?:_\d+)?/);
  48. if (match) {
  49. return parseInt(match[1], /* base= */ 10);
  50. }
  51. return null;
  52. });
  53. }
  54. /**
  55. * @override
  56. */
  57. getVersion() {
  58. return this.version_.value();
  59. }
  60. /**
  61. * @override
  62. */
  63. getDeviceName() {
  64. return 'WebKit STB';
  65. }
  66. /**
  67. * @override
  68. */
  69. getDeviceType() {
  70. return shaka.device.IDevice.DeviceType.TV;
  71. }
  72. /**
  73. * @override
  74. */
  75. getBrowserEngine() {
  76. return shaka.device.IDevice.BrowserEngine.WEBKIT;
  77. }
  78. /**
  79. * @override
  80. */
  81. supportsMediaCapabilities() {
  82. return false;
  83. }
  84. /**
  85. * @override
  86. */
  87. supportsSequenceMode() {
  88. // See: https://bugs.webkit.org/show_bug.cgi?id=210341
  89. const version = this.version_.value();
  90. return version !== null ? version >= 15 : true;
  91. }
  92. /**
  93. * @override
  94. */
  95. requiresEncryptionInfoInAllInitSegments(keySystem) {
  96. return this.isOrange_.value();
  97. }
  98. /**
  99. * @override
  100. */
  101. detectMaxHardwareResolution() {
  102. const maxResolution = {
  103. width: window.screen.width * window.devicePixelRatio,
  104. height: window.screen.height * window.devicePixelRatio,
  105. };
  106. return Promise.resolve(maxResolution);
  107. }
  108. /**
  109. * @override
  110. */
  111. supportsEncryptionSchemePolyfill() {
  112. return !this.isSkyQ_.value();
  113. }
  114. /**
  115. * @override
  116. */
  117. supportsContainerChangeType() {
  118. return false;
  119. }
  120. /**
  121. * @return {boolean}
  122. * @private
  123. */
  124. static isWebkitSTB_() {
  125. if (navigator.userAgent.includes('SOPOpenBrowser')) {
  126. return true;
  127. }
  128. if (navigator.userAgent.includes('DT_STB_BCM') ||
  129. navigator.userAgent.includes('Sky_STB')) {
  130. return true;
  131. }
  132. if (!(navigator.vendor || '').includes('Apple')) {
  133. return false;
  134. }
  135. if (/(?:iPhone|iPad|iPod)/.test(navigator.userAgent) ||
  136. navigator.maxTouchPoints > 1) {
  137. return false;
  138. }
  139. if (navigator.userAgentData && navigator.userAgentData.platform &&
  140. navigator.userAgentData.platform.toLowerCase() == 'macos') {
  141. return false;
  142. } else if (navigator.platform &&
  143. navigator.platform.toLowerCase().includes('mac')) {
  144. return false;
  145. }
  146. return true;
  147. }
  148. };
  149. if (shaka.device.WebKitSTB.isWebkitSTB_()) {
  150. shaka.device.DeviceFactory.registerDeviceFactory(
  151. () => new shaka.device.WebKitSTB());
  152. }