Skip to content

Commit d8a8dc2

Browse files
authored
feat: add support for multiple concurrent players (#30)
- Enable simultaneous usage of multiple player instances - Implement independent instance management for each player - Support concurrent playback without interference
1 parent fa294d9 commit d8a8dc2

File tree

7 files changed

+60
-23
lines changed

7 files changed

+60
-23
lines changed

.changeset/itchy-rooms-crash.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"react-native-vimeo-bridge": minor
3+
---
4+
5+
feat: add support for multiple concurrent players
6+
7+
- Enable simultaneous usage of multiple player instances
8+
- Implement independent instance management for each player
9+
- Support concurrent playback without interference

README-ko_kr.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ React Native에서 Vimeo 플레이어를 사용하기 위해 복잡한 설정과
1616
-**풍부한 API** - Vimeo Player JS API의 모든 핵심 기능 지원
1717
-**React Native 개발** - Expo의 Hook 기반 방식처럼, 직관적이고 사용하기 쉬운 API를 제공
1818
-**Expo 호환** - Expo 프로젝트에서도 바로 사용 가능
19+
-**다중 인스턴스 지원** - 여러 플레이어를 독립적으로 관리 가능
1920

2021
## 빠른 시작
2122

@@ -142,6 +143,27 @@ function App() {
142143
}
143144
```
144145

146+
### 다중 플레이어 지원
147+
148+
여러 플레이어를 동시에 사용할 수 있습니다.
149+
각 플레이어는 독립적인 인스턴스로 관리되며, 컴포넌트 unmount 시 자동으로 정리됩니다.
150+
151+
```tsx
152+
import { useVimeoPlayer, VimeoView } from 'react-native-vimeo-bridge';
153+
154+
function App() {
155+
const player1 = useVimeoPlayer(vimeoUrl1);
156+
const player2 = useVimeoPlayer(vimeoUrl2);
157+
158+
return (
159+
<View>
160+
<VimeoView player={player1} />
161+
<VimeoView player={player2} />
162+
</View>
163+
);
164+
}
165+
```
166+
145167
### 임베드 옵션 설정
146168

147169
Vimeo Player의 [임베드 옵션](https://developer.vimeo.com/player/sdk/embed)을 통해 초기 설정을 커스터마이징할 수 있습니다.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ With the lack of actively maintained Vimeo player libraries for React Native, `r
1616
-**Rich API Support** - Access to all core Vimeo Player JS API features
1717
-**React Native Development** - Provides an intuitive, easy-to-use Hook-based API, much like Expo's approach
1818
-**Expo Compatible** - Ready to use in Expo projects
19+
-**Multiple instance support** - manage multiple players independently
1920

2021
## Quick Start
2122

@@ -142,6 +143,27 @@ function App() {
142143
}
143144
```
144145

146+
### Multiple Player Support
147+
148+
Multiple players can be used simultaneously.
149+
Each player is managed as an independent instance and automatically cleaned up when the component unmounts.
150+
151+
```tsx
152+
import { useVimeoPlayer, VimeoView } from 'react-native-vimeo-bridge';
153+
154+
function App() {
155+
const player1 = useVimeoPlayer(vimeoUrl1);
156+
const player2 = useVimeoPlayer(vimeoUrl2);
157+
158+
return (
159+
<View>
160+
<VimeoView player={player1} />
161+
<VimeoView player={player2} />
162+
</View>
163+
);
164+
}
165+
```
166+
145167
### Embed Options
146168

147169
Customize initial settings through Vimeo Player [embed options](https://developer.vimeo.com/player/sdk/embed).

src/VimeoView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function VimeoView({ player, height = 200, width = screenWidth, style, webViewPr
213213

214214
useEffect(() => {
215215
if (isReady && webViewRef.current) {
216-
const controller = WebviewVimeoPlayerController.getInstance(webViewRef);
216+
const controller = WebviewVimeoPlayerController.createInstance(webViewRef);
217217

218218
playerRef.current = controller;
219219

src/VimeoView.web.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ function VimeoView({ player, height = 200, width, style, iframeStyle }: VimeoVie
1616
useEffect(() => {
1717
WebVimeoPlayerController.initialize().then(() => {
1818
setIsInitialized(true);
19-
playerRef.current = WebVimeoPlayerController.getInstance();
19+
playerRef.current = WebVimeoPlayerController.createInstance();
2020
});
2121
}, []);
2222

2323
useEffect(() => {
2424
const source = player.getSource();
2525

2626
if (isInitialized && containerRef.current && source) {
27-
const containerId = `vimeo-player`;
27+
const containerId = `vimeo-player-${Math.random().toString(36).substring(2, 15)}`;
2828
containerRef.current.id = containerId;
2929
const options = player.getOptions();
3030

src/module/WebVimeoPlayerController.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import type { EmbedOptions, EventCallback, VimeoPlayer } from '../types/vimeo';
22

33
class WebVimeoPlayerController {
44
private player: VimeoPlayer | null = null;
5-
private static instance: WebVimeoPlayerController | null = null;
65

7-
static getInstance(): WebVimeoPlayerController {
8-
if (!WebVimeoPlayerController.instance) {
9-
WebVimeoPlayerController.instance = new WebVimeoPlayerController();
10-
}
11-
12-
return WebVimeoPlayerController.instance;
6+
static createInstance(): WebVimeoPlayerController {
7+
return new WebVimeoPlayerController();
138
}
149

1510
static initialize(): Promise<void> {
@@ -165,8 +160,6 @@ class WebVimeoPlayerController {
165160
}
166161
this.player = null;
167162
}
168-
169-
WebVimeoPlayerController.instance = null;
170163
}
171164
}
172165

src/module/WebviewVimeoPlayerController.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@ class WebviewVimeoPlayerController {
55
private webViewRef: React.RefObject<WebView | null>;
66
private commandId: number = 0;
77
private pendingCommands: Map<string, (result: unknown) => void> = new Map();
8-
private static instance: WebviewVimeoPlayerController | null = null;
98

109
constructor(webViewRef: React.RefObject<WebView | null>) {
1110
this.webViewRef = webViewRef;
1211
}
1312

14-
static getInstance(webViewRef: React.RefObject<WebView | null>): WebviewVimeoPlayerController {
15-
if (!WebviewVimeoPlayerController.instance) {
16-
WebviewVimeoPlayerController.instance = new WebviewVimeoPlayerController(webViewRef);
17-
} else {
18-
WebviewVimeoPlayerController.instance.webViewRef = webViewRef;
19-
}
20-
21-
return WebviewVimeoPlayerController.instance;
13+
static createInstance(webViewRef: React.RefObject<WebView | null>): WebviewVimeoPlayerController {
14+
return new WebviewVimeoPlayerController(webViewRef);
2215
}
2316

2417
getPendingCommands(): Map<string, (result: unknown) => void> {
@@ -148,8 +141,6 @@ class WebviewVimeoPlayerController {
148141
dispose(): void {
149142
this.pendingCommands.clear();
150143
this.destroy();
151-
152-
WebviewVimeoPlayerController.instance = null;
153144
}
154145
}
155146

0 commit comments

Comments
 (0)