-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OBS integration and song request preview settings
- Loading branch information
Showing
28 changed files
with
787 additions
and
200 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { FC, useMemo } from 'react'; | ||
import useSWR from 'swr'; | ||
import * as styles from '../scss/modules/BeatSaverMap.module.scss'; | ||
import { SongInfo } from './beat-saber/SongInfo'; | ||
import { validateBeatSaverMapData } from './validators/validate-beat-saver-map-data'; | ||
import classNames from 'classnames'; | ||
import { mapDifficulty } from './utils/mappers'; | ||
|
||
export interface BeatSaverMapProps { | ||
mapId: string; | ||
text?: string; | ||
inChat?: boolean; | ||
} | ||
|
||
export const BeatSaverMap: FC<BeatSaverMapProps> = ({ mapId, inChat }) => { | ||
const { | ||
data, | ||
isLoading | ||
} = useSWR(() => mapId ? `bsr-map-${mapId}` : null, () => fetch(`https://api.beatsaver.com/maps/id/${mapId}`).then(r => r.json()).then(data => validateBeatSaverMapData(data)), { | ||
revalidateOnFocus: false, | ||
refreshWhenHidden: false, | ||
refreshWhenOffline: false, | ||
}); | ||
const versions = data?.versions; | ||
const publishedVersion = useMemo(() => versions?.slice().sort((a, | ||
b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).find(v => v.state === 'Published'), [versions]); | ||
return <div className={classNames(styles['beat-saver-map'], { [styles['in-chat']]: inChat })}> | ||
<div className={styles['beat-saver-song-info']}> | ||
<SongInfo | ||
name={data?.metadata?.songName ?? (isLoading ? '' : 'Could not retrieve song information')} | ||
author={isLoading ? 'Loading map data…' : data?.metadata?.songAuthorName} | ||
duration={data?.metadata?.duration} | ||
mapper={data?.metadata?.levelAuthorName} | ||
subName={data?.metadata?.songSubName} | ||
url={publishedVersion?.coverURL} | ||
bsr={data?.id} | ||
difficulty={publishedVersion?.diffs?.filter(diff => diff.characteristic === 'Standard').map(diff => mapDifficulty(diff.difficulty)).join(', ')} | ||
/> | ||
</div> | ||
</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import { isInBrowserSource } from '../utils/is-in-browser-source'; | ||
|
||
export const useObs = () => { | ||
const inBrowserSource = useMemo(() => isInBrowserSource(), []); | ||
const [controlLevel, setControlLevel] = useState<OBSControlLevel>(0); | ||
const [streaming, setStreaming] = useState<OBSStatus['streaming']>(false); | ||
const [currentSceneName, setCurrentSceneName] = useState<OBSSceneInfo['name']>(''); | ||
const [allSceneNames, setAllSceneNames] = useState<OBSSceneInfo['name'][]>([]); | ||
|
||
const updateScenes = useCallback(() => { | ||
window.obsstudio.getScenes((scenes) => { | ||
setAllSceneNames(scenes); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!inBrowserSource) return; | ||
|
||
window.obsstudio.getControlLevel((level) => { | ||
setControlLevel(level); | ||
}); | ||
window.obsstudio.getStatus((status) => { | ||
setStreaming(status !== null && status.streaming); | ||
}); | ||
updateScenes(); | ||
const listeners = { | ||
obsSceneChanged(event: CustomEvent<OBSSceneInfo>) { | ||
setCurrentSceneName(event.detail.name); | ||
updateScenes(); | ||
}, | ||
obsStreamingStarting() { | ||
setStreaming(true); | ||
}, | ||
obsStreamingStopping() { | ||
setStreaming(false); | ||
}, | ||
} satisfies Partial<{ [k in keyof OBSStudioEventMap]: (event: OBSStudioEventMap[k]) => void }>; | ||
|
||
Object.entries(listeners).forEach(([event, handler]) => { | ||
window.addEventListener(event as never, handler as never); | ||
}); | ||
return () => { | ||
Object.entries(listeners).forEach(([event, handler]) => { | ||
window.removeEventListener(event as never, handler as never); | ||
}); | ||
}; | ||
}, [inBrowserSource, updateScenes]); | ||
|
||
return { | ||
inBrowserSource, | ||
controlLevel, | ||
streaming, | ||
currentSceneName, | ||
allSceneNames | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface BeatSaverMapMetadata { | ||
duration: number; | ||
songName: string; | ||
songSubName: string; | ||
songAuthorName: string; | ||
levelAuthorName: string; | ||
} | ||
|
||
export interface BeatSaverMapVersion { | ||
state: string; | ||
diffs: BeatSaverMapVersionDifficulty[]; | ||
createdAt: string; | ||
coverURL?: string; | ||
} | ||
|
||
export interface BeatSaverMapVersionDifficulty { | ||
characteristic: string; | ||
difficulty: string; | ||
} | ||
|
||
export interface BeatSaverMapData { | ||
id: string; | ||
metadata?: BeatSaverMapMetadata; | ||
versions?: BeatSaverMapVersion[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.