Merge pull request #1 from qe201020335/main

Add CurrentSongTime support from HttpSiraStatus
This commit is contained in:
RealFascinated 2022-04-02 06:38:41 +01:00 committed by GitHub
commit f85b11040f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;