Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/mux-player/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const muxMediaErrorToDialogTitle = (mediaError: MediaError, translate = false) =
return i18n(`{category} does not exist`, translate).format({ category });
}
if (mediaError.muxCode === MuxErrorCode.NETWORK_NOT_READY) {
return i18n(`{category} is not currently available`, translate).format({ category });
const mediaType = mediaError.streamType === 'live' ? 'Live stream' : 'Video';
return i18n(`{mediaType} is not currently available`, translate).format({ mediaType });
}
}

Expand Down Expand Up @@ -102,7 +103,7 @@ const muxMediaErrorToDialogMessage = (mediaError: MediaError, translate = false)
return '';
}
if (mediaError.muxCode === MuxErrorCode.NETWORK_NOT_READY) {
return i18n(`The live stream or video file are not yet ready.`, translate);
return i18n(`Retrying in 5 seconds...`, translate);
}
return mediaError.message;
}
Expand Down
1 change: 1 addition & 0 deletions packages/playback-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class MediaError extends Error {
context?: string;
fatal: boolean;
data?: any;
streamType?: 'live' | 'on-demand' | 'unknown';

constructor(message?: Stringable, code: number = MediaError.MEDIA_ERR_CUSTOM, fatal?: boolean, context?: string) {
super(message);
Expand Down
2 changes: 2 additions & 0 deletions packages/playback-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ export const loadMedia = (
hls.on(Hls.Events.ERROR, (_event, data) => {
saveAndDispatchError(mediaEl, getErrorFromHlsErrorData(data, props));
});

mediaEl.addEventListener('error', handleInternalError);
addEventListenerWithTeardown(mediaEl, 'waiting', maybeDispatchEndedCallback);

Expand Down Expand Up @@ -1386,6 +1387,7 @@ const getErrorFromHlsErrorData = (
props: Partial<Pick<MuxMediaPropsInternal, 'playbackId' | 'drmToken' | 'playbackToken' | 'tokens'>>
) => {
console.error('getErrorFromHlsErrorData()', data);

const ErrorCodeMap: Partial<Record<ValueOf<typeof Hls.ErrorTypes>, 0 | 1 | 2 | 3 | 4 | 5>> = {
[Hls.ErrorTypes.NETWORK_ERROR]: MediaError.MEDIA_ERR_NETWORK,
[Hls.ErrorTypes.MEDIA_ERROR]: MediaError.MEDIA_ERR_DECODE,
Expand Down
12 changes: 10 additions & 2 deletions packages/playback-core/src/request-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
parseJwt,
toPlaybackIdParts,
} from './util';
import { isKeyOf, MuxMediaPropsInternal } from './types';
import { isKeyOf, MuxMediaPropsInternal, StreamTypes } from './types';
import type { MuxErrorCategoryValue } from './errors';
import { errorCategoryToTokenNameOrPrefix, MediaError, MuxErrorCategory, MuxErrorCode } from './errors';

Expand Down Expand Up @@ -39,7 +39,9 @@ export const categoryToToken = (
export const getErrorFromResponse = (
resp: Pick<Response, 'status' | 'url'> | Pick<LoaderResponse, 'code' | 'url'>,
category: MuxErrorCategoryValue,
muxMediaEl: Partial<Pick<MuxMediaPropsInternal, 'playbackId' | 'drmToken' | 'playbackToken' | 'tokens'>>,
muxMediaEl: Partial<
Pick<MuxMediaPropsInternal, 'playbackId' | 'drmToken' | 'playbackToken' | 'tokens' | 'streamType'>
>,
fatal?: boolean,
translate = false,
offline = !globalThis.navigator?.onLine // NOTE: Passing this in for testing purposes
Expand Down Expand Up @@ -205,6 +207,12 @@ export const getErrorFromResponse = (
const mediaError = new MediaError(message, mediaErrorCode, fatal ?? true, context);
mediaError.errorCategory = category;
mediaError.muxCode = MuxErrorCode.NETWORK_NOT_READY;
mediaError.streamType =
muxMediaEl.streamType === StreamTypes.LIVE
? 'live'
: muxMediaEl.streamType === StreamTypes.ON_DEMAND
? 'on-demand'
: 'unknown';
mediaError.data = resp;
return mediaError;
}
Expand Down
Loading