Source: ui/externs/ui.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @externs
  8. * @suppress {duplicate} To prevent compiler errors with the namespace
  9. * being declared both here and by goog.provide in the library.
  10. */
  11. /** @namespace */
  12. var shaka = {};
  13. /** @namespace */
  14. shaka.extern = {};
  15. /**
  16. * @typedef {{
  17. * base: string,
  18. * buffered: string,
  19. * played: string,
  20. * adBreaks: string
  21. * }}
  22. *
  23. * @property {string} base
  24. * The CSS background color applied to the base of the seek bar, on top of
  25. * which the buffer level and playback position are shown.
  26. * @property {string} buffered
  27. * The CSS background color applied to the portion of the seek bar showing
  28. * what has been buffered ahead of the playback position.
  29. * @property {string} played
  30. * The CSS background color applied to the portion of the seek bar showing
  31. * what has been played already.
  32. * @property {string} adBreaks
  33. * The CSS background color applied to the portion of the seek bar showing
  34. * when the ad breaks are scheduled to occur on the timeline.
  35. * @exportDoc
  36. */
  37. shaka.extern.UISeekBarColors;
  38. /**
  39. * @typedef {{
  40. * base: string,
  41. * level: string
  42. * }}
  43. *
  44. * @property {string} base
  45. * The CSS background color applied to the base of the volume bar, on top of
  46. * which the volume level is shown.
  47. * @property {string} level
  48. * The CSS background color applied to the portion of the volume bar showing
  49. * the volume level.
  50. * @exportDoc
  51. */
  52. shaka.extern.UIVolumeBarColors;
  53. /**
  54. * @description
  55. * The UI's configuration options.
  56. *
  57. * @typedef {{
  58. * controlPanelElements: !Array.<string>,
  59. * overflowMenuButtons: !Array.<string>,
  60. * addSeekBar: boolean,
  61. * addBigPlayButton: boolean,
  62. * castReceiverAppId: string,
  63. * clearBufferOnQualityChange: boolean,
  64. * showUnbufferedStart: boolean,
  65. * seekBarColors: shaka.extern.UISeekBarColors,
  66. * volumeBarColors: shaka.extern.UIVolumeBarColors,
  67. * trackLabelFormat: shaka.ui.Overlay.TrackLabelFormat,
  68. * fadeDelay: number,
  69. * doubleClickForFullscreen: boolean,
  70. * enableKeyboardPlaybackControls: boolean,
  71. * enableFullscreenOnRotation: boolean,
  72. * forceLandscapeOnFullscreen: boolean
  73. * }}
  74. *
  75. * @property {!Array.<string>} controlPanelElements
  76. * The ordered list of control panel elements of the UI.
  77. * @property {!Array.<string>} overflowMenuButtons
  78. * The ordered list of the overflow menu buttons.
  79. * @property {boolean} addSeekBar
  80. * Whether or not a seek bar should be part of the UI.
  81. * @property {boolean} addBigPlayButton
  82. * Whether or not a big play button in the center of the video
  83. * should be part of the UI.
  84. * @property {string} castReceiverAppId
  85. * Receiver app id to use for the Chromecast support.
  86. * @property {boolean} clearBufferOnQualityChange
  87. * Only applicable if the resolution selection is part of the UI.
  88. * Whether buffer should be cleared when changing resolution
  89. * via UI. Clearing buffer would result in immidiate change of quality,
  90. * but playback may flicker/stall for a sec as the content in new
  91. * resolution is being buffered. Not clearing the buffer will mean
  92. * we play the content in the previously selected resolution that we
  93. * already have buffered before switching to the new resolution.
  94. * @property {boolean} showUnbufferedStart
  95. * If true, color any unbuffered region at the start of the seek bar as
  96. * unbuffered (using the "base" color). If false, color any unbuffered region
  97. * at the start of the seek bar as played (using the "played" color).
  98. * <br>
  99. * A value of false matches the default behavior of Chrome's native controls
  100. * and Shaka Player v3.0+.
  101. * <br>
  102. * A value of true matches the default behavior of Shaka Player v2.5.
  103. * <br>
  104. * Defaults to false.
  105. * @property {shaka.extern.UISeekBarColors} seekBarColors
  106. * The CSS colors applied to the seek bar. This allows you to override the
  107. * colors used in the linear gradient constructed in JavaScript, since you
  108. * cannot easily do this in pure CSS.
  109. * @property {shaka.extern.UIVolumeBarColors} volumeBarColors
  110. * The CSS colors applied to the volume bar. This allows you to override the
  111. * colors used in the linear gradient constructed in JavaScript, since you
  112. * cannot do this in pure CSS.
  113. * @property {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat
  114. * An enum that determines what is shown in the labels for text track and
  115. * audio variant selection.
  116. * LANGUAGE means that only the language of the item is shown.
  117. * ROLE means that only the role of the item is shown.
  118. * LANGUAGE_ROLE means both language and role are shown, or just language if
  119. * there is no role.
  120. * LABEL means the non-standard DASH "label" attribute or the HLS "NAME"
  121. * attribute are shown.
  122. * Defaults to LANGUAGE.
  123. * @property {number} fadeDelay
  124. * The delay (in seconds) before fading out the controls once the user stops
  125. * interacting with them. We recommend setting this to 3 on your cast
  126. * receiver UI.
  127. * Defaults to 0.
  128. * @property {boolean} doubleClickForFullscreen
  129. * Whether or not double-clicking on the UI should cause it to enter
  130. * fullscreen.
  131. * Defaults to true.
  132. * @property {boolean} enableKeyboardPlaybackControls
  133. * Whether or not playback controls via keyboard is enabled, such as seek
  134. * forward, seek backward, jump to the beginning/end of the video.
  135. * Defaults to true.
  136. * @property {boolean} enableFullscreenOnRotation
  137. * Whether or not to enter/exit fullscreen mode when the screen is rotated.
  138. * Defaults to true.
  139. * @property {boolean} forceLandscapeOnFullscreen
  140. * Whether or not the device should rotate to landscape mode when the video
  141. * enters fullscreen. Note that this behavior is based on an experimental
  142. * browser API, and may not work on all platforms.
  143. * Defaults to true.
  144. * @exportDoc
  145. */
  146. shaka.extern.UIConfiguration;
  147. /**
  148. * Interface for UI elements. UI elements should inherit from the concrete base
  149. * class shaka.ui.Element. The members defined in this extern's constructor are
  150. * all available from the base class, and are defined here to keep the compiler
  151. * from renaming them.
  152. *
  153. * @extends {shaka.util.IReleasable}
  154. * @interface
  155. * @exportDoc
  156. */
  157. shaka.extern.IUIElement = class {
  158. /**
  159. * @param {!HTMLElement} parent
  160. * @param {!shaka.ui.Controls} controls
  161. */
  162. constructor(parent, controls) {
  163. /**
  164. * @protected {HTMLElement}
  165. * @exportDoc
  166. */
  167. this.parent;
  168. /**
  169. * @protected {shaka.ui.Controls}
  170. * @exportDoc
  171. */
  172. this.controls;
  173. /**
  174. * @protected {shaka.util.EventManager}
  175. * @exportDoc
  176. */
  177. this.eventManager;
  178. /**
  179. * @protected {shaka.ui.Localization}
  180. * @exportDoc
  181. */
  182. this.localization;
  183. /**
  184. * @protected {shaka.Player}
  185. * @exportDoc
  186. */
  187. this.player;
  188. /**
  189. * @protected {HTMLMediaElement}
  190. * @exportDoc
  191. */
  192. this.video;
  193. /**
  194. * @protected {shaka.extern.IAdManager}
  195. * @exportDoc
  196. */
  197. this.adManager;
  198. /**
  199. * @protected {shaka.extern.IAd}
  200. * @exportDoc
  201. */
  202. this.ad;
  203. }
  204. /**
  205. * @override
  206. */
  207. release() {}
  208. };
  209. /**
  210. * A factory for creating a UI element.
  211. *
  212. * @interface
  213. * @exportDoc
  214. */
  215. shaka.extern.IUIElement.Factory = class {
  216. /**
  217. * @param {!HTMLElement} rootElement
  218. * @param {!shaka.ui.Controls} controls
  219. * @return {!shaka.extern.IUIElement}
  220. */
  221. create(rootElement, controls) {}
  222. };
  223. /**
  224. * Interface for UI range elements. UI range elements should inherit from the
  225. * concrete base class shaka.ui.RangeElement. The members defined in this
  226. * extern's constructor are all available from the base class, and are defined
  227. * here to keep the compiler from renaming them.
  228. *
  229. * @extends {shaka.extern.IUIElement}
  230. * @interface
  231. * @exportDoc
  232. */
  233. shaka.extern.IUIRangeElement = class {
  234. /**
  235. * @param {!HTMLElement} parent
  236. * @param {!shaka.ui.Controls} controls
  237. * @param {!Array.<string>} containerClassNames
  238. * @param {!Array.<string>} barClassNames
  239. */
  240. constructor(parent, controls, containerClassNames, barClassNames) {
  241. /**
  242. * @protected {!HTMLElement}
  243. * @exportDoc
  244. */
  245. this.container;
  246. /**
  247. * @protected {!HTMLInputElement}
  248. * @exportDoc
  249. */
  250. this.bar;
  251. }
  252. /**
  253. * @param {number} min
  254. * @param {number} max
  255. */
  256. setRange(min, max) {}
  257. /**
  258. * Called when user interaction begins.
  259. * To be overridden by subclasses.
  260. */
  261. onChangeStart() {}
  262. /**
  263. * Called when a new value is set by user interaction.
  264. * To be overridden by subclasses.
  265. */
  266. onChange() {}
  267. /**
  268. * Called when user interaction ends.
  269. * To be overridden by subclasses.
  270. */
  271. onChangeEnd() {}
  272. /** @return {number} */
  273. getValue() {}
  274. /** @param {number} value */
  275. setValue(value) {}
  276. /** @param {number} value */
  277. changeTo(value) {}
  278. };
  279. /**
  280. * Interface for UI settings menus. UI settings menus should inherit from the
  281. * concrete base class shaka.ui.SettingsMenu. The members defined in this
  282. * extern's constructor are all available from the base class, and are defined
  283. * here to keep the compiler from renaming them.
  284. *
  285. * @extends {shaka.extern.IUIElement}
  286. * @interface
  287. * @exportDoc
  288. */
  289. shaka.extern.IUISettingsMenu = class {
  290. /**
  291. * @param {!HTMLElement} parent
  292. * @param {!shaka.ui.Controls} controls
  293. * @param {string} iconText
  294. */
  295. constructor(parent, controls, iconText) {
  296. /**
  297. * @protected {!HTMLButtonElement}
  298. * @exportDoc
  299. */
  300. this.button;
  301. /**
  302. * @protected {!HTMLElement}
  303. * @exportDoc
  304. */
  305. this.icon;
  306. /**
  307. * @protected {!HTMLElement}
  308. * @exportDoc
  309. */
  310. this.nameSpan;
  311. /**
  312. * @protected {!HTMLElement}
  313. * @exportDoc
  314. */
  315. this.currentSelection;
  316. /**
  317. * @protected {!HTMLElement}
  318. * @exportDoc
  319. */
  320. this.menu;
  321. /**
  322. * @protected {!HTMLButtonElement}
  323. * @exportDoc
  324. */
  325. this.backButton;
  326. /**
  327. * @protected {!HTMLElement}
  328. * @exportDoc
  329. */
  330. this.backSpan;
  331. }
  332. };
  333. /**
  334. * Interface for SeekBars. SeekBars should inherit from the concrete base
  335. * class shaka.ui.Element. If you do not need to totaly rebuild the
  336. * SeekBar, you should consider using shaka.ui.RangeElement or
  337. * shaka.ui.SeekBar as your base class.
  338. *
  339. * @extends {shaka.extern.IUIRangeElement}
  340. * @interface
  341. * @exportDoc
  342. */
  343. shaka.extern.IUISeekBar = class {
  344. /** @return {number} */
  345. getValue() {}
  346. /** @param {number} value */
  347. setValue(value) {}
  348. /**
  349. * Called by Controls on a timer to update the state of the seek bar.
  350. * Also called internally when the user interacts with the input element.
  351. */
  352. update() {}
  353. /** @return {boolean} */
  354. isShowing() {}
  355. };
  356. /**
  357. * A factory for creating a SeekBar element.
  358. *
  359. * @interface
  360. * @exportDoc
  361. */
  362. shaka.extern.IUISeekBar.Factory = class {
  363. /**
  364. * @param {!HTMLElement} rootElement
  365. * @param {!shaka.ui.Controls} controls
  366. * @return {!shaka.extern.IUISeekBar}
  367. */
  368. create(rootElement, controls) {}
  369. };