From 8cd2ce3f4523f53b89bea08832a91a97f6edaeb2 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sat, 10 Sep 2022 18:22:36 -0500 Subject: [PATCH] refactor: move trackerUrls to its own file --- src/components/Room/Room.tsx | 5 ++--- src/config/trackerUrls.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/config/trackerUrls.ts diff --git a/src/components/Room/Room.tsx b/src/components/Room/Room.tsx index f48d4f7..3a3d5bb 100644 --- a/src/components/Room/Room.tsx +++ b/src/components/Room/Room.tsx @@ -4,6 +4,7 @@ import Box from '@mui/material/Box' import Divider from '@mui/material/Divider' import { rtcConfig } from 'config/rtcConfig' +import { trackerUrls } from 'config/trackerUrls' import { ShellContext } from 'contexts/ShellContext' import { usePeerRoom, usePeerRoomAction } from 'hooks/usePeerRoom' import { PeerActions } from 'models/network' @@ -34,9 +35,7 @@ export function Room({ const peerRoom = usePeerRoom( { appId, - trackerUrls: process.env.REACT_APP_TRACKER_URL - ? [process.env.REACT_APP_TRACKER_URL] - : undefined, + trackerUrls, rtcConfig, }, roomId diff --git a/src/config/trackerUrls.ts b/src/config/trackerUrls.ts new file mode 100644 index 0000000..fd42f27 --- /dev/null +++ b/src/config/trackerUrls.ts @@ -0,0 +1,25 @@ +let trackerUrls: string[] | undefined = [ + // If you would like to host your own Chitchatter instance with alternative + // WebTorrent trackers to connect peers, add them to this array. This array + // gets provided to Trystero as the `trackerUrls` configuration option: + // https://github.com/dmotz/trystero#joinroomconfig-namespace + // + // See the default tracker list for examples of what to use: + // https://github.com/dmotz/trystero/blob/694f49974974cc9df8b621db09215d6df10fad09/src/torrent.js#L27-L33 +] + +// If a tracker URL has been provided via the REACT_APP_TRACKER_URL environment +// variable, prioritize using it. This is mainly relevant for local development +// when using the `npm run dev` script. If you are hosting your own Chitchatter +// instance, consider populating the trackerUrls above instead. +if (process.env.REACT_APP_TRACKER_URL) { + trackerUrls.unshift(process.env.REACT_APP_TRACKER_URL) +} + +// If no tracker URL overrides have been provided, set trackerUrls to undefined +// to allow Trystero to use the default list (linked above). +if (!trackerUrls.length) { + trackerUrls = undefined +} + +export { trackerUrls }