Skip to content

Commit 228d559

Browse files
authored
feat: introduce expo-video support (#3010)
* feat: introduce support for expo-video * fix: remove redundant test * fix: add check for audio component
1 parent 1f84064 commit 228d559

File tree

15 files changed

+109
-143
lines changed

15 files changed

+109
-143
lines changed

examples/ExpoMessaging/app.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
{
4949
"microphonePermission": "$(PRODUCT_NAME) would like to use your microphone for voice recording."
5050
}
51+
],
52+
[
53+
"expo-video",
54+
{
55+
"supportsBackgroundPlayback": true,
56+
"supportsPictureInPicture": true
57+
}
5158
]
5259
]
5360
}

examples/ExpoMessaging/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"expo-sharing": "~13.0.1",
2929
"expo-splash-screen": "~0.29.22",
3030
"expo-status-bar": "~2.0.1",
31+
"expo-video": "^2.0.5",
3132
"react": "18.3.1",
3233
"react-dom": "18.3.1",
3334
"react-native": "0.77.1",

examples/ExpoMessaging/yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,6 +4363,11 @@ expo-status-bar@~2.0.1:
43634363
resolved "https://registry.yarnpkg.com/expo-status-bar/-/expo-status-bar-2.0.1.tgz#fc07726346dc30fbb68aadb0d7890b34fba42eee"
43644364
integrity sha512-AkIPX7jWHRPp83UBZ1iXtVvyr0g+DgBVvIXTtlmPtmUsm8Vq9Bb5IGj86PW8osuFlgoTVAg7HI/+Ok7yEYwiRg==
43654365

4366+
expo-video@^2.0.5:
4367+
version "2.0.5"
4368+
resolved "https://registry.yarnpkg.com/expo-video/-/expo-video-2.0.5.tgz#5c5311b0a20dcb7897d06cd4f9d7fb0ce13711d9"
4369+
integrity sha512-K5Q4bFKtYq0wEC38mckWUYeaTXsmhl6duidhSdbA63VBy6cwxDOk8uPsFPTQD3FXKJg6wFB0z8ZUASSPuUaY5A==
4370+
43664371
expo@~52.0.36:
43674372
version "52.0.37"
43684373
resolved "https://registry.yarnpkg.com/expo/-/expo-52.0.37.tgz#159b5f3f9bedb2c56b36a815b8679a2602a406cc"
@@ -7397,10 +7402,10 @@ [email protected], stream-buffers@~2.2.0:
73977402
version "0.0.0"
73987403
uid ""
73997404

7400-
7401-
version "9.0.0-rc.4"
7402-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.4.tgz#30ffd324069cd012372014efe3a6d94bf264963a"
7403-
integrity sha512-kVlDls6TXEWAlAQf6WLwNv3wDwVo0y9J536+NS8PFmkJKkBNfD9RGAbb4SuZNxeEpd+kAy3861vxspB1mpFEmQ==
7405+
7406+
version "9.0.0-rc.7"
7407+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.7.tgz#c2c1ab17cda9c55a0068720164228b3d92852db7"
7408+
integrity sha512-hvwilti9vqEGBnD8v81/4s1IOgOKmzG+d/49BDGzrwUl8M2yDLvIWd93Xo4gj/+0edEgcOVaW4gncenEqXVR9A==
74047409
dependencies:
74057410
"@types/jsonwebtoken" "^9.0.8"
74067411
"@types/ws" "^8.5.14"

examples/SampleApp/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7538,10 +7538,10 @@ statuses@~1.5.0:
75387538
version "0.0.0"
75397539
uid ""
75407540

7541-
7542-
version "9.0.0-rc.4"
7543-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.4.tgz#30ffd324069cd012372014efe3a6d94bf264963a"
7544-
integrity sha512-kVlDls6TXEWAlAQf6WLwNv3wDwVo0y9J536+NS8PFmkJKkBNfD9RGAbb4SuZNxeEpd+kAy3861vxspB1mpFEmQ==
7541+
7542+
version "9.0.0-rc.7"
7543+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.7.tgz#c2c1ab17cda9c55a0068720164228b3d92852db7"
7544+
integrity sha512-hvwilti9vqEGBnD8v81/4s1IOgOKmzG+d/49BDGzrwUl8M2yDLvIWd93Xo4gj/+0edEgcOVaW4gncenEqXVR9A==
75457545
dependencies:
75467546
"@types/jsonwebtoken" "^9.0.8"
75477547
"@types/ws" "^8.5.14"

package/expo-package/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
"main": "src/index.js",
1111
"types": "types/index.d.ts",
1212
"dependencies": {
13-
"stream-chat-react-native-core": "6.6.7"
13+
"stream-chat-react-native-core": "link:../"
1414
},
1515
"peerDependencies": {
1616
"expo": ">=51.0.0",
1717
"expo-av": "*",
18+
"expo-video": "*",
1819
"expo-clipboard": "*",
1920
"expo-document-picker": "*",
2021
"expo-file-system": "*",
@@ -28,6 +29,9 @@
2829
"expo-av": {
2930
"optional": true
3031
},
32+
"expo-video": {
33+
"optional": true
34+
},
3135
"expo-clipboard": {
3236
"optional": true
3337
},
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
let VideoComponent;
21
let AudioComponent;
32
let RecordingObject;
43
try {
54
const audioVideoPackage = require('expo-av');
6-
VideoComponent = audioVideoPackage.Video;
75
AudioComponent = audioVideoPackage.Audio;
86
RecordingObject = audioVideoPackage.RecordingObject;
97
} catch (e) {
108
// do nothing
119
}
1210

13-
if (!VideoComponent || !AudioComponent) {
11+
if (!AudioComponent) {
1412
console.log(
15-
'Audio Video library is currently not installed. To allow in-app audio or video playback, install the "expo-av" package.',
13+
'Audio Video library is currently not installed. To allow in-app audio playback, install the "expo-av" package.',
1614
);
1715
}
1816

19-
export { AudioComponent, VideoComponent, RecordingObject };
17+
export { AudioComponent, RecordingObject };

package/expo-package/src/optionalDependencies/Video.tsx

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,71 @@
11
import React, { useEffect } from 'react';
22

3-
import { AudioComponent, VideoComponent } from './AudioVideo';
3+
import { useEventListener } from 'expo';
4+
5+
import { AudioComponent } from './AudioVideo';
6+
7+
let videoPackage;
8+
9+
try {
10+
videoPackage = require('expo-video');
11+
} catch (e) {
12+
// do nothing
13+
}
14+
15+
if (!videoPackage) {
16+
console.log(
17+
'The video library is currently not installed. To allow in-app video playback, install the "expo-video" package.',
18+
);
19+
}
20+
21+
const VideoComponent = videoPackage ? videoPackage.VideoView : null;
22+
const useVideoPlayer = videoPackage ? videoPackage.useVideoPlayer : null;
23+
24+
export const Video = videoPackage
25+
? ({ onLoadStart, onLoad, onEnd, onProgress, onBuffer, resizeMode, style, uri, videoRef }) => {
26+
const player = useVideoPlayer(uri, (player) => {
27+
player.timeUpdateEventInterval = 0.5;
28+
videoRef.current = player;
29+
});
30+
31+
useEventListener(player, 'statusChange', ({ status, oldStatus }) => {
32+
if ((!oldStatus || oldStatus === 'idle') && status === 'loading') {
33+
onLoadStart();
34+
} else if ((oldStatus === 'loading' || oldStatus === 'idle') && status === 'readyToPlay') {
35+
onLoad({ duration: player.duration });
36+
onBuffer({ buffering: false });
37+
} else if (oldStatus === 'readyToPlay' && status === 'loading') {
38+
onBuffer({ buffering: true });
39+
}
40+
});
41+
42+
useEventListener(player, 'playToEnd', () => {
43+
player.replay();
44+
onEnd();
45+
});
46+
47+
useEventListener(player, 'timeUpdate', ({ currentTime }) =>
48+
onProgress({ currentTime, seekableDuration: player.duration }),
49+
);
450

5-
export const Video = VideoComponent
6-
? ({ onPlaybackStatusUpdate, paused, resizeMode, style, uri, videoRef }) => {
751
// This is done so that the audio of the video is not muted when the phone is in silent mode for iOS.
852
useEffect(() => {
953
const initializeSound = async () => {
10-
await AudioComponent.setAudioModeAsync({
11-
playsInSilentModeIOS: true,
12-
});
54+
if (AudioComponent) {
55+
await AudioComponent.setAudioModeAsync({
56+
playsInSilentModeIOS: true,
57+
});
58+
}
1359
};
1460
initializeSound();
1561
}, []);
1662

1763
return (
1864
<VideoComponent
19-
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
20-
ref={videoRef}
21-
resizeMode={resizeMode}
22-
shouldPlay={!paused}
23-
source={{
24-
uri,
25-
}}
65+
allowsFullscreen
66+
contentFit={resizeMode}
67+
nativeControls={false}
68+
player={player}
2669
style={[style]}
2770
/>
2871
);

package/expo-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,10 +4772,10 @@ [email protected], stream-buffers@~2.2.0:
47724772
version "0.0.0"
47734773
uid ""
47744774

4775-
4776-
version "9.0.0-rc.4"
4777-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.4.tgz#30ffd324069cd012372014efe3a6d94bf264963a"
4778-
integrity sha512-kVlDls6TXEWAlAQf6WLwNv3wDwVo0y9J536+NS8PFmkJKkBNfD9RGAbb4SuZNxeEpd+kAy3861vxspB1mpFEmQ==
4775+
4776+
version "9.0.0-rc.7"
4777+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.7.tgz#c2c1ab17cda9c55a0068720164228b3d92852db7"
4778+
integrity sha512-hvwilti9vqEGBnD8v81/4s1IOgOKmzG+d/49BDGzrwUl8M2yDLvIWd93Xo4gj/+0edEgcOVaW4gncenEqXVR9A==
47794779
dependencies:
47804780
"@types/jsonwebtoken" "^9.0.8"
47814781
"@types/ws" "^8.5.14"

package/native-package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"types": "types/index.d.ts",
2121
"dependencies": {
2222
"es6-symbol": "^3.1.3",
23-
"stream-chat-react-native-core": "6.6.7"
23+
"stream-chat-react-native-core": "link:../"
2424
},
2525
"peerDependencies": {
2626
"@react-native-camera-roll/camera-roll": ">=7.8.0",

package/native-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,10 +3444,10 @@ statuses@~1.5.0:
34443444
version "0.0.0"
34453445
uid ""
34463446

3447-
3448-
version "9.0.0-rc.4"
3449-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.4.tgz#30ffd324069cd012372014efe3a6d94bf264963a"
3450-
integrity sha512-kVlDls6TXEWAlAQf6WLwNv3wDwVo0y9J536+NS8PFmkJKkBNfD9RGAbb4SuZNxeEpd+kAy3861vxspB1mpFEmQ==
3447+
3448+
version "9.0.0-rc.7"
3449+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.0.0-rc.7.tgz#c2c1ab17cda9c55a0068720164228b3d92852db7"
3450+
integrity sha512-hvwilti9vqEGBnD8v81/4s1IOgOKmzG+d/49BDGzrwUl8M2yDLvIWd93Xo4gj/+0edEgcOVaW4gncenEqXVR9A==
34513451
dependencies:
34523452
"@types/jsonwebtoken" "^9.0.8"
34533453
"@types/ws" "^8.5.14"

0 commit comments

Comments
 (0)