Skip to content

Commit

Permalink
Fix no-op storage (#511)
Browse files Browse the repository at this point in the history
* fix: storage on lvpr.tv

* fix: lvpr.tv

* ci: bump

* fix: localstorage null

* fix: lvpr.tv

* fix: build

* fix: storage
  • Loading branch information
0xcadams authored Mar 12, 2024
1 parent b9e6d86 commit 5da507e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .changeset/selfish-frogs-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@livepeer/react": patch
"@livepeer/core": patch
"@livepeer/core-react": patch
"@livepeer/core-web": patch
---

**Fix:** fixed no-op localstorage when the `storage` prop is null.
2 changes: 1 addition & 1 deletion apps/docs-embed/src/lib/player-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const source = `export const vodSource = {
{
hrn: "HLS (TS)",
type: "html5/application/vnd.apple.mpegurl",
url: "https://lp-playback.com/hls/f5eese9wwl88k4g8/index.m3u8",
url: "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/f5eese9wwl88k4g8/index.m3u8",
},
],
},
Expand Down
1 change: 1 addition & 0 deletions apps/lvpr-tv/src/components/broadcast/Broadcast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function BroadcastWithControls({
}
aspectRatio={null}
ingestUrl={ingestUrl}
storage={null}
>
<Broadcast.Container className="flex-1 w-full h-full overflow-hidden rounded-sm bg-gray-950">
<Broadcast.Video title="Live stream" className="w-full h-full" />
Expand Down
12 changes: 12 additions & 0 deletions apps/lvpr-tv/src/components/player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export async function PlayerWithControls(props: PlayerProps) {
jwt={props.jwt}
src={src}
aspectRatio={null}
storage={null}
>
<Player.Container className="flex-1 h-full w-full overflow-hidden bg-black outline-none transition-all">
<Player.Video
Expand Down Expand Up @@ -267,3 +268,14 @@ export const PlayerLoading = ({
)}
</div>
);

function isInIframe() {
try {
return typeof window !== "undefined" && window.self !== window.top;
} catch (e) {
// if accessing window.top throws an exception due to cross-origin policy,
// the catch block will also return true,
// indicating the code is running inside an iframe
return true;
}
}
13 changes: 3 additions & 10 deletions packages/core/src/media/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
isPermissionsError,
isStreamOfflineError,
} from "./errors";
import { type ClientStorage, createStorage, noopStorage } from "./storage";
import type { ClientStorage } from "./storage";
import {
generateRandomToken,
getBoundedRate,
Expand Down Expand Up @@ -431,13 +431,6 @@ export const createControllerStore = ({
initialProps: Partial<InitialProps>;
playbackId?: string;
}): { store: MediaControllerStore; destroy: () => void } => {
const resolvedStorage =
initialProps?.storage === null
? createStorage({
storage: noopStorage,
})
: initialProps?.storage ?? storage;

const initialPlaybackRate = initialProps?.playbackRate ?? 1;
const initialVolume = getBoundedVolume(
initialProps.volume ?? DEFAULT_VOLUME_LEVEL,
Expand Down Expand Up @@ -576,7 +569,7 @@ export const createControllerStore = ({
playbackRate: initialPlaybackRate,
posterLiveUpdate: initialProps.posterLiveUpdate ?? 30000,
preload: initialProps.preload ?? "none",
storage: resolvedStorage,
storage,
timeout: initialProps.timeout ?? 10000,
videoQuality: initialVideoQuality,
viewerId: initialProps.viewerId ?? null,
Expand Down Expand Up @@ -1099,7 +1092,7 @@ export const createControllerStore = ({
volume,
videoQuality,
}),
storage: createJSONStorage(() => resolvedStorage),
storage: createJSONStorage(() => storage),
},
),
),
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/broadcast/Broadcast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Broadcast = (
createControllerStore({
device: getDeviceInfo(version.react),
storage: createStorage(
typeof window !== "undefined"
storage !== null && typeof window !== "undefined"
? {
storage: window.localStorage,
}
Expand All @@ -75,7 +75,6 @@ const Broadcast = (
aspectRatio,
volume: 0,
onError,
storage,
timeout,
videoQuality,
},
Expand All @@ -86,7 +85,7 @@ const Broadcast = (
createBroadcastStore({
device: getBroadcastDeviceInfo(version.react),
storage: createStorage(
typeof window !== "undefined"
storage !== null && typeof window !== "undefined"
? {
storage: window.localStorage,
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ const Player = React.memo((props: MediaScopedProps<PlayerProps>) => {
children,
jwt,
accessKey,
storage,
...rest
} = props;

const store = useRef(
createControllerStore({
device: getDeviceInfo(version.react),
storage: createStorage(
typeof window !== "undefined"
storage !== null && typeof window !== "undefined"
? {
storage: window.localStorage,
}
Expand Down

0 comments on commit 5da507e

Please sign in to comment.