Skip to content

Commit

Permalink
fast stop without waiting for request
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga authored and ThibaultNocchi committed Feb 28, 2023
1 parent 40d472a commit 462e9b4
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions frontend/src/store/playbackManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,18 +621,25 @@ class PlaybackManagerStore {
/**
* Report playback stopped to the server. Used by the "Now playing" statistics in other clients.
*/
private _reportPlaybackStopped = async (itemId: string): Promise<void> => {
private _reportPlaybackStopped = async (
itemId: string,
sessionId = state.playSessionId,
currentTime = this.currentTime,
updateState = true
): Promise<void> => {
const remote = useRemote();

await remote.sdk.newUserApi(getPlaystateApi).reportPlaybackStopped({
playbackStopInfo: {
ItemId: itemId,
PlaySessionId: state.playSessionId,
PositionTicks: msToTicks((this.currentTime || 0) * 1000)
PlaySessionId: sessionId,
PositionTicks: msToTicks((currentTime || 0) * 1000)
}
});

state.lastProgressUpdate = Date.now();
if (updateState) {
state.lastProgressUpdate = Date.now();
}
};

/**
Expand Down Expand Up @@ -837,24 +844,22 @@ class PlaybackManagerStore {
};

public stop = (): void => {
const sessionId = String(state.playSessionId || '');
const time = Number(this.currentTime);
const itemId = String(this.currentItem?.Id || '');
const volume = Number(this.currentVolume);

Object.assign(state, defaultState);
this.currentVolume = volume;

window.setTimeout(async () => {
const remote = useRemote();

try {
if (
!isNil(this.currentItem) &&
!isNil(this.currentItem.Id) &&
!isNil(remote.auth.currentUser)
) {
this._reportPlaybackStopped(this.currentItem.Id);
if (sessionId && itemId && time && remote.auth.currentUser) {
await this._reportPlaybackStopped(itemId, sessionId, time, false);
}
} catch {
} finally {
const volume = this.currentVolume;

Object.assign(state, defaultState);
this.currentVolume = volume;
}
} catch {}
});
};

Expand Down

0 comments on commit 462e9b4

Please sign in to comment.