From a8e13557ba3790485314f4a6118cef2fa2736fc8 Mon Sep 17 00:00:00 2001 From: stefano Date: Wed, 22 May 2024 14:12:32 +0200 Subject: [PATCH] Update getSrc to support web server url --- gateway/src/components/Player/GetSrc.js | 45 +++++++++++++++---------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/gateway/src/components/Player/GetSrc.js b/gateway/src/components/Player/GetSrc.js index be4f00e..669d181 100644 --- a/gateway/src/components/Player/GetSrc.js +++ b/gateway/src/components/Player/GetSrc.js @@ -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); + } } };