Skip to content

Commit dd71bfe

Browse files
authored
fix: make sure we have source on cldsourcechanged (#871)
1 parent e61ea93 commit dd71bfe

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/plugins/adaptive-streaming/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ export default async function lazyAdaptiveStreamingPlugin(options) {
22
const player = this;
33

44
try {
5-
if (options.isDash) {
5+
if (options.isDash && !window.dashjs) {
66
await import(/* webpackChunkName: "dash" */ 'videojs-contrib-dash');
77
}
8-
await import(/* webpackChunkName: "adaptive-streaming" */ './adaptive-streaming');
98
const { default: abrPlugin } = await import(/* webpackChunkName: "adaptive-streaming" */ './adaptive-streaming');
109
abrPlugin(player, options);
1110
} catch (error) {

src/plugins/cloudinary-analytics/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CloudinaryAnalytics {
2424
const metadata = this.getMetadata();
2525

2626
if (metadata.cloudName && metadata.publicId) {
27-
const isLiveStream = source.resourceConfig().type === 'live';
27+
const isLiveStream = source?.resourceConfig().type === 'live';
2828
this.currentVideoMetadata = metadata;
2929
this.cloudinaryAnalytics.startManualTracking({
3030
...metadata,

src/plugins/cloudinary/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ class CloudinaryContext {
269269

270270
const refresh = () => {
271271
const src = this.source();
272+
if (!src) {
273+
return;
274+
}
275+
272276
const posterOptions = Object.assign({}, this.player.cloudinary.posterOptions(), src.getInitOptions().poster);
273277

274278
if (posterOptions.posterColor) {

src/video-player.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
321321
this.videojs.controlBar.removeChild('chaptersButton');
322322
}
323323
this.videojs.on(PLAYER_EVENT.CLD_SOURCE_CHANGED, (e, { source }) => {
324-
if ((!isEmpty(source._chapters) || source._chapters === true) && this.videojs.chapters) {
324+
if ((!isEmpty(source?._chapters) || source?._chapters === true) && this.videojs.chapters) {
325325
isFunction(this.videojs.chapters)
326326
? this.videojs.chapters(source._chapters)
327327
: this.videojs.chapters.src(source._chapters);
@@ -342,11 +342,11 @@ class VideoPlayer extends Utils.mixin(Eventable) {
342342
_initVisualSearch() {
343343
// Listen for source changes to apply visual search based on source config
344344
this.videojs.on(PLAYER_EVENT.CLD_SOURCE_CHANGED, (e, { source }) => {
345-
if (source._visualSearch && this.videojs.visualSearch) {
345+
if (source?._visualSearch && this.videojs.visualSearch) {
346346
isFunction(this.videojs.visualSearch)
347347
? this.videojs.visualSearch(source._visualSearch)
348348
: this.videojs.visualSearch.createSearchUI(source._visualSearch);
349-
} else if (!source._visualSearch && this.videojs.visualSearch?.clearUI) {
349+
} else if (!source?._visualSearch && this.videojs.visualSearch?.clearUI) {
350350
this.videojs.visualSearch.clearUI();
351351
}
352352
});
@@ -360,7 +360,9 @@ class VideoPlayer extends Utils.mixin(Eventable) {
360360

361361
_initTextTracks () {
362362
this.videojs.on(PLAYER_EVENT.CLD_SOURCE_CHANGED, (e, { source }) => {
363-
this.setTextTracks(source._textTracks);
363+
if (source?._textTracks) {
364+
this.setTextTracks(source._textTracks);
365+
}
364366
});
365367
}
366368

@@ -502,7 +504,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
502504

503505
_onSourceChange(e, { source, sourceOptions }) {
504506
this._sendInternalAnalytics({ ...(sourceOptions && { sourceOptions }) });
505-
this.isLiveStream = source.resourceConfig().type === 'live';
507+
this.isLiveStream = source?.resourceConfig()?.type === 'live';
506508
}
507509

508510
_setExtendedEvents() {

0 commit comments

Comments
 (0)