@gcorevideo/player 2.19.14 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/assets/level-selector/list.ejs +2 -2
  2. package/dist/core.js +2 -2
  3. package/dist/index.css +780 -780
  4. package/dist/index.js +1720 -1473
  5. package/dist/player.d.ts +425 -94
  6. package/dist/plugins/index.css +1466 -1466
  7. package/dist/plugins/index.js +1501 -1252
  8. package/docs/api/player.bottomgear.getelement.md +56 -0
  9. package/docs/api/player.bottomgear.md +51 -0
  10. package/docs/api/player.bottomgear.setcontent.md +56 -0
  11. package/docs/api/player.clapprnerdstats.md +12 -259
  12. package/docs/api/player.dvrcontrols.md +5 -1
  13. package/docs/api/player.errorscreen.attributes.md +3 -0
  14. package/docs/api/player.errorscreen.bindevents.md +3 -0
  15. package/docs/api/player.errorscreen.container.md +3 -0
  16. package/docs/api/player.errorscreen.hide.md +3 -0
  17. package/docs/api/player.errorscreen.md +27 -0
  18. package/docs/api/player.errorscreen.name.md +3 -0
  19. package/docs/api/player.errorscreen.render.md +3 -0
  20. package/docs/api/player.errorscreen.show.md +3 -0
  21. package/docs/api/player.errorscreen.supportedversion.md +3 -0
  22. package/docs/api/player.errorscreen.template.md +3 -0
  23. package/docs/api/player.errorscreen.unbindevents.md +3 -0
  24. package/docs/api/player.gearevents.md +49 -0
  25. package/docs/api/{player.sourcecontroller.name.md → player.gearitemelement.md} +5 -3
  26. package/docs/api/{player.playbackrate.template.md → player.initeventdata.event.md} +3 -3
  27. package/docs/api/{player.playbackrate.updateplaybackrate.md → player.initeventdata.md} +15 -11
  28. package/docs/api/player.levelselector.md +9 -1
  29. package/docs/api/player.md +124 -4
  30. package/docs/api/{player.clapprnerdstats.render.md → player.mediacontrol.getrightpanel.md} +8 -4
  31. package/docs/api/player.mediacontrol.md +14 -0
  32. package/docs/api/player.mediacontrolelement.md +1 -1
  33. package/docs/api/player.pictureinpicture.md +9 -197
  34. package/docs/api/player.playbackrate.md +10 -314
  35. package/docs/api/player.sourcecontroller.md +0 -90
  36. package/docs/api/player.spinnerevents.md +49 -0
  37. package/docs/api/player.spinnerthreebounce._constructor_.md +3 -0
  38. package/docs/api/player.spinnerthreebounce.hide.md +5 -0
  39. package/docs/api/player.spinnerthreebounce.md +14 -95
  40. package/docs/api/player.spinnerthreebounce.show.md +6 -37
  41. package/docs/api/{player.playbackrate.onplay.md → player.stalleventdata.count.md} +5 -7
  42. package/docs/api/{player.playbackrate.name.md → player.stalleventdata.event.md} +3 -3
  43. package/docs/api/player.stalleventdata.md +112 -0
  44. package/docs/api/player.stalleventdata.time.md +13 -0
  45. package/docs/api/player.stalleventdata.total_ms.md +13 -0
  46. package/docs/api/{player.pluginsettings.md → player.starteventdata.event.md} +3 -5
  47. package/docs/api/{player.playbackrate.onrateselect.md → player.starteventdata.md} +15 -11
  48. package/docs/api/player.subtitles.hide.md +5 -0
  49. package/docs/api/player.subtitles.md +23 -275
  50. package/docs/api/player.subtitles.show.md +5 -0
  51. package/docs/api/{player.statistics._constructor_.md → player.telemetry._constructor_.md} +6 -3
  52. package/docs/api/player.telemetry.md +146 -0
  53. package/docs/api/{player.volumefade.name.md → player.telemetry.name.md} +4 -2
  54. package/docs/api/{player.sourcecontroller.supportedversion.md → player.telemetry.supportedversion.md} +4 -2
  55. package/docs/api/player.telemetryevent.md +89 -0
  56. package/docs/api/player.telemetryeventdata.md +15 -0
  57. package/docs/api/player.telemetrypluginsettings.md +57 -0
  58. package/docs/api/player.telemetrypluginsettings.send.md +13 -0
  59. package/docs/api/player.telemetryrecord.md +17 -0
  60. package/docs/api/player.volumefade.md +0 -93
  61. package/docs/api/{player.pictureinpicture.name.md → player.watcheventdata.event.md} +3 -3
  62. package/docs/api/{player.playbackrate.setselectedrate.md → player.watcheventdata.md} +15 -11
  63. package/lib/index.plugins.d.ts +2 -2
  64. package/lib/index.plugins.d.ts.map +1 -1
  65. package/lib/index.plugins.js +2 -2
  66. package/lib/playback/hls-playback/HlsPlayback.js +1 -1
  67. package/lib/plugins/bottom-gear/BottomGear.d.ts +20 -1
  68. package/lib/plugins/bottom-gear/BottomGear.d.ts.map +1 -1
  69. package/lib/plugins/bottom-gear/BottomGear.js +28 -7
  70. package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.d.ts +38 -5
  71. package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.d.ts.map +1 -1
  72. package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.js +67 -21
  73. package/lib/plugins/dvr-controls/DvrControls.d.ts +5 -2
  74. package/lib/plugins/dvr-controls/DvrControls.d.ts.map +1 -1
  75. package/lib/plugins/dvr-controls/DvrControls.js +5 -2
  76. package/lib/plugins/error-screen/ErrorScreen.d.ts +5 -0
  77. package/lib/plugins/error-screen/ErrorScreen.d.ts.map +1 -1
  78. package/lib/plugins/error-screen/ErrorScreen.js +5 -0
  79. package/lib/plugins/index.d.ts +2 -3
  80. package/lib/plugins/index.d.ts.map +1 -1
  81. package/lib/plugins/index.js +2 -3
  82. package/lib/plugins/level-selector/LevelSelector.d.ts +10 -3
  83. package/lib/plugins/level-selector/LevelSelector.d.ts.map +1 -1
  84. package/lib/plugins/level-selector/LevelSelector.js +20 -19
  85. package/lib/plugins/media-control/MediaControl.d.ts +6 -2
  86. package/lib/plugins/media-control/MediaControl.d.ts.map +1 -1
  87. package/lib/plugins/media-control/MediaControl.js +40 -39
  88. package/lib/plugins/picture-in-picture/PictureInPicture.d.ts +32 -4
  89. package/lib/plugins/picture-in-picture/PictureInPicture.d.ts.map +1 -1
  90. package/lib/plugins/picture-in-picture/PictureInPicture.js +30 -2
  91. package/lib/plugins/playback-rate/PlaybackRate.d.ts +47 -14
  92. package/lib/plugins/playback-rate/PlaybackRate.d.ts.map +1 -1
  93. package/lib/plugins/playback-rate/PlaybackRate.js +38 -9
  94. package/lib/plugins/source-controller/SourceController.d.ts +9 -0
  95. package/lib/plugins/source-controller/SourceController.d.ts.map +1 -1
  96. package/lib/plugins/source-controller/SourceController.js +11 -1
  97. package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.d.ts +35 -1
  98. package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.d.ts.map +1 -1
  99. package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.js +46 -23
  100. package/lib/plugins/statistics/Statistics.d.ts +38 -3
  101. package/lib/plugins/statistics/Statistics.d.ts.map +1 -1
  102. package/lib/plugins/statistics/Statistics.js +51 -9
  103. package/lib/plugins/subtitles/Subtitles.d.ts +65 -16
  104. package/lib/plugins/subtitles/Subtitles.d.ts.map +1 -1
  105. package/lib/plugins/subtitles/Subtitles.js +131 -109
  106. package/lib/plugins/telemetry/Telemetry.d.ts +135 -0
  107. package/lib/plugins/telemetry/Telemetry.d.ts.map +1 -0
  108. package/lib/plugins/telemetry/Telemetry.js +180 -0
  109. package/lib/plugins/volume-fade/VolumeFade.d.ts +7 -1
  110. package/lib/plugins/volume-fade/VolumeFade.d.ts.map +1 -1
  111. package/lib/plugins/volume-fade/VolumeFade.js +8 -1
  112. package/package.json +1 -1
  113. package/src/index.plugins.ts +2 -2
  114. package/src/playback/hls-playback/HlsPlayback.ts +1 -1
  115. package/src/plugins/bottom-gear/BottomGear.ts +26 -4
  116. package/src/plugins/clappr-nerd-stats/ClapprNerdStats.ts +240 -173
  117. package/src/plugins/dvr-controls/DvrControls.ts +5 -2
  118. package/src/plugins/error-screen/ErrorScreen.ts +5 -0
  119. package/src/plugins/index.ts +2 -3
  120. package/src/plugins/level-selector/LevelSelector.ts +22 -19
  121. package/src/plugins/level-selector/__tests__/LevelSelector.test.ts +47 -26
  122. package/src/plugins/level-selector/__tests__/__snapshots__/LevelSelector.test.ts.snap +18 -18
  123. package/src/plugins/media-control/MediaControl.ts +43 -41
  124. package/src/plugins/picture-in-picture/PictureInPicture.ts +35 -7
  125. package/src/plugins/playback-rate/PlaybackRate.ts +53 -24
  126. package/src/plugins/source-controller/SourceController.ts +11 -1
  127. package/src/plugins/source-controller/__tests__/SourceController.test.ts +1 -1
  128. package/src/plugins/spinner-three-bounce/SpinnerThreeBounce.ts +46 -22
  129. package/src/plugins/subtitles/Subtitles.ts +146 -155
  130. package/src/plugins/telemetry/Telemetry.ts +299 -0
  131. package/src/plugins/volume-fade/VolumeFade.ts +9 -2
  132. package/temp/player.api.json +3384 -4872
  133. package/tsconfig.tsbuildinfo +1 -1
  134. package/docs/api/player.clapprnerdstats.attributes.md +0 -17
  135. package/docs/api/player.clapprnerdstats.bindevents.md +0 -18
  136. package/docs/api/player.clapprnerdstats.events.md +0 -18
  137. package/docs/api/player.clapprnerdstats.name.md +0 -14
  138. package/docs/api/player.clapprnerdstats.playerheight.md +0 -14
  139. package/docs/api/player.clapprnerdstats.playerwidth.md +0 -14
  140. package/docs/api/player.clapprnerdstats.statsboxelem.md +0 -14
  141. package/docs/api/player.clapprnerdstats.statsboxwidththreshold.md +0 -14
  142. package/docs/api/player.clapprnerdstats.supportedversion.md +0 -16
  143. package/docs/api/player.clapprnerdstats.template.md +0 -14
  144. package/docs/api/player.pictureinpicture.bindevents.md +0 -15
  145. package/docs/api/player.pictureinpicture.events.md +0 -13
  146. package/docs/api/player.pictureinpicture.exitpictureinpicture.md +0 -15
  147. package/docs/api/player.pictureinpicture.render.md +0 -15
  148. package/docs/api/player.pictureinpicture.requestpictureinpicture.md +0 -15
  149. package/docs/api/player.pictureinpicture.supportedversion.md +0 -13
  150. package/docs/api/player.pictureinpicture.togglepictureinpicture.md +0 -15
  151. package/docs/api/player.pictureinpicture.version.md +0 -11
  152. package/docs/api/player.pictureinpicture.videoelement.md +0 -11
  153. package/docs/api/player.playbackrate.attributes.md +0 -14
  154. package/docs/api/player.playbackrate.bindevents.md +0 -15
  155. package/docs/api/player.playbackrate.events.md +0 -15
  156. package/docs/api/player.playbackrate.gettitle.md +0 -15
  157. package/docs/api/player.playbackrate.goback.md +0 -15
  158. package/docs/api/player.playbackrate.highlightcurrentrate.md +0 -15
  159. package/docs/api/player.playbackrate.onfinishad.md +0 -15
  160. package/docs/api/player.playbackrate.onshowmenu.md +0 -15
  161. package/docs/api/player.playbackrate.onstartad.md +0 -15
  162. package/docs/api/player.playbackrate.onstop.md +0 -15
  163. package/docs/api/player.playbackrate.reload.md +0 -15
  164. package/docs/api/player.playbackrate.render.md +0 -15
  165. package/docs/api/player.playbackrate.supportedversion.md +0 -13
  166. package/docs/api/player.playbackrate.unbindevents.md +0 -15
  167. package/docs/api/player.sourcecontroller.version.md +0 -14
  168. package/docs/api/player.spinnerthreebounce.attributes.md +0 -14
  169. package/docs/api/player.spinnerthreebounce.name.md +0 -11
  170. package/docs/api/player.spinnerthreebounce.render.md +0 -15
  171. package/docs/api/player.spinnerthreebounce.supportedversion.md +0 -13
  172. package/docs/api/player.statistics.bindevents.md +0 -15
  173. package/docs/api/player.statistics.md +0 -141
  174. package/docs/api/player.statistics.name.md +0 -11
  175. package/docs/api/player.statistics.supportedversion.md +0 -13
  176. package/docs/api/player.subtitles.attributes.md +0 -14
  177. package/docs/api/player.subtitles.bindevents.md +0 -15
  178. package/docs/api/player.subtitles.buttonelement.md +0 -15
  179. package/docs/api/player.subtitles.events.md +0 -14
  180. package/docs/api/player.subtitles.levelelement.md +0 -51
  181. package/docs/api/player.subtitles.name.md +0 -11
  182. package/docs/api/player.subtitles.preselectedlanguage.md +0 -11
  183. package/docs/api/player.subtitles.reload.md +0 -15
  184. package/docs/api/player.subtitles.render.md +0 -15
  185. package/docs/api/player.subtitles.selectsubtitles.md +0 -15
  186. package/docs/api/player.subtitles.startlevelswitch.md +0 -15
  187. package/docs/api/player.subtitles.stoplevelswitch.md +0 -15
  188. package/docs/api/player.subtitles.supportedversion.md +0 -13
  189. package/docs/api/player.subtitles.template.md +0 -11
  190. package/docs/api/player.subtitles.templatestring.md +0 -11
  191. package/docs/api/player.subtitles.unbindevents.md +0 -15
  192. package/docs/api/player.subtitles.version.md +0 -11
  193. package/docs/api/player.volumefade.bindevents.md +0 -18
  194. package/docs/api/player.volumefade.unbindevents.md +0 -18
  195. package/src/plugins/statistics/Statistics.ts +0 -207
  196. /package/src/plugins/{statistics → telemetry}/Statistics copy.xts +0 -0
@@ -1,14 +1,11 @@
1
1
  import {
2
- Container,
3
2
  Events,
4
- Playback,
5
3
  UICorePlugin,
6
4
  Browser,
7
5
  template,
8
6
  $,
9
7
  } from '@clappr/core'
10
- import { type TimeValue } from '../../playback.types.js'
11
- import { reportError } from '@gcorevideo/utils'
8
+ import { reportError, trace } from '@gcorevideo/utils'
12
9
  import assert from 'assert'
13
10
 
14
11
  import { CLAPPR_VERSION } from '../../build.js'
@@ -22,56 +19,88 @@ import stringHTML from '../../../assets/subtitles/string.ejs'
22
19
  import { isFullscreen } from '../utils.js'
23
20
  import type { ZeptoResult } from '../../utils/types.js'
24
21
 
25
- const VERSION: string = '0.0.1'
22
+ const VERSION: string = '2.19.14'
26
23
 
27
- const LOCAL_STORAGE_SUBTITLES_ID = 'subtitles_select'
24
+ const LOCAL_STORAGE_SUBTITLES_ID =
25
+ 'gplayer.plugins.subtitles.selected'
28
26
 
29
- const T = 'plugins.media_control_subtitles'
27
+ const T = 'plugins.subtitles'
30
28
 
31
29
  type TextTrackInfo = {
32
30
  language: string
33
31
  mode?: 'showing' | 'hidden' | 'disabled'
34
32
  }
35
33
 
36
- type TimelyPlayback = Playback & {
37
- getCurrentTime(): TimeValue
38
- }
39
-
40
34
  const NO_TRACK = { language: 'off' }
41
35
 
36
+ /**
37
+ * A {@link MediaControl | media control} plugin that provides a UI to select the subtitles when available.
38
+ * @beta
39
+ *
40
+ * @remarks
41
+ * Depends on:
42
+ *
43
+ * - {@link MediaControl}
44
+ *
45
+ * Configuration options:
46
+ *
47
+ * - subtitles.language - The language of the subtitles to select by default.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { Subtitles } from '@gcorevideo/player'
52
+ *
53
+ * Player.registerPlugin(Subtitles)
54
+ *
55
+ * new Player({
56
+ * ...
57
+ * subtitles: {
58
+ * language: 'en',
59
+ * },
60
+ * })
61
+ * ```
62
+ */
42
63
  export class Subtitles extends UICorePlugin {
43
- private currentContainer: Container | undefined
64
+ private currentLevel: TextTrackInfo | null = null
44
65
 
45
- private currentLevel: TextTrackInfo | undefined
46
-
47
- private currentPlayback: TimelyPlayback | undefined
66
+ private isPreselectedApplied = false
48
67
 
49
68
  private isShowing = false
50
69
 
51
- private tracks: TextTrackList | undefined
70
+ private track: TextTrackInfo = { ...NO_TRACK }
71
+
72
+ private tracks: TextTrackList | null = null
52
73
 
53
- private $string: ZeptoResult | undefined
74
+ private $string: ZeptoResult | null = null
54
75
 
76
+ /**
77
+ * @internal
78
+ */
55
79
  get name() {
56
- return 'media_control_subtitles'
80
+ return 'subtitles'
57
81
  }
58
82
 
83
+ /**
84
+ * @internal
85
+ */
59
86
  get supportedVersion() {
60
87
  return { min: CLAPPR_VERSION }
61
88
  }
62
89
 
90
+ /**
91
+ * @internal
92
+ */
63
93
  static get version() {
64
94
  return VERSION
65
95
  }
66
96
 
67
- get template() {
68
- return template(comboboxHTML)
69
- }
97
+ private static readonly template = template(comboboxHTML)
70
98
 
71
- get templateString() {
72
- return template(stringHTML)
73
- }
99
+ private static readonly templateString = template(stringHTML)
74
100
 
101
+ /**
102
+ * @internal
103
+ */
75
104
  override get attributes() {
76
105
  return {
77
106
  class: this.name,
@@ -79,6 +108,9 @@ export class Subtitles extends UICorePlugin {
79
108
  }
80
109
  }
81
110
 
111
+ /**
112
+ * @internal
113
+ */
82
114
  override get events() {
83
115
  return {
84
116
  'click [data-subtitles-select]': 'onLevelSelect',
@@ -86,95 +118,49 @@ export class Subtitles extends UICorePlugin {
86
118
  }
87
119
  }
88
120
 
89
- private isPreselectedApplied = false
90
-
91
- private track: TextTrackInfo = { ...NO_TRACK }
92
-
93
- get preselectedLanguage(): string {
121
+ private get preselectedLanguage(): string {
94
122
  return this.core.options.subtitles?.language ?? 'off'
95
123
  }
96
124
 
125
+ /**
126
+ * @internal
127
+ */
97
128
  override bindEvents() {
129
+ const mediaControl = this.core.getPlugin('media_control')
130
+ assert(mediaControl, 'media_control plugin is required')
98
131
  this.listenTo(this.core, Events.CORE_RESIZE, this.playerResize)
99
- this.listenToOnce(this.core, Events.CORE_READY, this.bindPlaybackEvents)
100
- this.listenTo(
101
- this.core.mediaControl,
102
- Events.MEDIACONTROL_CONTAINERCHANGED,
103
- this.reload,
104
- )
105
132
  this.listenTo(
106
- this.core.mediaControl,
107
- Events.MEDIACONTROL_RENDERED,
108
- this.render,
133
+ this.core,
134
+ Events.CORE_ACTIVE_CONTAINER_CHANGED,
135
+ this.bindPlaybackEvents,
109
136
  )
137
+ this.listenTo(mediaControl, Events.MEDIACONTROL_RENDERED, this.render)
110
138
  this.listenTo(
111
- this.core.mediaControl,
139
+ mediaControl,
112
140
  Events.MEDIACONTROL_HIDE,
113
141
  this.hideSelectLevelMenu,
114
142
  )
115
143
  }
116
144
 
117
- unBindEvents() {
118
- // @ts-ignore
119
- this.stopListening(this.core, Events.CORE_READY)
120
- // @ts-ignore
121
- this.stopListening(
122
- this.core.mediaControl,
123
- Events.MEDIACONTROL_CONTAINERCHANGED,
124
- )
125
- // @ts-ignore
126
- this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_RENDERED)
127
- // @ts-ignore
128
- this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_HIDE)
129
- // @ts-ignore
130
- this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_SHOW)
131
- if (this.currentContainer) {
132
- // @ts-ignore
133
- this.stopListening(this.currentContainer, Events.CONTAINER_FULLSCREEN)
134
- // @ts-ignore
135
- this.stopListening(
136
- this.currentContainer,
137
- 'container:advertisement:start',
138
- this.onStartAd,
139
- )
140
- // @ts-ignore
141
- this.stopListening(
142
- this.currentContainer,
143
- 'container:advertisement:finish',
144
- this.onFinishAd,
145
- )
146
- }
147
- }
148
-
149
145
  private bindPlaybackEvents() {
150
- if (
151
- this.currentPlayback &&
152
- this.currentPlayback === this.core.activePlayback
153
- ) {
154
- return
155
- }
156
-
157
- this.currentPlayback = this.core.activePlayback
158
- this.currentContainer = this.core.activeContainer
159
-
160
146
  this.listenTo(
161
- this.currentContainer,
147
+ this.core.activeContainer,
162
148
  Events.CONTAINER_FULLSCREEN,
163
149
  this.playerResize,
164
150
  )
165
151
  this.listenToOnce(
166
- this.currentPlayback,
152
+ this.core.activePlayback,
167
153
  Events.PLAYBACK_PLAY,
168
154
  this.getTracks,
169
155
  )
170
156
  this.listenTo(
171
- this.currentContainer,
157
+ this.core.activeContainer,
172
158
  'container:advertisement:start',
173
159
  this.onStartAd,
174
160
  )
175
161
 
176
162
  // fix for iOS
177
- const video = this.currentPlayback?.el
163
+ const video = this.core.activePlayback.el
178
164
  assert(video, 'video element is required')
179
165
 
180
166
  video.addEventListener('webkitbeginfullscreen', () => {
@@ -191,11 +177,13 @@ export class Subtitles extends UICorePlugin {
191
177
  }
192
178
 
193
179
  private getTracks() {
194
- if (this.currentPlayback) {
180
+ if (this.core.activePlayback) {
195
181
  try {
196
- const tracks = (this.currentPlayback.el as HTMLMediaElement).textTracks
197
-
198
- tracks.length > 0 && this.fillLevels(tracks)
182
+ const tracks = (this.core.activePlayback.el as HTMLMediaElement)
183
+ .textTracks
184
+ if (tracks.length > 0) {
185
+ this.setTracks(tracks)
186
+ }
199
187
  } catch (error) {
200
188
  reportError(error)
201
189
  }
@@ -203,10 +191,10 @@ export class Subtitles extends UICorePlugin {
203
191
  }
204
192
 
205
193
  private onStartAd() {
206
- if (this.isShowing && this.currentContainer) {
194
+ if (this.isShowing && this.core.activeContainer) {
207
195
  this.hide()
208
196
  this.listenTo(
209
- this.currentContainer,
197
+ this.core.activeContainer,
210
198
  'container:advertisement:finish',
211
199
  this.onFinishAd,
212
200
  )
@@ -216,22 +204,16 @@ export class Subtitles extends UICorePlugin {
216
204
  private onFinishAd() {
217
205
  this.show()
218
206
  this.stopListening(
219
- this.currentContainer,
207
+ this.core.activeContainer,
220
208
  'container:advertisement:finish',
221
209
  this.onFinishAd,
222
210
  )
223
211
  }
224
212
 
225
- reload() {
226
- this.unBindEvents()
227
- this.bindEvents()
228
- this.bindPlaybackEvents()
229
- }
230
-
231
213
  private playerResize() {
232
214
  const shouldShow =
233
- this.currentContainer &&
234
- isFullscreen(this.currentContainer.el) &&
215
+ this.core.activeContainer &&
216
+ isFullscreen(this.core.activeContainer.el) &&
235
217
  this.currentLevel &&
236
218
  this.currentLevel.mode &&
237
219
  Browser.isiOS &&
@@ -248,6 +230,9 @@ export class Subtitles extends UICorePlugin {
248
230
  }
249
231
  }
250
232
 
233
+ /**
234
+ * Hides the subtitles menu and the subtitles.
235
+ */
251
236
  hide() {
252
237
  this.isShowing = false
253
238
  this.renderIcon()
@@ -259,12 +244,15 @@ export class Subtitles extends UICorePlugin {
259
244
  }
260
245
  }
261
246
 
247
+ /**
248
+ * Shows the subtitles menu and the subtitles.
249
+ */
262
250
  show() {
263
251
  this.isShowing = true
264
252
  this.renderIcon()
265
253
  if (
266
- this.currentContainer &&
267
- isFullscreen(this.currentContainer.el) &&
254
+ this.core.activeContainer &&
255
+ isFullscreen(this.core.activeContainer.el) &&
268
256
  this.currentLevel &&
269
257
  this.currentLevel.mode &&
270
258
  Browser.isiOS
@@ -277,22 +265,11 @@ export class Subtitles extends UICorePlugin {
277
265
  }
278
266
 
279
267
  private shouldRender() {
280
- if (!this.currentContainer) {
281
- return false
282
- }
283
-
284
- if (!this.currentPlayback) {
285
- return false
286
- }
287
-
288
- // Only care if we have at least 2 to choose from
289
- const hasLevels = !!(this.tracks && this.tracks.length > 0)
290
-
291
- return hasLevels
268
+ return !!(this.tracks && this.tracks.length > 0)
292
269
  }
293
270
 
294
271
  private resizeFont() {
295
- if (!this.currentContainer) {
272
+ if (!this.core.activeContainer) {
296
273
  return
297
274
  }
298
275
 
@@ -300,53 +277,64 @@ export class Subtitles extends UICorePlugin {
300
277
  return
301
278
  }
302
279
 
303
- const skinWidth = this.currentContainer.$el.width()
280
+ const skinWidth = this.core.activeContainer.$el.width()
304
281
 
305
282
  this.$string.find('p').css('font-size', skinWidth * 0.03)
306
283
  }
307
284
 
285
+ /**
286
+ * @internal
287
+ */
308
288
  override render() {
309
- if (this.shouldRender()) {
310
- this.$el.html(this.template({ tracks: this.tracks }))
311
- this.currentContainer?.$el.find('.subtitle-string').remove()
312
- this.$string = $(this.templateString())
313
- this.resizeFont()
289
+ if (!this.core.activeContainer) {
290
+ return this
291
+ }
314
292
 
315
- this.currentContainer?.$el.append(this.$string[0])
316
- if (
317
- this.core.mediaControl.$subtitlesSelector &&
318
- this.core.mediaControl.$subtitlesSelector.length > 0
319
- ) {
320
- this.core.mediaControl.$subtitlesSelector.append(this.el)
321
- } else {
322
- this.core.mediaControl.$('.media-control-right-panel').append(this.el)
323
- }
293
+ if (!this.shouldRender()) {
294
+ return this
295
+ }
324
296
 
325
- this.updateCurrentLevel(this.track)
326
- this.highlightCurrentSubtitles()
297
+ trace(`${T} render`, {
298
+ tracks: this.tracks?.length,
299
+ track: this.track?.language,
300
+ })
327
301
 
328
- this.applyPreselectedSubtitles()
329
- }
330
- if (
331
- this.core.mediaControl.$subtitlesSelector?.find('span.subtitle-text')
332
- .length > 0
333
- ) {
334
- this.renderIcon()
302
+ const mediaControl = this.core.getPlugin('media_control')
303
+ assert(mediaControl, 'media_control plugin is required')
304
+
305
+ this.$el.html(Subtitles.template({ tracks: this.tracks }))
306
+ this.core.activeContainer.$el.find('.subtitle-string').remove()
307
+ this.$string = $(Subtitles.templateString())
308
+ this.resizeFont()
309
+
310
+ this.core.activeContainer.$el.append(this.$string[0])
311
+ const ss = mediaControl.getElement('subtitlesSelector')
312
+ if (ss && ss.length > 0) {
313
+ ss.append(this.el)
314
+ } else {
315
+ mediaControl.getRightPanel().append(this.el)
335
316
  }
336
317
 
318
+ this.updateCurrentLevel(this.track)
319
+ this.highlightCurrentSubtitles()
320
+
321
+ this.applyPreselectedSubtitles()
322
+
323
+ this.renderIcon()
324
+
337
325
  return this
338
326
  }
339
327
 
340
- private fillLevels(tracks: TextTrackList) {
328
+ private setTracks(tracks: TextTrackList) {
341
329
  this.tracks = tracks
342
330
  this.render()
343
331
  }
344
332
 
345
333
  private findLevelBy(id: string) {
346
334
  if (this.tracks) {
347
- for (let i = 0; i < this.tracks.length; i++) {
348
- if (this.tracks[i].language === id) {
349
- return this.tracks[i] // TODO TrackInfo?
335
+ for (const track of this.tracks) {
336
+ if (track.language === id) {
337
+ return track // TODO TrackInfo?
350
338
  }
351
339
  }
352
340
  }
@@ -385,38 +373,39 @@ export class Subtitles extends UICorePlugin {
385
373
  }
386
374
 
387
375
  private onShowLevelSelectMenu() {
376
+ trace(`${T} onShowLevelSelectMenu`)
388
377
  this.toggleContextMenu()
389
378
  }
390
379
 
391
380
  private hideSelectLevelMenu() {
392
- ;(this.$('.subtitles ul') as ZeptoResult).hide()
381
+ ;(this.$('[data-subtitles] ul') as ZeptoResult).hide()
393
382
  }
394
383
 
395
384
  private toggleContextMenu() {
396
- ;(this.$('.subtitles ul') as ZeptoResult).toggle()
385
+ (this.$('[data-subtitles] ul') as ZeptoResult).toggle()
397
386
  }
398
387
 
399
- buttonElement(): ZeptoResult {
400
- return this.$('.subtitles button')
388
+ private buttonElement(): ZeptoResult {
389
+ return this.$('[data-subtitles] button')
401
390
  }
402
391
 
403
- levelElement(id?: string): ZeptoResult {
392
+ private levelElement(id?: string): ZeptoResult {
404
393
  return (
405
394
  this.$(
406
- '.subtitles ul a' + (id ? '[data-subtitles-select="' + id + '"]' : ''),
395
+ '[data-subtitles] ul a' + (id ? '[data-subtitles-select="' + id + '"]' : ''),
407
396
  ) as ZeptoResult
408
397
  ).parent()
409
398
  }
410
399
 
411
- startLevelSwitch() {
400
+ private startLevelSwitch() {
412
401
  this.buttonElement().addClass('changing')
413
402
  }
414
403
 
415
- stopLevelSwitch() {
404
+ private stopLevelSwitch() {
416
405
  this.buttonElement().removeClass('changing')
417
406
  }
418
407
 
419
- selectSubtitles() {
408
+ private selectSubtitles() {
420
409
  if (!this.currentLevel) {
421
410
  return
422
411
  }
@@ -427,7 +416,7 @@ export class Subtitles extends UICorePlugin {
427
416
  if (track.language === this.currentLevel.language) {
428
417
  track.mode = 'showing'
429
418
 
430
- const currentTime = this.currentPlayback?.getCurrentTime() ?? 0
419
+ const currentTime = this.core.activePlayback?.getCurrentTime() ?? 0
431
420
  const cues = track.cues
432
421
  let subtitleText = ''
433
422
 
@@ -498,8 +487,10 @@ export class Subtitles extends UICorePlugin {
498
487
  private renderIcon() {
499
488
  const icon = this.isShowing ? subtitlesOnIcon : subtitlesOffIcon
500
489
 
501
- this.core.mediaControl.$subtitlesSelector
502
- .find('span.subtitle-text')
490
+ this.core
491
+ .getPlugin('media_control')
492
+ .getElement('subtitlesSelector')
493
+ ?.find('span.subtitle-text')
503
494
  .html(icon)
504
495
  }
505
496
  }