Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow manual src URL
  • Loading branch information
third774 committed Nov 5, 2021
commit 69371b33eb97b0c5243e57e21d2a20669678c2f5
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;
}
}