From 42f32b079d83bc8944250f66cbd2c0704018c966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Moska=C5=82a?= Date: Thu, 26 Mar 2026 17:30:04 +0100 Subject: [PATCH] fix(web): add WebError type with proper HTML5 MediaError code mapping --- .../src/core/types/VideoError.ts | 7 ++++++ .../src/core/web/WebEventEmitter.ts | 22 ++++++------------- packages/react-native-video/src/index.tsx | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/react-native-video/src/core/types/VideoError.ts b/packages/react-native-video/src/core/types/VideoError.ts index a1cbbe7d..550705ce 100644 --- a/packages/react-native-video/src/core/types/VideoError.ts +++ b/packages/react-native-video/src/core/types/VideoError.ts @@ -20,6 +20,12 @@ export type VideoViewError = | 'view/deallocated' | 'view/picture-in-picture-not-supported'; +export type WebError = + | 'web/aborted' + | 'web/network' + | 'web/decode' + | 'web/unsupported-source'; + export type UnknownError = 'unknown/unknown'; export type VideoErrorCode = @@ -27,6 +33,7 @@ export type VideoErrorCode = | PlayerError | SourceError | VideoViewError + | WebError | UnknownError; export class VideoError extends Error { diff --git a/packages/react-native-video/src/core/web/WebEventEmitter.ts b/packages/react-native-video/src/core/web/WebEventEmitter.ts index da9e95c8..45ed361e 100644 --- a/packages/react-native-video/src/core/web/WebEventEmitter.ts +++ b/packages/react-native-video/src/core/web/WebEventEmitter.ts @@ -9,10 +9,7 @@ import type { } from '../types/Events'; import type { TextTrack } from '../types/TextTrack'; import { - type LibraryError, - type PlayerError, - type SourceError, - type UnknownError, + type WebError, VideoError, type VideoRuntimeError, } from '../types/VideoError'; @@ -33,7 +30,6 @@ export class WebEventEmitter implements VideoPlayerEventEmitterBase { private _listeners: Map void>> = new Map(); private _mediaCleanup: (() => void) | null = null; private _storeUnsubscribe: (() => void) | null = null; - private _store: VideoStore | null = null; private _isBuffering = false; constructor( @@ -48,10 +44,9 @@ export class WebEventEmitter implements VideoPlayerEventEmitterBase { /** * Connect or disconnect the video.js store (optional enhancement). */ - setStore(store: VideoStore | null) { + setStore(_store: VideoStore | null) { this._storeUnsubscribe?.(); this._storeUnsubscribe = null; - this._store = store; } destroy() { @@ -199,14 +194,11 @@ export class WebEventEmitter implements VideoPlayerEventEmitterBase { console.error('Unknown error occurred in player'); return; } - const codeMap: Record< - number, - LibraryError | PlayerError | SourceError | UnknownError - > = { - 1: 'player/asset-not-initialized', - 2: 'player/not-initialized', - 3: 'player/invalid-source', - 4: 'source/unsupported-content-type', + const codeMap: Record = { + 1: 'web/aborted', + 2: 'web/network', + 3: 'web/decode', + 4: 'web/unsupported-source', }; this._emit( 'onError', diff --git a/packages/react-native-video/src/index.tsx b/packages/react-native-video/src/index.tsx index b84723dc..0c7aa4ad 100644 --- a/packages/react-native-video/src/index.tsx +++ b/packages/react-native-video/src/index.tsx @@ -19,6 +19,7 @@ export type { VideoErrorCode, VideoRuntimeError, VideoViewError, + WebError, } from './core/types/VideoError'; export type { VideoPlayerStatus } from './core/types/VideoPlayerStatus';