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