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