Skip to content

Commit 9aded62

Browse files
jspizziriSpadarShutdcvz
authored
feat(web): add a web implementation (#1886)
* chore(example): update example to include a web version * feat(web): add a web implementation * feat(web): prevent exceptions during SSR due to inability to import shaka player * fix(example): update tsconfig extension path * chore(example): update the web build to work with the upgraded example code * chore(example): update react-native-windows dependency to prevent runtime error * fix(web): have setupPlayer throw an exception on duplicate calls * fix(web): don't add track to queue on skip * fix(web): silence eslint errors * fix(web): fix skip method * fix(web): fix the HLS stream example for web by retranscoding the whip.mp3 * fix(web): fix various issues causing failure states due to player errors * refactor(web): refactor _most_ state changes into generic method * chore(example): update appname for example web Co-authored-by: David Chavez <[email protected]> * revert(web): move shaka-player to an optional peer dependency and document its installation * chore(src, example): clean up linting, formatting, and type errors --------- Co-authored-by: Pavel Shut <[email protected]> Co-authored-by: David Chavez <[email protected]>
1 parent ef9fb00 commit 9aded62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+8720
-3050
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root = true
22

3-
[{src,scripts}/**.{ts,json,js}]
3+
[{src,web,scripts}/**.{ts,json,js}]
44
end_of_line = lf
55
charset = utf-8
66
trim_trailing_whitespace = true

README.md

+28
-189 KB
Binary file not shown.
-186 KB
Binary file not shown.
-187 KB
Binary file not shown.
-186 KB
Binary file not shown.
-187 KB
Binary file not shown.
-188 KB
Binary file not shown.
-189 KB
Binary file not shown.
-186 KB
Binary file not shown.
-187 KB
Binary file not shown.
-184 KB
Binary file not shown.
-185 KB
Binary file not shown.
-184 KB
Binary file not shown.
-187 KB
Binary file not shown.
-184 KB
Binary file not shown.
-185 KB
Binary file not shown.
-189 KB
Binary file not shown.
-85.6 KB
Binary file not shown.
-183 KB
Binary file not shown.
-185 KB
Binary file not shown.
-185 KB
Binary file not shown.
-186 KB
Binary file not shown.
-182 KB
Binary file not shown.
-179 KB
Binary file not shown.
-186 KB
Binary file not shown.
199 KB
Binary file not shown.
198 KB
Binary file not shown.
201 KB
Binary file not shown.
205 KB
Binary file not shown.
205 KB
Binary file not shown.
198 KB
Binary file not shown.
199 KB
Binary file not shown.
204 KB
Binary file not shown.
206 KB
Binary file not shown.
199 KB
Binary file not shown.
198 KB
Binary file not shown.
200 KB
Binary file not shown.
203 KB
Binary file not shown.
201 KB
Binary file not shown.
203 KB
Binary file not shown.
198 KB
Binary file not shown.
82.4 KB
Binary file not shown.

docs/static/example/hls/whip/playlist.m3u8

+35-49
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,39 @@
22
#EXT-X-VERSION:3
33
#EXT-X-MEDIA-SEQUENCE:0
44
#EXT-X-ALLOW-CACHE:YES
5-
#EXT-X-TARGETDURATION:8
6-
#EXTINF:7.012433,
7-
file0.m4a
8-
#EXTINF:6.989200,
9-
file1.m4a
10-
#EXTINF:7.012433,
11-
file2.m4a
12-
#EXTINF:6.989200,
13-
file3.m4a
14-
#EXTINF:7.012433,
15-
file4.m4a
16-
#EXTINF:6.989211,
17-
file5.m4a
18-
#EXTINF:7.012433,
19-
file6.m4a
20-
#EXTINF:6.989211,
21-
file7.m4a
22-
#EXTINF:7.012433,
23-
file8.m4a
24-
#EXTINF:6.989211,
25-
file9.m4a
26-
#EXTINF:7.012422,
27-
file10.m4a
28-
#EXTINF:6.989211,
29-
file11.m4a
30-
#EXTINF:7.012422,
31-
file12.m4a
32-
#EXTINF:6.989211,
33-
file13.m4a
34-
#EXTINF:6.989211,
35-
file14.m4a
36-
#EXTINF:7.012433,
37-
file15.m4a
38-
#EXTINF:6.989200,
39-
file16.m4a
40-
#EXTINF:7.012433,
41-
file17.m4a
42-
#EXTINF:6.989200,
43-
file18.m4a
44-
#EXTINF:7.012433,
45-
file19.m4a
46-
#EXTINF:6.989200,
47-
file20.m4a
48-
#EXTINF:7.012433,
49-
file21.m4a
50-
#EXTINF:6.989200,
51-
file22.m4a
52-
#EXTINF:3.300133,
53-
file23.m4a
5+
#EXT-X-TARGETDURATION:11
6+
#EXTINF:10.007800,
7+
playlist-00000.ts
8+
#EXTINF:10.007800,
9+
playlist-00001.ts
10+
#EXTINF:9.984589,
11+
playlist-00002.ts
12+
#EXTINF:10.007800,
13+
playlist-00003.ts
14+
#EXTINF:10.007800,
15+
playlist-00004.ts
16+
#EXTINF:9.984578,
17+
playlist-00005.ts
18+
#EXTINF:10.007800,
19+
playlist-00006.ts
20+
#EXTINF:10.007800,
21+
playlist-00007.ts
22+
#EXTINF:9.984578,
23+
playlist-00008.ts
24+
#EXTINF:10.007800,
25+
playlist-00009.ts
26+
#EXTINF:10.007800,
27+
playlist-00010.ts
28+
#EXTINF:9.984589,
29+
playlist-00011.ts
30+
#EXTINF:10.007800,
31+
playlist-00012.ts
32+
#EXTINF:10.007800,
33+
playlist-00013.ts
34+
#EXTINF:9.984578,
35+
playlist-00014.ts
36+
#EXTINF:10.007800,
37+
playlist-00015.ts
38+
#EXTINF:4.298589,
39+
playlist-00016.ts
5440
#EXT-X-ENDLIST

example/craco.config.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const path = require('path');
2+
const {CracoAliasPlugin} = require('react-app-alias-ex');
3+
const babelInclude = require('@dealmore/craco-plugin-babel-include');
4+
const webpack = require('webpack');
5+
const { loaderByName, addBeforeLoader } = require('@craco/craco');
6+
7+
8+
module.exports = {
9+
webpack: {
10+
alias: {
11+
'react-native$': 'react-native-web',
12+
'react-native-track-player': path.resolve(__dirname, '../'),
13+
// make sure we don't include multiple versions of react
14+
'react': path.resolve(__dirname, './node_modules/react'),
15+
},
16+
plugins: {
17+
add: [
18+
new webpack.EnvironmentPlugin({ JEST_WORKER_ID: null }),
19+
new webpack.DefinePlugin({
20+
process: { env: {} },
21+
__DEV__: true,
22+
})
23+
],
24+
},
25+
configure: (config) => {
26+
// BEGIN: resolve react-native-vector-icons font files
27+
config.resolve.extensions.push('.ttf');
28+
addBeforeLoader(
29+
config,
30+
loaderByName('url-loader'),
31+
{
32+
test: /\.ttf$/,
33+
loader: 'url-loader', // or directly file-loader
34+
include: path.resolve(__dirname, 'node_modules/react-native-vector-icons'),
35+
},
36+
);
37+
// END: resolve react-native-vector-icons font files
38+
39+
return config;
40+
},
41+
},
42+
babel: {
43+
presets: [
44+
'@babel/preset-react',
45+
'@babel/preset-typescript',
46+
],
47+
plugins: [
48+
'@babel/plugin-proposal-export-namespace-from',
49+
'react-native-reanimated/plugin',
50+
],
51+
},
52+
plugins: [
53+
{
54+
plugin: CracoAliasPlugin,
55+
options: {}
56+
},
57+
{
58+
plugin: babelInclude,
59+
options: {
60+
include: [
61+
path.resolve(__dirname, '../'),
62+
],
63+
},
64+
},
65+
],
66+
};

example/package.json

+28-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"ios": "react-native run-ios",
1313
"ios:sim": "react-native run-ios --simulator=\"iPhone\"",
1414
"ios:ide": "open ios/*.xcworkspace/",
15+
"web:start": "craco start",
16+
"web:build": "craco build",
1517
"windows": "react-native run-windows",
1618
"start": "react-native start",
1719
"test": "jest",
@@ -25,23 +27,33 @@
2527
"@gorhom/bottom-sheet": "^4",
2628
"@react-native-community/slider": "^4.4.2",
2729
"@react-native-segmented-control/segmented-control": "^2.4.2",
30+
"mux.js": "^7.0.0",
2831
"react": "18.2.0",
32+
"react-dom": "^18.0.2",
2933
"react-native": "0.71.12",
30-
"react-native-gesture-handler": "^2.12.1",
31-
"react-native-reanimated": "^3.4.1",
34+
"react-native-gesture-handler": "2.12.1",
35+
"react-native-reanimated": "3.3.0",
3236
"react-native-track-player": "link:../",
3337
"react-native-vector-icons": "^10.0.0",
34-
"react-native-windows": "^0.65.0-0"
38+
"react-native-web": "^0.18.10",
39+
"react-native-windows": "0.71.12",
40+
"react-scripts": "5.0.1",
41+
"shaka-player": "^4.7.9"
3542
},
3643
"devDependencies": {
3744
"@babel/core": "^7.20.0",
45+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
3846
"@babel/preset-env": "^7.20.0",
3947
"@babel/runtime": "^7.20.0",
48+
"@craco/craco": "^7.0.0",
49+
"@dealmore/craco-plugin-babel-include": "^1.0.0",
4050
"@react-native-community/eslint-config": "^3.2.0",
4151
"@tsconfig/react-native": "^2.0.2",
4252
"@types/jest": "^29.2.1",
4353
"@types/react": "^18.0.24",
54+
"@types/react-dom": "^18.2.0",
4455
"@types/react-native": "^0.64.5",
56+
"@types/react-native-vector-icons": "^6.4.14",
4557
"@types/react-test-renderer": "^18.0.0",
4658
"@typescript-eslint/eslint-plugin": "^5.36.0",
4759
"@typescript-eslint/parser": "^5.36.0",
@@ -53,6 +65,7 @@
5365
"jest": "^29.2.1",
5466
"metro-react-native-babel-preset": "0.73.9",
5567
"prettier": "^2.4.1",
68+
"react-app-alias-ex": "^2.1.0",
5669
"react-native-clean-project": "^4.0.1",
5770
"react-test-renderer": "18.2.0",
5871
"rimraf": "^3.0.2",
@@ -74,5 +87,17 @@
7487
"dependencies": {
7588
"classic.yarnpkg.com": "^1"
7689
}
90+
},
91+
"browserslist": {
92+
"production": [
93+
">0.2%",
94+
"not dead",
95+
"not op_mini all"
96+
],
97+
"development": [
98+
"last 1 chrome version",
99+
"last 1 firefox version",
100+
"last 1 safari version"
101+
]
77102
}
78103
}

example/public/icon.png

5.51 KB

example/public/index.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
8+
/>
9+
<link rel="icon" type="image/png" href="/icon.png">
10+
<title>RNTP Example App</title>
11+
</head>
12+
13+
<body>
14+
<noscript>You need to enable JavaScript to run this app.</noscript>
15+
<div id="root"></div>
16+
</body>
17+
</html>

example/src/App.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
StatusBar,
1313
StyleSheet,
1414
View,
15+
Platform,
1516
} from 'react-native';
1617
import TrackPlayer, { useActiveTrack } from 'react-native-track-player';
1718

@@ -124,6 +125,7 @@ const styles = StyleSheet.create({
124125
backgroundColor: '#212121',
125126
alignItems: 'center',
126127
justifyContent: 'center',
128+
minHeight: Platform.OS === 'web' ? '100vh' : '100%',
127129
},
128130
contentContainer: {
129131
flex: 1,

example/src/components/ActionSheet.tsx

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import { BottomSheetScrollView } from '@gorhom/bottom-sheet';
3-
import { StyleSheet } from 'react-native';
2+
import { ScrollView } from 'react-native';
43
import { Spacer } from './Spacer';
54
import { Button } from './Button';
65
import TrackPlayer from 'react-native-track-player';
@@ -31,7 +30,7 @@ const onReset = async () => {
3130

3231
export const ActionSheet: React.FC = () => {
3332
return (
34-
<BottomSheetScrollView contentContainerStyle={styles.contentContainer}>
33+
<ScrollView>
3534
<Spacer />
3635
<Button
3736
title={'Update Notification Metadata Randomly'}
@@ -44,19 +43,6 @@ export const ActionSheet: React.FC = () => {
4443
type={'primary'}
4544
/>
4645
<Button title={'Reset'} onPress={onReset} type={'primary'} />
47-
</BottomSheetScrollView>
46+
</ScrollView>
4847
);
4948
};
50-
51-
const styles = StyleSheet.create({
52-
contentContainer: {
53-
flex: 1,
54-
marginTop: '4%',
55-
marginHorizontal: 16,
56-
},
57-
optionRowLabel: {
58-
color: 'white',
59-
fontSize: 20,
60-
fontWeight: '600',
61-
},
62-
});

example/src/components/OptionSheet.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState } from 'react';
2-
import { Platform, StyleSheet, Text, View } from 'react-native';
3-
import { BottomSheetScrollView } from '@gorhom/bottom-sheet';
2+
import { Platform, StyleSheet, ScrollView, Text, View } from 'react-native';
43
import SegmentedControl from '@react-native-segmented-control/segmented-control';
54
import TrackPlayer, {
65
AppKilledPlaybackBehavior,
@@ -34,7 +33,7 @@ export const OptionSheet: React.FC = () => {
3433
useState(audioServiceBehaviourToIndex(DefaultAudioServiceBehaviour));
3534

3635
return (
37-
<BottomSheetScrollView contentContainerStyle={styles.contentContainer}>
36+
<ScrollView>
3837
<OptionStack vertical={true}>
3938
<Text style={styles.optionRowLabel}>Repeat Mode</Text>
4039
<Spacer />
@@ -94,7 +93,7 @@ export const OptionSheet: React.FC = () => {
9493
/>
9594
</OptionStack>
9695
)}
97-
</BottomSheetScrollView>
96+
</ScrollView>
9897
);
9998
};
10099

example/src/components/Progress.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const Progress: React.FC<{ live?: boolean }> = ({ live }) => {
1212

1313
return (
1414
<View style={styles.container}>
15-
{live ? (
15+
{live || duration === Infinity ? (
1616
<Text style={styles.liveText}>Live Stream</Text>
1717
) : (
18-
<>
18+
<View>
1919
<Slider
2020
style={{ ...styles.slider, width: progressBarWidth }}
2121
value={position}
@@ -33,7 +33,7 @@ export const Progress: React.FC<{ live?: boolean }> = ({ live }) => {
3333
{formatSeconds(Math.max(0, duration - position))}
3434
</Text>
3535
</View>
36-
</>
36+
</View>
3737
)}
3838
</View>
3939
);

0 commit comments

Comments
 (0)