Skip to content

Commit

Permalink
Update getSrc to support web server url
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-face committed May 22, 2024
1 parent 0159ea9 commit a8e1355
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions gateway/src/components/Player/GetSrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@ import { getSrc } from "@livepeer/react/external";
import { createLivepeerInstance } from "./LivepeerInstance";
import { useStore } from "./state";

const GetSrc = () => {
const GetSrc = ({ url }) => {
const { setSrc, setError, playbackId } = useStore();

const getPlaybackSource = async (playbackId) => {
const livepeer = createLivepeerInstance();

try {
console.log("-- livepeer.playback");
// TODO: use livepeer (js) 3.1
const playbackInfo = await livepeer.playback.get(playbackId);
// const srcInfo = await livepeer.asset.get(playbackId);

console.log("playbackInfo:");
console.log(playbackInfo);
// console.log(srcInfo);
const src = getSrc(playbackInfo.playbackInfo);

return src;
} catch (error) {
console.log(error);
setError(error.message);
if (url) {
try {
let result = await fetch(`${url}/playback/${playbackId}`);

result = await result.json();
const src = getSrc(result);

return src;
} catch (error) {
console.log(error);
}
} else {
const livepeer = createLivepeerInstance();

try {
// TODO: use livepeer (js) 3.1
const playbackInfo = await livepeer.playback.get(playbackId);
// const srcInfo = await livepeer.asset.get(playbackId);

const src = getSrc(playbackInfo.playbackInfo);

return src;
} catch (error) {
console.log(error);
setError(error.message);
}
}
};

Expand Down

0 comments on commit a8e1355

Please sign in to comment.