refactor: move trackerUrls to its own file

This commit is contained in:
Jeremy Kahn 2022-09-10 18:22:36 -05:00
parent d277820961
commit 8cd2ce3f45
2 changed files with 27 additions and 3 deletions

View File

@ -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

25
src/config/trackerUrls.ts Normal file
View File

@ -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 }