@gcorevideo/player 2.28.18 → 2.28.20

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ClosedCaptions.d.ts","sourceRoot":"","sources":["../../../src/plugins/subtitles/ClosedCaptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAwB,MAAM,cAAc,CAAA;AAOzE,OAAO,sCAAsC,CAAA;AAgB7C;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,oBAAoB,CAAQ;IAEpC,OAAO,CAAC,MAAM,CAAQ;IAEtB,OAAO,CAAC,IAAI,CAAQ;IAEpB,OAAO,CAAC,KAAK,CAA6B;IAE1C,OAAO,CAAC,MAAM,CAAsB;IAEpC,OAAO,CAAC,KAAK,CAA2B;IAExC;;OAEG;IACH,IAAI,IAAI,WAEP;IAED;;OAEG;IACH,IAAI,gBAAgB;;MAEnB;IAED;;OAEG;IACH,MAAM,KAAK,OAAO,WAEjB;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAyB;IAEhE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAuB;IAE3D;;OAEG;IACH,IAAa,UAAU;;MAItB;IAED;;OAEG;IACH,IAAa,MAAM;;;MAKlB;IAED,OAAO,KAAK,mBAAmB,GAM9B;IAED;;OAEG;IACM,UAAU;IASnB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,kBAAkB;IAgD1B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,iBAAiB;IA+BzB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,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,gBAAgB;;MAEnB;IAED;;OAEG;IACH,MAAM,KAAK,OAAO,WAEjB;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAyB;IAEhE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAuB;IAE3D;;OAEG;IACH,IAAa,UAAU;;MAItB;IAED;;OAEG;IACH,IAAa,MAAM;;;MAKlB;IAED,OAAO,KAAK,mBAAmB,GAK9B;IAED;;OAEG;IACM,UAAU;IASnB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,kBAAkB;IAgD1B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,iBAAiB;IAkCzB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;IACH,IAAI;IAcJ;;OAEG;IACH,IAAI;IAiBJ,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAUlB;;OAEG;IACM,MAAM;IA4Bf,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,yBAAyB;IAejC,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,yBAAyB;IAiBjC,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,KAAK;CAMd"}
@@ -93,8 +93,7 @@ export class ClosedCaptions extends UICorePlugin {
93
93
  }
94
94
  get preselectedLanguage() {
95
95
  return (this.core.options.cc?.language ??
96
- this.core.options.subtitles?.language ??
97
- '');
96
+ this.core.options.subtitles?.language);
98
97
  }
99
98
  /**
100
99
  * @internal
@@ -147,14 +146,17 @@ export class ClosedCaptions extends UICorePlugin {
147
146
  this.applyTracks();
148
147
  this.mount();
149
148
  }
150
- onSubtitleChanged({ id }) {
151
- trace(`${T} onSubtitleChanged`, { id });
149
+ onSubtitleChanged({ id: _ }) {
150
+ // ignoring the subtitle selected by the playback engine or user agent
151
+ const id = this.track?.id ?? -1;
152
152
  if (id === -1) {
153
153
  this.clearSubtitleText();
154
154
  }
155
155
  for (const track of this.tracks) {
156
+ // Native subtitles are always hidden
157
+ track.track.mode = 'hidden';
156
158
  if (track.id === id) {
157
- track.track.mode = 'showing';
159
+ // track.track.mode = 'showing'
158
160
  this.setSubtitleText(this.getSubtitleText(track.track));
159
161
  track.track.oncuechange = (e) => {
160
162
  try {
@@ -173,7 +175,7 @@ export class ClosedCaptions extends UICorePlugin {
173
175
  }
174
176
  else {
175
177
  track.track.oncuechange = null;
176
- track.track.mode = 'hidden';
178
+ // track.track.mode = 'hidden'
177
179
  }
178
180
  }
179
181
  }
@@ -302,12 +304,11 @@ export class ClosedCaptions extends UICorePlugin {
302
304
  applyPreselectedSubtitles() {
303
305
  if (!this.isPreselectedApplied) {
304
306
  this.isPreselectedApplied = true;
305
- if (!this.preselectedLanguage) {
306
- return;
307
- }
307
+ // if the language is undefined, then let the engine decide
308
+ // to hide the subtitles forcefully, set the language to 'none'
308
309
  setTimeout(() => {
309
310
  this.selectItem(this.tracks.find((t) => t.track.language === this.preselectedLanguage) ?? null);
310
- }, 300); // TODO why delay?
311
+ }, 0);
311
312
  }
312
313
  }
313
314
  hideMenu() {
@@ -337,7 +338,9 @@ export class ClosedCaptions extends UICorePlugin {
337
338
  }
338
339
  selectSubtitles() {
339
340
  const trackId = this.track ? this.track.id : -1;
340
- this.core.activePlayback.closedCaptionsTrackId = trackId; // TODO test
341
+ // TODO find out if this is needed
342
+ // this.core.activePlayback.closedCaptionsTrackId = trackId
343
+ this.core.activePlayback.closedCaptionsTrackId = -1;
341
344
  }
342
345
  getSubtitleText(track) {
343
346
  const currentTime = this.core.activePlayback?.getCurrentTime() ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gcorevideo/player",
3
- "version": "2.28.18",
3
+ "version": "2.28.20",
4
4
  "description": "Gcore JavaScript video player",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -217,6 +217,7 @@ export class QualityLevels extends UICorePlugin {
217
217
  */
218
218
  override render() {
219
219
  if (!this.shouldRender()) {
220
+ this.$el.hide()
220
221
  return this
221
222
  }
222
223
  this.renderDropdown()
@@ -241,6 +242,9 @@ export class QualityLevels extends UICorePlugin {
241
242
  }
242
243
 
243
244
  private updateButton() {
245
+ if (!this.shouldRender()) {
246
+ return
247
+ }
244
248
  ;(this.core.getPlugin('bottom_gear') as BottomGear)
245
249
  ?.addItem('quality', this.$el)
246
250
  .html(
@@ -471,9 +471,7 @@ export class MediaControl extends UICorePlugin {
471
471
  this.listenTo(
472
472
  this.core.activeContainer,
473
473
  Events.CONTAINER_CLICK,
474
- () => {
475
- this.clickaway(this.core.activeContainer.$el[0])
476
- },
474
+ () => this.clickaway(this.core.activeContainer.$el[0]),
477
475
  )
478
476
  this.listenTo(
479
477
  this.core.activeContainer,
@@ -951,9 +949,6 @@ export class MediaControl extends UICorePlugin {
951
949
  } else {
952
950
  this.hideVolumeId = setTimeout(() => {
953
951
  this.hideVolumeId = null
954
- trace(`${T} hideVolumeBar`, {
955
- volumeBarContainer: !!this.$volumeBarContainer,
956
- })
957
952
  this.$volumeBarContainer?.addClass('volume-bar-hide')
958
953
  }, timeout)
959
954
  }
@@ -1045,17 +1040,12 @@ export class MediaControl extends UICorePlugin {
1045
1040
  this.setSeekPercentage(pos)
1046
1041
  }
1047
1042
 
1048
- private setUserKeepVisible() {
1049
- trace(`${T} setUserKeepVisible`, {
1050
- userKeepVisible: this.userKeepVisible,
1051
- })
1043
+ private setUserKeepVisible(e?: MouseEvent) {
1052
1044
  this.userKeepVisible = true
1045
+ this.clickaway(this.core.activeContainer.$el[0])
1053
1046
  }
1054
1047
 
1055
- private resetUserKeepVisible = () => {
1056
- trace(`${T} resetUserKeepVisible`, {
1057
- userKeepVisible: this.userKeepVisible,
1058
- })
1048
+ private resetUserKeepVisible = (e?: MouseEvent) => {
1059
1049
  this.userKeepVisible = false
1060
1050
  }
1061
1051
 
@@ -1064,11 +1054,6 @@ export class MediaControl extends UICorePlugin {
1064
1054
  }
1065
1055
 
1066
1056
  private show(event?: MouseEvent) {
1067
- trace(`${T} show`, {
1068
- disabled: this.disabled,
1069
- disableControlPanel: this.options.disableControlPanel,
1070
- event,
1071
- })
1072
1057
  if (this.disabled || this.options.disableControlPanel) {
1073
1058
  return
1074
1059
  }
@@ -1103,17 +1088,6 @@ export class MediaControl extends UICorePlugin {
1103
1088
  }
1104
1089
 
1105
1090
  private hide(delay = 0) {
1106
- trace(`${T} hide`, {
1107
- delay,
1108
- visible: this.isVisible(),
1109
- disabled: this.disabled,
1110
- hideMediaControl: this.options.hideMediaControl,
1111
- userKeepVisible: this.userKeepVisible,
1112
- keepVisible: this.keepVisible,
1113
- draggingSeekBar: this.draggingSeekBar,
1114
- draggingVolumeBar: this.draggingVolumeBar,
1115
- })
1116
-
1117
1091
  if (!this.isVisible()) {
1118
1092
  return
1119
1093
  }
@@ -1650,14 +1624,17 @@ export class MediaControl extends UICorePlugin {
1650
1624
  }
1651
1625
  }
1652
1626
 
1653
- private delayHide(e: unknown) {
1654
- trace(`${T} delayHide`, {
1655
- e,
1656
- })
1627
+ private delayHide() {
1657
1628
  this.hide(this.options.hideMediaControlDelay || DEFAULT_HIDE_DELAY)
1658
1629
  }
1659
1630
 
1660
- private clickaway = clickaway(this.resetUserKeepVisible)
1631
+ // 2 seconds delay is needed since on mobile devices mouse(touch)move events are not dispatched immediately
1632
+ // as opposed to the click event
1633
+ private clickaway = clickaway(() => {
1634
+ if (Browser.isMobile) {
1635
+ setTimeout(this.resetUserKeepVisible, 0)
1636
+ }
1637
+ })
1661
1638
  }
1662
1639
 
1663
1640
  MediaControl.extend = function (properties) {
@@ -1721,13 +1698,9 @@ function clickaway(callback: () => void) {
1721
1698
  return
1722
1699
  }
1723
1700
  handler = (event: MouseEvent | TouchEvent) => {
1724
- trace(`${T} clickaway`, {
1725
- node,
1726
- event,
1727
- })
1728
1701
  if (!node.contains(event.target as Node)) {
1729
- callback()
1730
1702
  window.removeEventListener('click', handler)
1703
+ callback()
1731
1704
  }
1732
1705
  }
1733
1706
  window.addEventListener('click', handler)
@@ -124,11 +124,10 @@ export class ClosedCaptions extends UICorePlugin {
124
124
  }
125
125
  }
126
126
 
127
- private get preselectedLanguage(): string {
127
+ private get preselectedLanguage(): string | undefined {
128
128
  return (
129
129
  this.core.options.cc?.language ??
130
- this.core.options.subtitles?.language ??
131
- ''
130
+ this.core.options.subtitles?.language
132
131
  )
133
132
  }
134
133
 
@@ -218,14 +217,17 @@ export class ClosedCaptions extends UICorePlugin {
218
217
  this.mount()
219
218
  }
220
219
 
221
- private onSubtitleChanged({ id }: { id: number }) {
222
- trace(`${T} onSubtitleChanged`, { id })
220
+ private onSubtitleChanged({ id: _ }: { id: number }) {
221
+ // ignoring the subtitle selected by the playback engine or user agent
222
+ const id = this.track?.id ?? -1
223
223
  if (id === -1) {
224
224
  this.clearSubtitleText()
225
225
  }
226
226
  for (const track of this.tracks) {
227
+ // Native subtitles are always hidden
228
+ track.track.mode = 'hidden'
227
229
  if (track.id === id) {
228
- track.track.mode = 'showing'
230
+ // track.track.mode = 'showing'
229
231
 
230
232
  this.setSubtitleText(this.getSubtitleText(track.track))
231
233
 
@@ -244,7 +246,7 @@ export class ClosedCaptions extends UICorePlugin {
244
246
  }
245
247
  } else {
246
248
  track.track.oncuechange = null
247
- track.track.mode = 'hidden'
249
+ // track.track.mode = 'hidden'
248
250
  }
249
251
  }
250
252
  }
@@ -408,16 +410,15 @@ export class ClosedCaptions extends UICorePlugin {
408
410
  private applyPreselectedSubtitles() {
409
411
  if (!this.isPreselectedApplied) {
410
412
  this.isPreselectedApplied = true
411
- if (!this.preselectedLanguage) {
412
- return
413
- }
413
+ // if the language is undefined, then let the engine decide
414
+ // to hide the subtitles forcefully, set the language to 'none'
414
415
  setTimeout(() => {
415
416
  this.selectItem(
416
417
  this.tracks.find(
417
418
  (t) => t.track.language === this.preselectedLanguage,
418
419
  ) ?? null,
419
420
  )
420
- }, 300) // TODO why delay?
421
+ }, 0)
421
422
  }
422
423
  }
423
424
 
@@ -452,7 +453,9 @@ export class ClosedCaptions extends UICorePlugin {
452
453
  private selectSubtitles() {
453
454
  const trackId = this.track ? this.track.id : -1
454
455
 
455
- this.core.activePlayback.closedCaptionsTrackId = trackId // TODO test
456
+ // TODO find out if this is needed
457
+ // this.core.activePlayback.closedCaptionsTrackId = trackId
458
+ this.core.activePlayback.closedCaptionsTrackId = -1
456
459
  }
457
460
 
458
461
  private getSubtitleText(track: TextTrack) {
@@ -132,6 +132,7 @@ describe('ClosedCaptions', () => {
132
132
  describe('when subtitle is changed', () => {
133
133
  beforeEach(async () => {
134
134
  emitSubtitleAvailable(core)
135
+ cc.$el.find('#gplayer-cc-button').click()
135
136
  await new Promise((resolve) => setTimeout(resolve, 100))
136
137
  core.activePlayback.getCurrentTime = vi.fn().mockReturnValue(7)
137
138
  core.activeContainer.getCurrentTime = vi.fn().mockReturnValue(7)
@@ -167,11 +168,16 @@ describe('ClosedCaptions', () => {
167
168
  ),
168
169
  },
169
170
  ]
171
+ cc.$el.find('#gplayer-cc-menu li:nth-child(2) a').click()
172
+ await new Promise((resolve) => setTimeout(resolve, 100))
173
+ // TODO test explicitly that PLAYBACK_SUBTITLE_CHANGED event does not cause track switch
170
174
  core.activePlayback.emit(Events.PLAYBACK_SUBTITLE_CHANGED, { id: 2 })
175
+ await new Promise((resolve) => setTimeout(resolve, 100))
176
+
171
177
  })
172
178
  it('should activate subtitle track', () => {
173
179
  expect(core.activePlayback.closedCaptionsTracks[1].track.mode).toBe(
174
- 'showing',
180
+ 'hidden',
175
181
  )
176
182
  expect(core.activePlayback.closedCaptionsTracks[0].track.mode).toBe(
177
183
  'hidden',
@@ -188,8 +194,8 @@ describe('ClosedCaptions', () => {
188
194
  emitSubtitleAvailable(core)
189
195
  cc.$el.find('#gplayer-cc-menu li:nth-child(2) a').click()
190
196
  })
191
- it('should activate subtitle track', () => {
192
- expect(core.activePlayback.closedCaptionsTrackId).toEqual(2)
197
+ it('should deactivate native subtitles track', () => {
198
+ expect(core.activePlayback.closedCaptionsTrackId).toEqual(-1)
193
199
  })
194
200
  it('should highlight selected menu item', () => {
195
201
  expect(