Skip to content

Commit 82197c0

Browse files
authored
Implement ingest playback queryparam for Livepeer TV (#587)
1 parent 0e5a036 commit 82197c0

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

apps/lvpr-tv/src/app/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type LowLatency = Booleanish | "force";
1515
type ObjectFit = "contain" | "cover";
1616
type Constant = Booleanish;
1717
type Debug = Booleanish;
18+
type IngestPlayback = Booleanish;
1819

1920
type PlayerSearchParams = {
2021
v?: string;
@@ -31,6 +32,7 @@ type PlayerSearchParams = {
3132
jwt?: string;
3233
accessKey?: string;
3334
debug?: Debug;
35+
ingestPlayback?: IngestPlayback;
3436
};
3537

3638
export default async function PlayerPage({
@@ -60,6 +62,7 @@ export default async function PlayerPage({
6062
jwt: searchParams?.jwt ?? null,
6163
accessKey: searchParams?.accessKey ?? null,
6264
debug: coerceToBoolean(searchParams?.debug, false),
65+
ingestPlayback: coerceToBoolean(searchParams?.ingestPlayback, false),
6366
};
6467

6568
return (

apps/lvpr-tv/src/components/player/Player.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type PlayerProps = Partial<{
3737
jwt: string | null;
3838
accessKey: string | null;
3939
debug: boolean;
40+
ingestPlayback: boolean;
4041
}>;
4142

4243
const getPlaybackInfoUncached = cache(async (playbackId: string) => {
@@ -106,6 +107,7 @@ export async function PlayerWithControls(props: PlayerProps) {
106107
src={src}
107108
aspectRatio={null}
108109
storage={null}
110+
ingestPlayback={props.ingestPlayback}
109111
>
110112
<Player.Container className="flex-1 h-full w-full overflow-hidden bg-black outline-none transition-all">
111113
<Player.Video

packages/core/src/media/controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export type InitialProps = {
154154
* The viewerId for the viewer. A unique identifier for the user or session watching the media.
155155
*/
156156
viewerId: string | null;
157+
158+
ingestPlayback: boolean;
157159
};
158160

159161
export type DeviceInformation = {
@@ -538,6 +540,7 @@ export const createControllerStore = ({
538540
hasRecentWebRTCTimeout: getHasRecentWebRTCTimeout(
539541
initialProps.cacheWebRTCFailureMs,
540542
),
543+
ingestPlayback: initialProps.ingestPlayback ?? false,
541544
});
542545

543546
const initialControls: ControlsState = {
@@ -658,6 +661,7 @@ export const createControllerStore = ({
658661
videoQuality: initialVideoQuality,
659662
viewerId: initialProps.viewerId ?? null,
660663
volume: initialVolume ?? null,
664+
ingestPlayback: initialProps.ingestPlayback ?? false,
661665
},
662666

663667
__device: device,
@@ -856,6 +860,7 @@ export const createControllerStore = ({
856860
hasRecentWebRTCTimeout: getHasRecentWebRTCTimeout(
857861
__initialProps.cacheWebRTCFailureMs,
858862
),
863+
ingestPlayback: __initialProps.ingestPlayback,
859864
});
860865

861866
return {
@@ -1178,6 +1183,7 @@ export const createControllerStore = ({
11781183
sessionToken: __controls.sessionToken,
11791184
source: nextSource,
11801185
videoQuality,
1186+
ingestPlayback: __initialProps.ingestPlayback,
11811187
});
11821188

11831189
return {

packages/core/src/media/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export const parseCurrentSourceAndPlaybackId = ({
226226
sessionToken,
227227
source,
228228
videoQuality,
229+
ingestPlayback,
229230
}: {
230231
accessKey: InitialProps["accessKey"];
231232
aspectRatio: InitialProps["aspectRatio"];
@@ -235,6 +236,7 @@ export const parseCurrentSourceAndPlaybackId = ({
235236
sessionToken: string;
236237
source: Src | null;
237238
videoQuality: VideoQuality;
239+
ingestPlayback: InitialProps["ingestPlayback"];
238240
}) => {
239241
if (!source) {
240242
return null;
@@ -277,6 +279,10 @@ export const parseCurrentSourceAndPlaybackId = ({
277279
}
278280
}
279281

282+
if (ingestPlayback) {
283+
url.searchParams.append("ingestpb", String(ingestPlayback));
284+
}
285+
280286
// override the url with the new URL
281287
const newSrc = {
282288
...source,
@@ -309,6 +315,7 @@ export const getNewSource = ({
309315
src,
310316
videoQuality,
311317
hasRecentWebRTCTimeout,
318+
ingestPlayback,
312319
}: {
313320
accessKey: InitialProps["accessKey"] | undefined;
314321
aspectRatio: InitialProps["aspectRatio"] | undefined;
@@ -321,6 +328,7 @@ export const getNewSource = ({
321328
src: Src[] | string | null | undefined;
322329
videoQuality: VideoQuality;
323330
hasRecentWebRTCTimeout: boolean;
331+
ingestPlayback: InitialProps["ingestPlayback"];
324332
}) => {
325333
const sortedSources = sortSources({
326334
src,
@@ -340,6 +348,7 @@ export const getNewSource = ({
340348
sessionToken: sessionToken,
341349
source: sortedSources?.[0] ?? null,
342350
videoQuality,
351+
ingestPlayback,
343352
});
344353

345354
return {

0 commit comments

Comments
 (0)