From 1d0a6df84807a0d50d54e5fa20d30c2711c30fee Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Sun, 3 Jan 2021 20:23:58 +0100 Subject: [PATCH] Embed twitch player and default to it. --- frontend/pages/[id]/[vslug].tsx | 98 ++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/frontend/pages/[id]/[vslug].tsx b/frontend/pages/[id]/[vslug].tsx index bafeeab..fffae11 100644 --- a/frontend/pages/[id]/[vslug].tsx +++ b/frontend/pages/[id]/[vslug].tsx @@ -5,7 +5,7 @@ import Link from 'next/link'; import { useRouter } from 'next/router'; import { - Breadcrumb, Button, ButtonGroup, Col, Row, + Breadcrumb, Button, ButtonGroup, Col, ResponsiveEmbed, Row, Tab, Tabs, } from 'react-bootstrap'; import { useIntl } from 'react-intl'; @@ -129,6 +129,10 @@ const getProps = withSession(async (req, _res, { id, vslug }: { id: string, vslu volume = volumeSessionValue; } + if (!req.headers.host) { + throw new Error(JSON.stringify(req.headers)) + } + // Pass data to the page via props return { props: { @@ -139,19 +143,7 @@ const getProps = withSession(async (req, _res, { id, vslug }: { id: string, vslu title, hlsServerURL, dashServerURL, - - // extra: ((o) => Object - // .keys(o) - // .map((k) => { - // if (k === undefined || k === null) { - // return JSON.stringify(k); - // } - // if (k.toString) { - // return k.toString(); - // } - // return ''; - // }).join('\n'))(req.socket), - + twitchPlayerParentKey: req.headers.host.split(':')[0], basePath, }, }; @@ -174,6 +166,7 @@ export default function VideoPlayerPage({ hlsServerURL, dashServerURL, basePath, + twitchPlayerParentKey, }: InferGetServerSidePropsType) { if (redirect) { const router = useRouter(); @@ -226,6 +219,11 @@ export default function VideoPlayerPage({ } } + const twitchEmbedURL = new URL("https://player.twitch.tv"); + twitchEmbedURL.searchParams.append('video', sourceVideoURL.split('/').pop()); + twitchEmbedURL.searchParams.append('parent', twitchPlayerParentKey); + twitchEmbedURL.searchParams.append('t', `${Math.floor(sourceVideoStart / 60)}m${sourceVideoStart % 60}s`) + return (
@@ -247,12 +245,6 @@ export default function VideoPlayerPage({ - {/*
-        
-          {extra}
-        
-      
*/} - @@ -271,31 +263,47 @@ export default function VideoPlayerPage({ - + + + + + + + + + +

{title}