Skip to content

Commit

Permalink
Set live edge delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
i-zolotarenko committed Dec 24, 2023
1 parent 21f5a88 commit c6d9627
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion p2p-media-loader-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Vite + React + TS</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr@latest"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/clappr/clappr-level-selector-plugin@latest/dist/level-selector.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/shaka-player@~4.4.0/dist/shaka-player.compiled.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/shaka-player@~4.6.0/dist/shaka-player.compiled.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/clappr/dash-shaka-playback@latest/dist/dash-shaka-playback.external.js"></script>
</head>
<body>
Expand Down
5 changes: 1 addition & 4 deletions p2p-media-loader-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ function App() {
type: "customHls",
customType: {
customHls: (video: HTMLVideoElement) => {
const hls = new Hls({
...engine.getConfig(),
liveSyncDurationCount: 7,
});
const hls = new Hls(engine.getConfig());
engine.setHls(hls);
hls.loadSource(video.src);
hls.attachMedia(video);
Expand Down
6 changes: 4 additions & 2 deletions packages/p2p-media-loader-hlsjs/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { PlaylistLoaderBase } from "./playlist-loader";
import { SegmentManager } from "./segment-mananger";
import { Core, CoreEventHandlers } from "p2p-media-loader-core";

const LIVE_EDGE_DELAY = 25;

export class Engine {
private readonly core: Core;
private readonly segmentManager: SegmentManager;
Expand All @@ -23,12 +25,12 @@ export class Engine {

public getConfig(): Pick<
HlsConfig,
"fLoader" | "pLoader" | "liveSyncDurationCount"
"fLoader" | "pLoader" | "liveSyncDuration"
> {
return {
liveSyncDurationCount: 7,
fLoader: this.createFragmentLoaderClass(),
pLoader: this.createPlaylistLoaderClass(),
liveSyncDuration: LIVE_EDGE_DELAY,
};
}

Expand Down
10 changes: 10 additions & 0 deletions packages/p2p-media-loader-shaka/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { Loader } from "./loading-handler";
import { Core, CoreEventHandlers } from "p2p-media-loader-core";

const LIVE_EDGE_DELAY = 25;

export class Engine {
private player?: shaka.Player;
private readonly shaka: Shaka;
Expand Down Expand Up @@ -68,6 +70,14 @@ export class Engine {
player[method]("loaded", this.handlePlayerLoaded);
player[method]("loading", this.destroyCurrentStreamContext);
player[method]("unloading", this.handlePlayerUnloading);
player[method]("manifestparsed", this.handleManifestParsed);
};

private handleManifestParsed = () => {
const manifest = this.player?.getManifest();
if (!manifest) return;
const { presentationTimeline } = manifest;
presentationTimeline.setDelay(LIVE_EDGE_DELAY);
};

private handlePlayerLoaded = () => {
Expand Down

0 comments on commit c6d9627

Please sign in to comment.