forked from acmutsa/HackKit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding /live to broadcast livestream (#40)
* Created live page * Added /live page * Added Stream to page * Updated lockfile * Briefly fixed errors * Prettier write
- Loading branch information
1 parent
473eb98
commit d98d575
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use client"; | ||
import React, { useEffect, useRef } from "react"; | ||
import Hls from "hls.js"; | ||
|
||
export default function LivePage() { | ||
const streamUrl = | ||
"https://82934cf9c8696bd2.mediapackage.us-east-1.amazonaws.com/out/v1/0909ac7915bf450da5267c52f49797cb/index.m3u8"; | ||
|
||
const videoRef = useRef(null); | ||
|
||
useEffect(() => { | ||
// Initialize HLS only if supported | ||
if (Hls.isSupported()) { | ||
const hls = new Hls(); | ||
hls.loadSource(streamUrl); | ||
hls.attachMedia(videoRef.current!); | ||
|
||
hls.on(Hls.Events.MANIFEST_PARSED, () => { | ||
// TODO: WILL FIX LATER | ||
// @ts-ignore | ||
videoRef.current.play(); | ||
}); | ||
|
||
return () => { | ||
hls.destroy(); | ||
}; | ||
} else { | ||
// @ts-ignore | ||
if (videoRef.current.canPlayType("application/vnd.apple.mpegurl")) { | ||
// For Safari browsers where HLS is natively supported | ||
// @ts-ignore | ||
videoRef.current.src = streamUrl; | ||
// @ts-ignore | ||
videoRef.current.play(); | ||
} | ||
} | ||
}, [streamUrl]); | ||
|
||
return ( | ||
<div> | ||
<video | ||
ref={videoRef} | ||
controls | ||
width="1920" | ||
height="1080" | ||
style={{ maxWidth: "100%" }} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.