"use client"; import Container from "@/components/Container"; import Spinner from "@/components/Spinner"; import PlayerStats from "@/components/overlay/PlayerStats"; import ScoreStats from "@/components/overlay/ScoreStats"; import SongInfo from "@/components/overlay/SongInfo"; import { Card, CardDescription, CardTitle } from "@/components/ui/card"; import { HttpSiraStatus } from "@/overlay/httpSiraStatus"; import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; import { ScoreSaberAPI } from "@/utils/scoresaber/api"; import { Component } from "react"; const UPDATE_INTERVAL = 1000 * 60 * 5; // 5 minutes interface OverlayProps {} interface OverlayState { mounted: boolean; player: ScoresaberPlayer | undefined; settings: any | undefined; } export default class Overlay extends Component { constructor(props: OverlayProps) { super(props); this.state = { mounted: false, player: undefined, settings: undefined, }; } updatePlayer = async (playerId: string) => { console.log(`Updating player stats for ${playerId}`); const player = await ScoreSaberAPI.fetchPlayerData(playerId); if (!player) { return; } this.setState({ player }); }; componentDidMount() { if (this.state.mounted) { return; } this.setState({ mounted: true }); if (!this.state.mounted) { HttpSiraStatus.connectWebSocket(); } const url = new URL(window.location.href); const searchParams = url.searchParams; const data = searchParams.get("data"); if (!data) { return; } const settings = JSON.parse(data); this.setState({ settings: settings }); if (settings.settings.showPlayerStats) { this.updatePlayer(settings.playerId); setInterval(() => { this.updatePlayer(settings.playerId); }, UPDATE_INTERVAL); } } render() { const { player } = this.state; if (!this.state.mounted || !player) { return (

Loading player data

); } if (!this.state.settings) { return (
Overlay

This page is meant to be used as an overlay for streaming.

To generate an overlay, go to the builder{" "} here .

); } return (
{this.state.settings.settings.showPlayerStats && ( )} {this.state.settings.settings.showScoreStats && }
{this.state.settings.settings.showSongInfo && (
)}
); } }