Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add react-native-web support #3958

Merged
merged 30 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b06cfc8
Add shell.nix for nix users
zoriya Jun 30, 2024
b5260ca
Add VideoDecoderProperties for the web
zoriya Jun 30, 2024
8c72306
Move video ref type to its own file
zoriya Jun 30, 2024
afa8c03
Create ref handling and basics stollen from Kyoo
zoriya Jun 30, 2024
9b39bee
Add most events
zoriya Jun 30, 2024
b840755
Add most properties
zoriya Jun 30, 2024
733a95d
Add media session support
zoriya Jun 30, 2024
c4a920d
Make the basic example app work on web
zoriya Jul 1, 2024
d281a86
Fix web bugs
zoriya Jul 1, 2024
6e58566
Test notifications on web
zoriya Jul 1, 2024
45f23e0
Cleanup media session handling on the web
zoriya Jul 1, 2024
a1798e0
Update the doc for web things
zoriya Jul 1, 2024
c71f3ce
Prevent playback state change loop on web
zoriya Jul 1, 2024
f90118e
Fix and improve VideoNativeComponent (canPlay/isWidewine supportd) fo…
zoriya Jul 9, 2024
76b233f
Move video style to const var
zoriya Jul 9, 2024
c861cee
Renamve nativeHtmlRef to nativeHtmlVideoRef
zoriya Jul 9, 2024
a2923ec
Update doc for web
zoriya Jul 9, 2024
6fe3c0e
Remove unused errorHandler ref
zoriya Jul 10, 2024
7485da1
Add web support for fullscreen
zoriya Jul 10, 2024
6440439
Add isSeeking on web
zoriya Jul 16, 2024
f76af4a
Fix native import on web
zoriya Jul 16, 2024
562465d
Add nativeHtmlVideoRef doc
zoriya Jul 16, 2024
16913a8
Call onSeek after seek events
zoriya Nov 6, 2024
eb5cecf
Setup web demo
zoriya Nov 6, 2024
31dc24d
Review comments
zoriya Nov 6, 2024
c0d4050
Use weird deepEqual hack for source prop/setSource interaction
zoriya Nov 13, 2024
06c9243
Add constants in bare example
zoriya Nov 13, 2024
d0ceef7
Update styles
moskalakamil Nov 13, 2024
92a1d5e
Update expo example styles
moskalakamil Nov 13, 2024
d74d7df
add missing setSource type
moskalakamil Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/bun.lockb
Binary file not shown.
11 changes: 7 additions & 4 deletions docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Note: On Android, you must set the [reportBandwidth](#reportbandwidth) prop to e

### `onBuffer`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

Callback function that is called when the player buffers.

Expand Down Expand Up @@ -219,6 +219,9 @@ Payload: none

Callback function that is called when the media is loaded and ready to play.


NOTE: tracks (`audioTracks`, `textTracks` & `videoTracks`) are not available on the web.

Payload:

| Property | Type | Description |
Expand Down Expand Up @@ -292,7 +295,7 @@ Example:

### `onPlaybackStateChanged`

<PlatformsList types={['Android', 'iOS', 'visionOS']} />
<PlatformsList types={['Android', 'iOS', 'visionOS', 'web']} />

Callback function that is called when the playback state changes.

Expand Down Expand Up @@ -463,7 +466,7 @@ Payload: none

### `onSeek`

<PlatformsList types={['Android', 'iOS', 'Windows UWP']} />
<PlatformsList types={['Android', 'iOS', 'Windows UWP', 'web']} />

Callback function that is called when a seek completes.

Expand Down Expand Up @@ -604,7 +607,7 @@ Example:

### `onVolumeChange`

<PlatformsList types={['Android', 'iOS', 'visionOS']} />
<PlatformsList types={['Android', 'iOS', 'visionOS', 'web']} />

Callback function that is called when the volume of player changes.

Expand Down
23 changes: 15 additions & 8 deletions docs/pages/component/methods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This page shows the list of available methods

### `dismissFullscreenPlayer`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`dismissFullscreenPlayer(): Promise<void>`

Expand All @@ -17,15 +17,15 @@ Take the player out of fullscreen mode.

### `pause`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`pause(): Promise<void>`

Pause the video.

### `presentFullscreenPlayer`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`presentFullscreenPlayer(): Promise<void>`

Expand All @@ -40,7 +40,7 @@ On Android, this puts the navigation controls in fullscreen mode. It is not a co

### `resume`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`resume(): Promise<void>`

Expand Down Expand Up @@ -100,15 +100,15 @@ tolerance is the max distance in milliseconds from the seconds position that's a

### `setVolume`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`setVolume(value): Promise<void>`

This function will change the volume exactly like [volume](./props#volume) property. default value and range are the same then.

### `getCurrentPosition`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`getCurrentPosition(): Promise<number>`

Expand All @@ -127,7 +127,7 @@ Changing source with this function will overide source provided as props.

### `setFullScreen`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

`setFullScreen(fullscreen): Promise<void>`

Expand All @@ -137,6 +137,13 @@ On iOS, this displays the video in a fullscreen view controller with controls.

On Android, this puts the navigation controls in fullscreen mode. It is not a complete fullscreen implementation, so you will still need to apply a style that makes the width and height match your screen dimensions to get a fullscreen video.

### `nativeHtmlVideoRef`

<PlatformsList types={['web']} />

A ref to the underlying html video element. This can be used if you need to integrate a 3d party, web only video library (like hls.js, shaka, video.js...).


### Example Usage

```tsx
Expand Down Expand Up @@ -188,7 +195,7 @@ Possible values are:

### `isCodecSupported`

<PlatformsList types={['Android']} />
<PlatformsList types={['Android', 'web']} />

Indicates whether the provided codec is supported level supported by device.

Expand Down
12 changes: 7 additions & 5 deletions docs/pages/component/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ When playing an HLS live stream with a `EXT-X-PROGRAM-DATE-TIME` tag configured,

### `controls`

<PlatformsList types={['Android', 'iOS', 'visionOS']} />
<PlatformsList types={['Android', 'iOS', 'visionOS', 'web']} />

Determines whether to show player controls.

Expand Down Expand Up @@ -300,7 +300,7 @@ Whether this video view should be focusable with a non-touch input device, eg. r

### `fullscreen`

<PlatformsList types={['Android', 'iOS', 'visionOS']} />
<PlatformsList types={['Android', 'iOS', 'visionOS', 'web']} />

Controls whether the player enters fullscreen on play.
See [presentFullscreenPlayer](#presentfullscreenplayer) for details.
Expand All @@ -316,7 +316,7 @@ If a preferred [fullscreenOrientation](#fullscreenorientation) is set, causes th

### `fullscreenOrientation`

<PlatformsList types={['iOS', 'visionOS']} />
<PlatformsList types={['iOS', 'visionOS', 'web']} />

- **all (default)** -
- **landscape**
Expand Down Expand Up @@ -709,6 +709,8 @@ The docs for this prop are incomplete and will be updated as each option is inve

> ⚠️ on iOS, you file name must not contain spaces eg. `my video.mp4` will not work, use `my-video.mp4` instead

<PlatformsList types={['Android', 'iOS', 'visionOS', 'Windows UWP']} />

Example:

Pass directly the asset to play (deprecated)
Expand Down Expand Up @@ -820,7 +822,7 @@ Example:

#### Start playback at a specific point in time

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

Provide an optional `startPosition` for video. Value is in milliseconds. If the `cropStart` prop is applied, it will be applied from that point forward.
(If it is negative or undefined or null, it is ignored)
Expand Down Expand Up @@ -1048,7 +1050,7 @@ textTracks={[

### `showNotificationControls`

<PlatformsList types={['Android', 'iOS']} />
<PlatformsList types={['Android', 'iOS', 'web']} />

Controls whether to show media controls in the notification area.
For Android each Video component will have its own notification controls and for iOS only one notification control will be shown for the last Active Video component.
Expand Down
1 change: 1 addition & 0 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ It allows to stream video files (m3u, mpd, mp4, ...) inside your react native ap
- Exoplayer for android
- AVplayer for iOS, tvOS and visionOS
- Windows UWP for windows
- HTML5 for web
- Trick mode support
- Subtitles (embeded or side loaded)
- DRM support
Expand Down
9 changes: 9 additions & 0 deletions docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,12 @@ Select RCTVideo-tvOS
Run `pod install` in the `visionos` directory of your project

</details>

<details>
<summary>web</summary>

Nothing to do, everything should work out of the box.

Note that only basic video support is present, no hls/dash or ads/drm for now.

</details>
6 changes: 4 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This directory contains examples for `react-native-video` - this is a guide that

- **[`bare`](#bare)** - Main example ([react-native-test-app](https://github.com/microsoft/react-native-test-app) - bare react-native app) that you can run on: iOS, Android, Windows, visionOS

- **[`expo`](#expo)** - Expo example that you can run on: iOS, Android, tvOS, web (support coming soon)
- **[`expo`](#expo)** - Expo example that you can run on: iOS, Android, tvOS, web

### Updating Examples Content

Expand Down Expand Up @@ -135,7 +135,9 @@ cd examples/expo && yarn install
> Setup for android is not complete yet. Please use bare app for android testing.

- For Web:
Support for web is coming soon.
```bash
yarn web
```

If Metro Bundler is not running (or it did not start), you can start it by running:
```bash
Expand Down
8 changes: 8 additions & 0 deletions examples/bare/src/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ export const srcAllPlatformList = [
description: 'another bunny (can be saved)',
uri: 'https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4',
headers: {referer: 'www.github.com', 'User-Agent': 'react.native.video'},
metadata: {
title: 'Custom Title',
subtitle: 'Custom Subtitle',
artist: 'Custom Artist',
description: 'Custom Description',
imageUri:
'https://pbs.twimg.com/profile_images/1498641868397191170/6qW2XkuI_400x400.png',
},
},
{
description: 'sintel with subtitles',
Expand Down
5 changes: 3 additions & 2 deletions examples/bare/src/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {StyleSheet} from 'react-native';
import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -63,6 +63,7 @@ const styles = StyleSheet.create({
borderRadius: 4,
overflow: 'hidden',
paddingBottom: 10,
paddingTop: Platform.OS === 'web' ? 25 : 0,
},
rateControl: {
flex: 1,
Expand Down Expand Up @@ -146,7 +147,7 @@ const styles = StyleSheet.create({
},
picker: {
flex: 1,
color: 'white',
color: Platform.OS === 'web' ? 'black' : 'white',
flexDirection: 'row',
justifyContent: 'center',
width: 100,
Expand Down
4 changes: 3 additions & 1 deletion examples/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"update-src": "echo 'Updating src from ../bare/src' && rm -r ./src && cp -r ../bare/src ./src && echo 'Updated src from ../bare/src'"
},
"dependencies": {
"@expo/metro-runtime": "^3.2.3",
"@react-native-picker/picker": "2.8.1",
"expo": "~51.0.31",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "npm:react-native-tvos@~0.74.5-0"
"react-native": "npm:react-native-tvos@~0.74.5-0",
"react-native-web": "^0.19.13"
},
"devDependencies": {
"@babel/core": "^7.24.0",
Expand Down
8 changes: 8 additions & 0 deletions examples/expo/src/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ export const srcAllPlatformList = [
description: 'another bunny (can be saved)',
uri: 'https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4',
headers: {referer: 'www.github.com', 'User-Agent': 'react.native.video'},
metadata: {
title: 'Custom Title',
subtitle: 'Custom Subtitle',
artist: 'Custom Artist',
description: 'Custom Description',
imageUri:
'https://pbs.twimg.com/profile_images/1498641868397191170/6qW2XkuI_400x400.png',
},
},
{
description: 'sintel with subtitles',
Expand Down
5 changes: 3 additions & 2 deletions examples/expo/src/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {StyleSheet} from 'react-native';
import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -63,6 +63,7 @@ const styles = StyleSheet.create({
borderRadius: 4,
overflow: 'hidden',
paddingBottom: 10,
paddingTop: Platform.OS === 'web' ? 25 : 0,
},
rateControl: {
flex: 1,
Expand Down Expand Up @@ -146,7 +147,7 @@ const styles = StyleSheet.create({
},
picker: {
flex: 1,
color: 'white',
color: Platform.OS === 'web' ? 'black' : 'white',
flexDirection: 'row',
justifyContent: 'center',
width: 100,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.7.0",
"description": "A <Video /> element for react-native",
"main": "lib/index",
"source": "src/index",
"source": "src/index.ts",
"react-native": "src/index",
"license": "MIT",
"author": "Community Contributors",
Expand Down
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{pkgs ? import <nixpkgs> {}}:
KrzysztofMoch marked this conversation as resolved.
Show resolved Hide resolved
pkgs.mkShell {
packages = with pkgs; [
nodejs-18_x
nodePackages.yarn
bun
eslint_d
prettierd
jdk11
(jdt-language-server.override { jdk = jdk11; })
];
}

3 changes: 1 addition & 2 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import {
resolveAssetSourceForVideo,
} from './utils';
import NativeVideoManager from './specs/NativeVideoManager';
import type {VideoSaveData} from './specs/NativeVideoManager';
import {CmcdMode, ViewType} from './types';
import {ViewType, type VideoSaveData, CmcdMode} from './types';
import type {
OnLoadData,
OnTextTracksData,
Expand Down
Loading
Loading