From 9bce20ea7acc0584b45cd5e1b84924de1a50fc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Moska=C5=82a?= Date: Thu, 26 Mar 2026 18:13:39 +0100 Subject: [PATCH] refactor: extract WebMediaProxy for unified store/video access --- .../src/core/VideoPlayer.web.ts | 107 ++++++++---------- .../src/core/web/WebEventEmitter.ts | 54 +++------ .../src/core/web/WebMediaProxy.ts | 81 +++++++++++++ 3 files changed, 144 insertions(+), 98 deletions(-) create mode 100644 packages/react-native-video/src/core/web/WebMediaProxy.ts diff --git a/packages/react-native-video/src/core/VideoPlayer.web.ts b/packages/react-native-video/src/core/VideoPlayer.web.ts index d08b1304..a931b83c 100644 --- a/packages/react-native-video/src/core/VideoPlayer.web.ts +++ b/packages/react-native-video/src/core/VideoPlayer.web.ts @@ -15,6 +15,7 @@ import type { VideoPlayerStatus } from './types/VideoPlayerStatus'; import { VideoPlayerEvents } from './events/VideoPlayerEvents'; import { MediaSessionHandler } from './web/MediaSession'; import { WebEventEmitter } from './web/WebEventEmitter'; +import { WebMediaProxy } from './web/WebMediaProxy'; import type { VideoStore } from './web/VideoStore'; function setExternalSubtitles( @@ -84,22 +85,10 @@ function selectTrack( } class VideoPlayer extends VideoPlayerEvents implements WebVideoPlayer { - private video: HTMLVideoElement; - private _storeRef: WeakRef | null = null; + private _media: WebMediaProxy; private mediaSession: MediaSessionHandler | null = null; private _source: NativeVideoConfig | undefined; - /** Returns store if alive, null if destroyed or disconnected. */ - private get _store(): VideoStore | null { - const store = this._storeRef?.deref() ?? null; - return store?.destroyed ? null : store; - } - - /** Store when available, video element fallback. */ - private get media(): VideoStore | HTMLVideoElement { - return this._store ?? this.video; - } - /** * Creates a detached