Skip to content

Commit

Permalink
Merge pull request #43 from cloudflare/allow-manual-src-url
Browse files Browse the repository at this point in the history
Allow manual src URL
  • Loading branch information
third774 authored Nov 5, 2021
2 parents 13fcfb8 + 69371b3 commit 3c86433
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 3c86433

Please sign in to comment.