How to use on X

The library can run in many environments, so it can be tricky to figure out how to set it up.

Here is a checklist. For more specific environments, keep reading below:

  • When requests are very restricted (like browser client-side). Configure a proxied fetcher.
  • When your requests come from the same device on which it will be streamed (not compatible with proxied fetcher). Set consistentIpForRequests: true.
  • To set a target. Consult Targets.

To make use of the examples below, check out the following pages:

NodeJs server

import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';

const providers = makeProviders({
  fetcher: makeStandardFetcher(fetch),
  target: chooseYourself, // check out https://movie-web.github.io/providers/essentials/targets
})

Browser client-side

Using the provider package client-side requires a hosted version of simple-proxy. Read more about proxy fetchers.

import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';

const proxyUrl = "https://your.proxy.workers.dev/";

const providers = makeProviders({
  fetcher: makeStandardFetcher(fetch),
  proxiedFetcher: makeSimpleProxyFetcher(proxyUrl, fetch),
  target: target.BROWSER,
})

React native

To use the library in a react native app, you would also need a couple of polyfills to polyfill crypto and base64.

  1. First install the polyfills:
npm install @react-native-anywhere/polyfill-base64 react-native-quick-crypto
  1. Add the polyfills to your app:
// Import in your entry file
import '@react-native-anywhere/polyfill-base64';

And follow the react-native-quick-crypto documentation to set up the crypto polyfill.

  1. Then you can use the library like this:
import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';

const providers = makeProviders({
  fetcher: makeStandardFetcher(fetch),
  target: target.NATIVE,
  consistentIpForRequests: true,
})