@gcorevideo/player 2.26.9 → 2.28.0

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.
package/src/Player.ts CHANGED
@@ -17,6 +17,7 @@ import type {
17
17
  } from './internal.types.js'
18
18
  import type {
19
19
  ContainerSize,
20
+ PlayerMediaSource,
20
21
  PlayerMediaSourceDesc,
21
22
  PlayerPluginConstructor,
22
23
  } from './types.js'
@@ -24,6 +25,7 @@ import { PlayerConfig, PlayerEvent } from './types.js'
24
25
  import { buildMediaSourcesList, wrapSource } from './utils/mediaSources.js'
25
26
  import { registerPlaybacks } from './playback/index.js'
26
27
  import { PlaybackError, TimePosition } from './playback.types.js'
28
+ import { SourceController } from './plugins/source-controller/SourceController.js'
27
29
 
28
30
  /**
29
31
  * @public
@@ -246,6 +248,32 @@ export class Player {
246
248
  return this.player?.isPlaying() ?? false
247
249
  }
248
250
 
251
+ /**
252
+ * Loads new media source
253
+ * @param mediaSources - list of media sources to use
254
+ * @beta
255
+ */
256
+ load(mediaSources: PlayerMediaSource[]) {
257
+ if (mediaSources.length === 0) {
258
+ throw new Error('No media sources provided')
259
+ }
260
+ const ms = mediaSources.map((s) => wrapSource(s))
261
+ const sourceController = this.player?.core.activePlayback.getPlugin(
262
+ 'source_controller',
263
+ ) as SourceController
264
+ if (sourceController) {
265
+ sourceController.setMediaSource(ms)
266
+ return
267
+ }
268
+ if (this.player) {
269
+ this.player.load(ms, ms[0].mimeType ?? '')
270
+ return
271
+ }
272
+ this.configure({
273
+ sources: mediaSources,
274
+ })
275
+ }
276
+
249
277
  /**
250
278
  * Mutes the sound of the video.
251
279
  */
@@ -367,7 +395,9 @@ export class Player {
367
395
  * @param name - name of the plugin
368
396
  */
369
397
  static unregisterPlugin(name: string) {
370
- Player.corePlugins = Player.corePlugins.filter((p) => p.prototype.name !== name)
398
+ Player.corePlugins = Player.corePlugins.filter(
399
+ (p) => p.prototype.name !== name,
400
+ )
371
401
  Loader.unregisterPlugin(name)
372
402
  }
373
403
 
@@ -48,6 +48,7 @@ export default class HTML5Video extends BasePlayback {
48
48
  }
49
49
 
50
50
  override _handleBufferingEvents() {
51
+ // TODO use the logic from the base class to detect if it's stalled or resumed, because in the latter case the current behavior is not correct
51
52
  if (!this.stallTimerId) {
52
53
  this.stallTimerId = setTimeout(() => {
53
54
  this.stallTimerId = null
@@ -92,16 +92,17 @@ export class CmcdConfig extends CorePlugin {
92
92
  constructor(core: Core) {
93
93
  super(core)
94
94
  this.sid = this.options.cmcd?.sessionId ?? generateSessionId()
95
- this.cid = this.options.cmcd?.contentId ?? this.generateContentId()
95
+ this.setContentId()
96
96
  }
97
97
 
98
98
  /**
99
99
  * @internal
100
100
  */
101
101
  override bindEvents() {
102
- this.listenTo(this.core, Events.CORE_CONTAINERS_CREATED, () =>
103
- this.updateSettings(this.core.containers[0]),
104
- )
102
+ this.listenTo(this.core, Events.CORE_CONTAINERS_CREATED, () => {
103
+ this.setContentId()
104
+ this.updateSettings(this.core.containers[0])
105
+ })
105
106
  }
106
107
 
107
108
  /**
@@ -128,7 +129,7 @@ export class CmcdConfig extends CorePlugin {
128
129
  sid: this.sid,
129
130
  cid: this.cid,
130
131
  },
131
- }
132
+ },
132
133
  },
133
134
  })
134
135
  break
@@ -153,4 +154,8 @@ export class CmcdConfig extends CorePlugin {
153
154
  this.core.options.source ?? this.core.options.sources[0].source,
154
155
  ).pathname.slice(0, 64)
155
156
  }
157
+
158
+ private setContentId() {
159
+ this.cid = this.options.cmcd?.contentId ?? this.generateContentId()
160
+ }
156
161
  }
@@ -69,9 +69,6 @@ function noSync(cb: () => void) {
69
69
  *
70
70
  * ```
71
71
  *
72
- * This plugin does not expose any public methods apart from required by the Clappr plugin interface.
73
- * It is supposed to work autonomously.
74
- *
75
72
  * @example
76
73
  * ```ts
77
74
  * import { SourceController } from '@gcorevideo/player'
@@ -156,11 +153,25 @@ export class SourceController extends CorePlugin {
156
153
  if (this.core.options.source !== undefined) {
157
154
  // prevent Clappr from loading all sources simultaneously
158
155
  this.core.options.sources = [this.core.options.source]
156
+ this.core.options.source = undefined // TODO test
159
157
  } else {
160
158
  this.core.options.sources = this.core.options.sources.slice(0, 1)
161
159
  }
162
160
  }
163
161
 
162
+ /**
163
+ * Set new media source.
164
+ *
165
+ * @param sourcesList - The list of new media source URLs
166
+ * @beta
167
+ * @remarks
168
+ * Triggers a reload of the playback module, container and all container plugins.
169
+ */
170
+ setMediaSource(sourcesList: PlayerMediaSourceDesc[]) {
171
+ this.sourcesList = sourcesList
172
+ this.core.load(sourcesList, this.core.options.mimeType)
173
+ }
174
+
164
175
  /**
165
176
  * @internal
166
177
  */
@@ -5587,6 +5587,59 @@
5587
5587
  "isAbstract": false,
5588
5588
  "name": "isPlaying"
5589
5589
  },
5590
+ {
5591
+ "kind": "Method",
5592
+ "canonicalReference": "@gcorevideo/player!Player#load:member(1)",
5593
+ "docComment": "/**\n * Loads new media source\n *\n * @param mediaSources - list of media sources to use\n *\n * @beta\n */\n",
5594
+ "excerptTokens": [
5595
+ {
5596
+ "kind": "Content",
5597
+ "text": "load(mediaSources: "
5598
+ },
5599
+ {
5600
+ "kind": "Reference",
5601
+ "text": "PlayerMediaSource",
5602
+ "canonicalReference": "@gcorevideo/player!PlayerMediaSource:type"
5603
+ },
5604
+ {
5605
+ "kind": "Content",
5606
+ "text": "[]"
5607
+ },
5608
+ {
5609
+ "kind": "Content",
5610
+ "text": "): "
5611
+ },
5612
+ {
5613
+ "kind": "Content",
5614
+ "text": "void"
5615
+ },
5616
+ {
5617
+ "kind": "Content",
5618
+ "text": ";"
5619
+ }
5620
+ ],
5621
+ "isStatic": false,
5622
+ "returnTypeTokenRange": {
5623
+ "startIndex": 4,
5624
+ "endIndex": 5
5625
+ },
5626
+ "releaseTag": "Beta",
5627
+ "isProtected": false,
5628
+ "overloadIndex": 1,
5629
+ "parameters": [
5630
+ {
5631
+ "parameterName": "mediaSources",
5632
+ "parameterTypeTokenRange": {
5633
+ "startIndex": 1,
5634
+ "endIndex": 3
5635
+ },
5636
+ "isOptional": false
5637
+ }
5638
+ ],
5639
+ "isOptional": false,
5640
+ "isAbstract": false,
5641
+ "name": "load"
5642
+ },
5590
5643
  {
5591
5644
  "kind": "Method",
5592
5645
  "canonicalReference": "@gcorevideo/player!Player#mute:member(1)",
@@ -8501,7 +8554,7 @@
8501
8554
  {
8502
8555
  "kind": "Class",
8503
8556
  "canonicalReference": "@gcorevideo/player!SourceController:class",
8504
- "docComment": "/**\n * `PLUGIN` that is managing the automatic failover between media sources.\n *\n * @remarks\n *\n * Have a look at the {@link https://miro.com/app/board/uXjVLiN15tY=/?share_link_id=390327585787 | source failover diagram} for the details on how sources ordering and selection works. Below is a simplified diagram:\n * ```markdown\n * sources_list:\n * - a.mpd | +--------------------+\n * - b.m3u8 |--->| init |\n * - ... | |--------------------|\n * | current_source = 0 |\n * +--------------------+\n * |\n * | source = a.mpd\n * | playback = dash.js\n * v\n * +------------------+\n * +-->| load source |\n * | +---------|--------+\n * | v\n * | +------------------+\n * | | play |\n * | +---------|--------+\n * | |\n * | v\n * | +-----------------------+\n * | | on playback_error |\n * | |-----------------------|\n * | | current_source = |\n * | | (current_source + 1) |\n * | | % len sources_list |\n * | | |\n * | | delay 1..3s |\n * | +---------------|-------+\n * | |\n * | source=b.m3u8 |\n * | playback=hls.js |\n * +-------------------+\n *\n * ```\n *\n * This plugin does not expose any public methods apart from required by the Clappr plugin interface. It is supposed to work autonomously.\n *\n * @example\n * ```ts\n * import { SourceController } from '@gcorevideo/player'\n *\n * Player.registerPlugin(SourceController)\n * ```\n *\n * @public\n */\n",
8557
+ "docComment": "/**\n * `PLUGIN` that is managing the automatic failover between media sources.\n *\n * @remarks\n *\n * Have a look at the {@link https://miro.com/app/board/uXjVLiN15tY=/?share_link_id=390327585787 | source failover diagram} for the details on how sources ordering and selection works. Below is a simplified diagram:\n * ```markdown\n * sources_list:\n * - a.mpd | +--------------------+\n * - b.m3u8 |--->| init |\n * - ... | |--------------------|\n * | current_source = 0 |\n * +--------------------+\n * |\n * | source = a.mpd\n * | playback = dash.js\n * v\n * +------------------+\n * +-->| load source |\n * | +---------|--------+\n * | v\n * | +------------------+\n * | | play |\n * | +---------|--------+\n * | |\n * | v\n * | +-----------------------+\n * | | on playback_error |\n * | |-----------------------|\n * | | current_source = |\n * | | (current_source + 1) |\n * | | % len sources_list |\n * | | |\n * | | delay 1..3s |\n * | +---------------|-------+\n * | |\n * | source=b.m3u8 |\n * | playback=hls.js |\n * +-------------------+\n *\n * ```\n *\n * @example\n * ```ts\n * import { SourceController } from '@gcorevideo/player'\n *\n * Player.registerPlugin(SourceController)\n * ```\n *\n * @public\n */\n",
8505
8558
  "excerptTokens": [
8506
8559
  {
8507
8560
  "kind": "Content",
@@ -8555,6 +8608,59 @@
8555
8608
  "isOptional": false
8556
8609
  }
8557
8610
  ]
8611
+ },
8612
+ {
8613
+ "kind": "Method",
8614
+ "canonicalReference": "@gcorevideo/player!SourceController#setMediaSource:member(1)",
8615
+ "docComment": "/**\n * Set new media source.\n *\n * @remarks\n *\n * Triggers a reload of the playback module, container and all container plugins.\n *\n * @param sourcesList - The list of new media source URLs\n *\n * @beta\n */\n",
8616
+ "excerptTokens": [
8617
+ {
8618
+ "kind": "Content",
8619
+ "text": "setMediaSource(sourcesList: "
8620
+ },
8621
+ {
8622
+ "kind": "Reference",
8623
+ "text": "PlayerMediaSourceDesc",
8624
+ "canonicalReference": "@gcorevideo/player!PlayerMediaSourceDesc:interface"
8625
+ },
8626
+ {
8627
+ "kind": "Content",
8628
+ "text": "[]"
8629
+ },
8630
+ {
8631
+ "kind": "Content",
8632
+ "text": "): "
8633
+ },
8634
+ {
8635
+ "kind": "Content",
8636
+ "text": "void"
8637
+ },
8638
+ {
8639
+ "kind": "Content",
8640
+ "text": ";"
8641
+ }
8642
+ ],
8643
+ "isStatic": false,
8644
+ "returnTypeTokenRange": {
8645
+ "startIndex": 4,
8646
+ "endIndex": 5
8647
+ },
8648
+ "releaseTag": "Beta",
8649
+ "isProtected": false,
8650
+ "overloadIndex": 1,
8651
+ "parameters": [
8652
+ {
8653
+ "parameterName": "sourcesList",
8654
+ "parameterTypeTokenRange": {
8655
+ "startIndex": 1,
8656
+ "endIndex": 3
8657
+ },
8658
+ "isOptional": false
8659
+ }
8660
+ ],
8661
+ "isOptional": false,
8662
+ "isAbstract": false,
8663
+ "name": "setMediaSource"
8558
8664
  }
8559
8665
  ],
8560
8666
  "extendsTokenRange": {