Skip to content

Commit

Permalink
fix(multiplayer): use trystero/torrent strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Dec 17, 2024
1 parent 06db008 commit b7c5d16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/components/Farmhand/Farmhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft.js'
import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight.js'
import Tooltip from '@mui/material/Tooltip/index.js'
import MobileStepper from '@mui/material/MobileStepper/index.js'
// NOTE: This path is aliased to tryster/torrent in vite.config.js. The actual
// path can't be used here because it breaks either Vite or TypeScript.
import { joinRoom } from 'trystero'
import { SnackbarProvider } from 'notistack'
import debounce from 'lodash.debounce'
Expand Down Expand Up @@ -118,7 +120,7 @@ import {
REQUESTED_COW_TRADE_UNAVAILABLE,
SERVER_ERROR,
} from '../../strings.js'
import { endpoints, features, rtcConfig, trackerUrls } from '../../config.js'
import { endpoints, features, rtcConfig, relayUrls } from '../../config.js'

import { scarecrow } from '../../data/items.js'

Expand Down Expand Up @@ -938,15 +940,15 @@ export default class Farmhand extends FarmhandReducers {

this.scheduleHeartbeat()

const trackerRedundancy = 4
const relayRedundancy = 4

this.setState({
activePlayers: 1,
peerRoom: joinRoom(
{
appId: import.meta.env?.VITE_NAME,
trackerUrls,
trackerRedundancy,
relayUrls,
relayRedundancy,
rtcConfig,
},
room
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ export const rtcConfig = {
],
}

export const trackerUrls = import.meta.env?.VITE_TRACKER_URL
export const relayUrls = import.meta.env?.VITE_TRACKER_URL
? [import.meta.env?.VITE_TRACKER_URL]
: undefined
4 changes: 4 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const viteConfig = defineConfig({
],
resolve: {
alias: [
{
find: /^trystero$/,
replacement: `trystero/torrent`,
},
{
// NOTE: This is required for the SCSS modules
find: /^~(.*)$/,
Expand Down

0 comments on commit b7c5d16

Please sign in to comment.