fix: actually send out /Playing events as session updates.

This should more consistently result in output data in your play back reporting modules.

fixes #218
This commit is contained in:
Lei Nelissen
2024-05-26 18:00:05 +02:00
parent 823f7b59e8
commit b01470bde8
2 changed files with 23 additions and 21 deletions

View File

@@ -37,18 +37,18 @@ export default async function() {
TrackPlayer.seekTo(event.position);
});
TrackPlayer.addEventListener(Event.PlaybackTrackChanged, async (e) => {
TrackPlayer.addEventListener(Event.PlaybackActiveTrackChanged, async (e) => {
// Retrieve the current settings from the Redux store
const settings = store.getState().settings;
// 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 ('nextTrack' in e && typeof e.track === 'number') {
sendPlaybackEvent('/Sessions/Playing/Stopped', settings.jellyfin, e.track);
if (e.lastTrack) {
await sendPlaybackEvent('/Sessions/Playing/Stopped', settings.jellyfin, e.lastTrack);
}
sendPlaybackEvent('/Sessions/Playing', settings.jellyfin);
await sendPlaybackEvent('/Sessions/Playing', settings.jellyfin, e.track);
}
});
@@ -69,14 +69,16 @@ export default async function() {
});
TrackPlayer.addEventListener(Event.PlaybackState, (event) => {
// GUARD: Only respond to stopped events
if (event.state === State.Stopped) {
// Retrieve the current settings from the Redux store
const settings = store.getState().settings;
// Retrieve the current settings from the Redux store
const settings = store.getState().settings;
// GUARD: Only report playback when the settings is enabled
if (settings.enablePlaybackReporting) {
// GUARD: Only report playback when the settings is enabled
if (settings.enablePlaybackReporting) {
// GUARD: Only respond to stopped events
if (event.state === State.Stopped) {
sendPlaybackEvent('/Sessions/Playing/Stopped', settings.jellyfin);
} else if (event.state === State.Paused) {
sendPlaybackEvent('/Sessions/Playing/Progress', settings.jellyfin);
}
}
});