Skip to content

Commit 6350a9b

Browse files
authored
fix: respect hls.js fatal error flag if available (#1099)
fixes an issue where playback is not broken yet but the player throws a fatal error making the error dialog show up while the video is playing underneath.
1 parent 7fc6a2c commit 6350a9b

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- uses: nick-fields/retry@v3
7878
with:
7979
timeout_minutes: 10
80-
max_attempts: 3
80+
max_attempts: 6
8181
# run npm test and pass through `-- --all` to turborepo
8282
command: npm run test -- -- --all
8383
- name: Upload coverage to Codecov

packages/playback-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,8 @@ const getErrorFromHlsErrorData = (
14151415
const errorCode = hlsErrorDataToErrorCode(data);
14161416
if (errorCode === MediaError.MEDIA_ERR_NETWORK && data.response) {
14171417
const category = hlsErrorDataToCategory(data) ?? MuxErrorCategory.VIDEO;
1418-
mediaError = getErrorFromResponse(data.response, category, props) ?? new MediaError('', errorCode);
1418+
mediaError =
1419+
getErrorFromResponse(data.response, category, props, data.fatal) ?? new MediaError('', errorCode, data.fatal);
14191420
} else if (errorCode === MediaError.MEDIA_ERR_ENCRYPTED) {
14201421
if (data.details === Hls.ErrorDetails.KEY_SYSTEM_NO_CONFIGURED_LICENSE) {
14211422
const message = i18n('Attempting to play DRM-protected content without providing a DRM token.');

packages/playback-core/src/request-errors.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ export const getErrorFromResponse = (
4040
resp: Pick<Response, 'status' | 'url'> | Pick<LoaderResponse, 'code' | 'url'>,
4141
category: MuxErrorCategoryValue,
4242
muxMediaEl: Partial<Pick<MuxMediaPropsInternal, 'playbackId' | 'drmToken' | 'playbackToken' | 'tokens'>>,
43+
fatal?: boolean,
4344
translate = false,
4445
offline = !globalThis.navigator?.onLine // NOTE: Passing this in for testing purposes
4546
) => {
4647
if (offline) {
4748
const message = i18n(`Your device appears to be offline`, translate);
4849
const context = undefined;
4950
const mediaErrorCode = MediaError.MEDIA_ERR_NETWORK;
50-
const mediaError = new MediaError(message, mediaErrorCode, true, context);
51+
// Being offline is not immediately a fatal error for playback.
52+
const mediaError = new MediaError(message, mediaErrorCode, false, context);
5153
mediaError.errorCategory = category;
5254
mediaError.muxCode = MuxErrorCode.NETWORK_OFFLINE;
5355
mediaError.data = resp;
@@ -88,7 +90,7 @@ export const getErrorFromResponse = (
8890
* @TODO We plausibly should have some basic retry logic for all other 500 status
8991
* cases (CJP)
9092
**/
91-
const mediaError = new MediaError('', mediaErrorCode, true);
93+
const mediaError = new MediaError('', mediaErrorCode, fatal ?? true);
9294
mediaError.errorCategory = category;
9395
mediaError.muxCode = MuxErrorCode.NETWORK_UNKNOWN_ERROR;
9496
/** @TODO Add error msg + context crud here (NOT YET DEFINED) (CJP) */
@@ -186,7 +188,7 @@ export const getErrorFromResponse = (
186188
category,
187189
});
188190
const context = i18n(`Specified playback ID: {playbackId}`, translate).format({ playbackId });
189-
const mediaError = new MediaError(message, mediaErrorCode, true, context);
191+
const mediaError = new MediaError(message, mediaErrorCode, fatal ?? true, context);
190192
mediaError.errorCategory = category;
191193
mediaError.muxCode = MuxErrorCode.NETWORK_TOKEN_MISSING;
192194
mediaError.data = resp;
@@ -200,7 +202,7 @@ export const getErrorFromResponse = (
200202
translate
201203
);
202204
const context = i18n(`Specified playback ID: {playbackId}`, translate).format({ playbackId });
203-
const mediaError = new MediaError(message, mediaErrorCode, true, context);
205+
const mediaError = new MediaError(message, mediaErrorCode, fatal ?? true, context);
204206
mediaError.errorCategory = category;
205207
mediaError.muxCode = MuxErrorCode.NETWORK_NOT_READY;
206208
mediaError.data = resp;
@@ -222,7 +224,7 @@ export const getErrorFromResponse = (
222224
translate
223225
);
224226
const context = i18n(`Specified playback ID: {playbackId}`, translate).format({ playbackId });
225-
const mediaError = new MediaError(message, mediaErrorCode, true, context);
227+
const mediaError = new MediaError(message, mediaErrorCode, fatal ?? true, context);
226228
mediaError.errorCategory = category;
227229
mediaError.muxCode = MuxErrorCode.NETWORK_NOT_FOUND;
228230
mediaError.data = resp;
@@ -240,14 +242,14 @@ export const getErrorFromResponse = (
240242
if (status === 400) {
241243
const message = i18n(`The URL or playback-id was invalid. You may have used an invalid value as a playback-id.`);
242244
const context = i18n(`Specified playback ID: {playbackId}`, translate).format({ playbackId });
243-
const mediaError = new MediaError(message, mediaErrorCode, true, context);
245+
const mediaError = new MediaError(message, mediaErrorCode, fatal ?? true, context);
244246
mediaError.errorCategory = category;
245247
mediaError.muxCode = MuxErrorCode.NETWORK_INVALID_URL;
246248
mediaError.data = resp;
247249
return mediaError;
248250
}
249251

250-
const mediaError = new MediaError('', mediaErrorCode, true);
252+
const mediaError = new MediaError('', mediaErrorCode, fatal ?? true);
251253
mediaError.errorCategory = category;
252254
mediaError.muxCode = MuxErrorCode.NETWORK_UNKNOWN_ERROR;
253255
mediaError.data = resp;

0 commit comments

Comments
 (0)