add CurrentSongTime support from HttpSiraStatus

This commit is contained in:
Sky Z 2022-04-02 01:32:51 -04:00
parent 18098707d1
commit c1088361a2

@ -50,14 +50,33 @@ export default class Home extends Component {
} }
// I'd love if HTTP Status just gave this data lmao // I'd love if HTTP Status just gave this data lmao
// HttpSiraStatus(https://github.com/denpadokei/HttpSiraStatus) does give this data.
isCurrentSongTimeProvided = false;
// we don't need to reset this to false because it is highly unlikely for a player to swap mods within a browser session
setupTimer() { setupTimer() {
setInterval(() => { setInterval(() => {
if (this.isCurrentSongTimeProvided) {
return
}
if (!this.state.paused && this.state.beatSaverData !== undefined) { if (!this.state.paused && this.state.beatSaverData !== undefined) {
this.setState({ currentSongTime: this.state.currentSongTime + 1 }) this.setState({ currentSongTime: this.state.currentSongTime + 1 })
} }
}, 1000); }, 1000);
} }
handleCurrentSongTime(data) {
try {
const time = data.status.performance.currentSongTime
if (time!==undefined && time!=null) {
this.isCurrentSongTimeProvided = true
this.setState({ currentSongTime: time})
}
} catch (e) {
// do nothing
}
}
async componentDidMount() { async componentDidMount() {
this.#_beatSaverURL = document.location.origin + "/api/beatsaver/map?hash=%s"; this.#_beatSaverURL = document.location.origin + "/api/beatsaver/map?hash=%s";
const urlSearchParams = new URLSearchParams(window.location.search); const urlSearchParams = new URLSearchParams(window.location.search);
@ -118,6 +137,7 @@ export default class Home extends Component {
}); });
socket.addEventListener('message', (message) => { socket.addEventListener('message', (message) => {
const json = JSON.parse(message.data); const json = JSON.parse(message.data);
this.handleCurrentSongTime(json)
if (!this.handlers[json.event]) { if (!this.handlers[json.event]) {
console.log("Unhandled message from HTTP Status. (" + json.event + ")"); console.log("Unhandled message from HTTP Status. (" + json.event + ")");
return; return;