Skip to content

Commit

Permalink
Merge pull request #680 from 3flex/patch-3
Browse files Browse the repository at this point in the history
Migrate transcoder pinging to jellyfin-sdk-typescript
  • Loading branch information
nielsvanvelzen authored Nov 7, 2024
2 parents 9bf4443 + 073f5c2 commit a31be60
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/components/jellyfinActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function restartPingInterval(reportingParams: PlaybackProgressInfo): void {

if (reportingParams.PlayMethod == 'Transcode') {
pingInterval = window.setInterval(() => {
pingTranscoder(reportingParams);
if (reportingParams.PlaySessionId) {
pingTranscoder(reportingParams.PlaySessionId);
}
}, 1000);
}
}
Expand Down Expand Up @@ -143,12 +145,10 @@ export function reportPlaybackStopped(
* /Sessions/Playing/Progress does work but may not be called during pause.
* The web client calls that during pause, but this endpoint gets the job done
* as well.
* @param reportingParams - progress information to carry
* @param playSessionId - the playback session ID to ping
* @returns promise for waiting for the request
*/
export function pingTranscoder(
reportingParams: PlaybackProgressInfo
): Promise<void> {
export async function pingTranscoder(playSessionId: string): Promise<void> {
const now = new Date().getTime();

// 10s is the timeout value, so use half that to report often enough
Expand All @@ -162,18 +162,9 @@ export function pingTranscoder(

lastTranscoderPing = new Date().getTime();

// 10.7 oddly wants it as a query string parameter. This is a server bug for now.
return JellyfinApi.authAjax(
`Sessions/Playing/Ping?playSessionId=${reportingParams.PlaySessionId}`,
{
contentType: 'application/json',
data: JSON.stringify({
// jellyfin <= 10.6 wants it in the post data.
PlaySessionId: reportingParams.PlaySessionId
}),
type: 'POST'
}
);
await getPlaystateApi(JellyfinApi.jellyfinApi).pingPlaybackSession({
playSessionId: playSessionId
});
}

/**
Expand Down

0 comments on commit a31be60

Please sign in to comment.