Skip to content

Commit

Permalink
Allow manual src URL
Browse files Browse the repository at this point in the history
  • Loading branch information
third774 committed Nov 5, 2021
1 parent 6ed6b80 commit 69371b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React, {
import { StreamPlayerApi, StreamProps, VideoDimensions } from "types";
import { useStreamSDK, safelyAccessStreamSDK } from "./useStreamSDK";
import { useIframeSrc } from "./useIframeSrc";
import { validSrcUrl } from "./validSrcUrl";

/**
* Hook for syncing properties to the SDK api when they change
Expand Down Expand Up @@ -143,7 +144,7 @@ export const StreamEmbed: FC<StreamProps> = ({

const iframeRef = useRef<HTMLIFrameElement>(null);

const iframeSrc = useIframeSrc(src, {
const computedSrc = useIframeSrc(src, {
muted,
preload,
loop,
Expand All @@ -155,6 +156,11 @@ export const StreamEmbed: FC<StreamProps> = ({
defaultTextTrack,
});

// While it's easier for most consumers to simply provide the video id
// or signed URL and have us compute the iframe's src for them, some
// consumers may need to manually specify the iframe's src.
const iframeSrc = validSrcUrl(src) ? src : computedSrc;

useProperty("muted", ref, muted);
useProperty("controls", ref, controls);
useProperty("src", ref, src);
Expand Down
8 changes: 8 additions & 0 deletions src/validSrcUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function validSrcUrl(str: string) {
try {
const url = new URL(str);
return url.hostname.endsWith("videodelivery.net");
} catch {
return false;
}
}

0 comments on commit 69371b3

Please sign in to comment.