From 0389ad1a9c130caf9738c6d40f755da30f2851db Mon Sep 17 00:00:00 2001 From: Spencer Spenst Date: Tue, 9 Jan 2024 17:50:57 -0800 Subject: [PATCH] wip using base domain for all media accesses --- components/formatted/formattedLevelLink.tsx | 2 ++ components/profile/profileAvatar.tsx | 7 +++++-- contexts/musicContext.tsx | 12 ++++++++---- next.config.js | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/formatted/formattedLevelLink.tsx b/components/formatted/formattedLevelLink.tsx index ec5d3f753..0742b75b8 100644 --- a/components/formatted/formattedLevelLink.tsx +++ b/components/formatted/formattedLevelLink.tsx @@ -35,6 +35,8 @@ export default function FormattedLevelLink({ id, gameId, level, onClick }: Enric className='max-w-full' height={Dimensions.LevelCanvasHeight / 3} src={'/api/level/image/' + level._id + '.png'} + // TODO: localhost origin in renderToStaticMarkup doesn't work, should probably not be using renderToStaticMarkup if possible + // src={getUrl(GameId.THINKY, `/api/level/image/${level._id}.png`)} width={Dimensions.LevelCanvasWidth / 3} /> )} diff --git a/components/profile/profileAvatar.tsx b/components/profile/profileAvatar.tsx index b19ddac59..5c199251e 100644 --- a/components/profile/profileAvatar.tsx +++ b/components/profile/profileAvatar.tsx @@ -1,3 +1,5 @@ +import { GameId } from '@root/constants/GameId'; +import useUrl from '@root/hooks/useUrl'; import classNames from 'classnames'; import React, { useContext } from 'react'; import Dimensions from '../../constants/dimensions'; @@ -12,16 +14,17 @@ interface ProfileAvatarProps { } export default function ProfileAvatar({ hideStatusCircle, size = Dimensions.AvatarSize, user }: ProfileAvatarProps) { + const borderWidth = Math.round(size / 40) || 1; + const getUrl = useUrl(); const { multiplayerSocket } = useContext(AppContext); const connectedUser = multiplayerSocket.connectedPlayers.find(u => u._id === user._id); - const borderWidth = Math.round(size / 40) || 1; return (
(); const [volume, setVolume] = useState(0.66); + const getUrl = useUrl(); + useEffect(() => { const audio = new Audio(); const canPlayOgg = audio.canPlayType('audio/ogg') !== ''; @@ -260,9 +264,9 @@ export default function MusicContextProvider({ children }: { children: React.Rea }; if (isDynamicSupported) { - const ambient = new Audio(song.ambient); - const original = new Audio(song.original); - const thud = new Audio(song.thud); + const ambient = new Audio(getUrl(GameId.THINKY, song.ambient)); + const original = new Audio(getUrl(GameId.THINKY, song.original)); + const thud = new Audio(getUrl(GameId.THINKY, song.thud)); ambient.preload = 'auto'; original.preload = 'auto'; @@ -351,7 +355,7 @@ export default function MusicContextProvider({ children }: { children: React.Rea return newSongMetadata; }); }); - }, [isDynamicSupported, isHot, isPlaying, volume]); + }, [getUrl, isDynamicSupported, isHot, isPlaying, volume]); const seek = useCallback((offset: number, playOriginal = isHot) => { // add songs.length to account for negative offset diff --git a/next.config.js b/next.config.js index dad7df1db..9827a055f 100644 --- a/next.config.js +++ b/next.config.js @@ -36,6 +36,11 @@ module.exports = { hostname: 'i.imgur.com', pathname: '**', }, + // { + // protocol: 'http', + // hostname: 'localhost', + // pathname: '**', + // } ], }, eslint: {