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

fix(web): fix issues with certain bundlers only containing default #2299

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions docs/docs/basics/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ iOS requires a few extra steps that are _not_ required for Android/Web.

### Enable Swift Modules

Because the iOS module uses Swift, if the user is using a standard react-native application they'll need to add support for Swift in the project. This can be easily by adding a swift file to the Xcode project -- could be called `dummy.swift` and saying yes when prompted if you'd like to generate a bridging header.
Because the iOS module uses Swift, if the user is using a standard react-native
application they'll need to add support for Swift in the project. This can be
easily by adding a swift file to the Xcode project -- could be called
`dummy.swift` and saying yes when prompted if you'd like to generate a bridging
header.

![Importing Swift](https://i.imgur.com/CBqBcWs.png)

Expand Down Expand Up @@ -97,8 +101,10 @@ if you're using HLS streams with MPEG2-TS content.

## Expo

You can now use React Native Track Player with Expo.
You can now use React Native Track Player with Expo.

Please be aware that while many people are using React Native Track Player with Expo successfully, the current maintainers of this project do not use Expo and their ability to resolve issues involving Expo is limited.
Please be aware that while many people are using React Native Track Player with
Expo successfully, the current maintainers of this project do not use Expo and
their ability to resolve issues involving Expo is limited.

For more information, see [Developing with Expo](../guides/with-expo.md).
56 changes: 46 additions & 10 deletions docs/docs/guides/with-expo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,73 @@ sidebar_position: 98

Expo is a popular development platform in the react-native ecosystem.

Please be aware that while many people are using React Native Track Player with Expo successfully, the current maintainers of this project do not use Expo and their ability to resolve issues involving Expo is limited.

Please be aware that while many people are using React Native Track Player with
Expo successfully, the current maintainers of this project do not use Expo and
their ability to resolve issues involving Expo is limited.

## Development Build

A [Dev Client](https://docs.expo.dev/more/glossary-of-terms/#dev-clients) is required in order to use this package (Expo Go is not supported).
A [Dev Client](https://docs.expo.dev/more/glossary-of-terms/#dev-clients) is
required in order to use this package (Expo Go is not supported).

To get started, create a [development build](https://docs.expo.dev/clients/getting-started/) for your Expo app and then install React Native Track Player.
To get started, create a [development build](https://docs.expo.dev/clients/getting-started/)
for your Expo app and then install React Native Track Player.


## Custom Entry Point

In order to configure the Playback Service within the [entry point](https://docs.expo.dev/more/glossary-of-terms/#entry-point), you will need to [create a custom entry point](https://docs.expo.dev/guides/monorepos/#change-default-entrypoint) and adjust the `package.json` configuration.
In order to configure the Playback Service within the [entry point](https://docs.expo.dev/more/glossary-of-terms/#entry-point),
you will need to [create a custom entry point](https://docs.expo.dev/guides/monorepos/#change-default-entrypoint)
and adjust the `package.json` configuration.

By default, Expo points to an entry point in the `node_modules` folder. The path for this is configured in the `"main"` field of `package.json`. To create a new entry point:
By default, Expo points to an entry point in the `node_modules` folder. The path
for this is configured in the `"main"` field of `package.json`. To create a new
entry point:

1. Copy the default one

```
cp node_modules/expo/AppEntry.js AppEntry.js
cp node_modules/expo/AppEntry.js AppEntry.js
```

2. Update the `"main"` field of `package.json` to reference the new file e.g. `"AppEntry.js"`
3. Edit the new file to have it import your app code, and configure the Playback Service.


## Web

Expo web [does not currently support dynamic imports](https://github.com/doublesymmetry/react-native-track-player/pull/2299#issuecomment-2462566794)
which are leveraged in the web package to support SSR. If you'd like to use the
web version via Expo the recommendation is to:

### 1. Install `@expo/metro-runtime`

<Tabs groupId="pkg">
<TabItem value="npm" label="NPM" default>

npm install --save @expo/metro-runtime

</TabItem>
<TabItem value="yarn" label="Yarn">

yarn add @expo/metro-runtime

</TabItem>
</Tabs>

### 2. Import `@expo/metro-runtime` in your App root

```tsx
// App.tsx
import '@expo/metro-runtime';
...
```

## Streaming HTTP

On newer versions of Android, HTTP streaming is disallowed by default (HTTPS is OK). However, it is only disallowed in production builds which can make this issue hard to diagnose.
On newer versions of Android, HTTP streaming is disallowed by default (HTTPS is
OK). However, it is only disallowed in production builds which can make this
issue hard to diagnose.

To allow HTTP, you must first install the [`expo-build-properties` package](https://docs.expo.dev/versions/latest/sdk/build-properties).

Expand Down Expand Up @@ -66,5 +104,3 @@ Here is the configuration required for audio playback in background:

- [iOS: Enable audio playback in background via your app.json](https://docs.expo.dev/versions/latest/sdk/audio/#playing-or-recording-audio-in-background)
- [Android: Stop playback when the app is closed](../basics/background-mode.md/#android)


2 changes: 1 addition & 1 deletion web/TrackPlayer/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Player {
}

// @ts-ignore
const shaka = await import('shaka-player/dist/shaka-player.ui');
const shaka = (await import('shaka-player/dist/shaka-player.ui')).default;
// Install built-in polyfills to patch browser incompatibilities.
shaka.polyfill.installAll();
// Check to see if the browser supports the basic APIs Shaka needs.
Expand Down