fix: further limit extraneous events from playback reporting

This commit is contained in:
Lei Nelissen
2024-07-25 15:45:26 +02:00
parent 0b13e69854
commit c9f7f71194
4 changed files with 38 additions and 11 deletions

View File

@@ -40,15 +40,16 @@ export default async function() {
TrackPlayer.addEventListener(Event.PlaybackActiveTrackChanged, async (e) => {
// Retrieve the current settings from the Redux store
const settings = store.getState().settings;
console.log('TrackChanged', e?.track?.title);
// GUARD: Only report playback when the settings is enabled
if (settings.enablePlaybackReporting && 'track' in e) {
// GUARD: End the previous track if it's about to end
if (e.lastTrack) {
await sendPlaybackEvent('/Sessions/Playing/Stopped', e.lastTrack, e.lastPosition);
sendPlaybackEvent('/Sessions/Playing/Stopped', e.lastTrack, e.lastPosition);
}
await sendPlaybackEvent('/Sessions/Playing', e.track);
sendPlaybackEvent('/Sessions/Playing', e.track);
}
});