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