Skip to content

Commit

Permalink
Resolve conflicts and improve alert
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnouv committed Apr 5, 2022
1 parent d04ad98 commit c9cfb77
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 56 deletions.
77 changes: 48 additions & 29 deletions app/components/clientsideonly/videostreamer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ import Head from "next/head";
import { useEffect, useState } from "react";

export default function Videostreamer(props) {
const [ping, setPing] = useState(false)
const [ping, setPing] = useState(false);

const pingStream = async () => {
const response = await fetch(props.src)
const response = await fetch(props.src);
if (response.ok) {
setPing(true)
}
return;
}
useEffect(() => {
setInterval(() => {
pingStream().catch(e => {
console.error("Stream error", e)
setPing(false)
})
}, 60000)

}, [])
return response;
};
useEffect(() => {
setInterval(async () => {
pingStream()
.catch((e) => {
console.error("Stream error", e);
setPing(false);
return
});

}, 30000);
}, []);

const handleToast = () => {
setPing(true)
}
setPing(true);
};

return (
<>
<Head>
Expand All @@ -45,7 +50,7 @@ export default function Videostreamer(props) {
<video
autoPlay
id="my-video"
class="video-js vjs-big-play-centered vjs-responsive"
className="video-js vjs-big-play-centered vjs-responsive"
controls
preload="auto"
poster={props.poster}
Expand All @@ -60,23 +65,37 @@ export default function Videostreamer(props) {
</a>
</p>
</video>
<Alert show={!ping} handleToast={handleToast}/>

<Alert
show={!ping}
handleToast={handleToast}
/>
</Col>
</>
);
}

const Alert = ({handleToast, show}) => {
const Alert = ({ handleToast, show }) => {
return (
<ToastContainer show={show} position="bottom-start" style={{zIndex: "10"}} className="p-3">
<Toast show={show} onClose={handleToast} bg="info">
<Toast.Header>
<strong className="me-auto">Stream Alert!</strong>
<small className="text-muted">just now</small>
</Toast.Header>
<Toast.Body>Thank you for tuning in! Looks like the streaming has stopped! Please stay tune!</Toast.Body>
</Toast>
</ToastContainer>
)
}
<ToastContainer
position="bottom-start"
style={{ zIndex: "10" }}
className="p-3"
>
<Toast
show={show}
onClose={handleToast}
delay={60000}
autohide
bg="warning"
>
<Toast.Header>
<strong className="me-auto">Stream Alert!</strong>
</Toast.Header>
<Toast.Body>
Thank you for watching! Looks like the streaming has stopped! Please
stay tune and refresh the page if this alert does not shows up!
</Toast.Body>
</Toast>
</ToastContainer>
);
};
66 changes: 39 additions & 27 deletions app/pages/virtualconf/mainstage/[id].js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Head from 'next/head';
import { useEffect, useState } from 'react';
import { Container, Button } from 'react-bootstrap';
import Videostreamer from '../../../components/clientsideonly/videostreamer';
import InAppChat from '../../../components/inappchat/inappchat';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';
import styles from '../../../styles/Videostreamer.module.css';
import Head from "next/head";
import { useEffect, useState } from "react";
import { Container, Button } from "react-bootstrap";
import Videostreamer from "../../../components/clientsideonly/videostreamer";
import InAppChat from "../../../components/inappchat/inappchat";
import { useMediaQuery } from "@rocket.chat/fuselage-hooks";
import styles from "../../../styles/Videostreamer.module.css";
import { FaRocketchat } from "react-icons/fa";
import { getIPInfo } from '../../../lib/geoAPI';
import { getIPInfo } from "../../../lib/geoAPI";

const rid = "GENERAL";
const host = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://community.liaison.rocketchat.digital";
Expand All @@ -15,38 +15,47 @@ const otherLink = process.env.NEXT_PUBLIC_SERVER_STREAM_LINK1

export default function ConfMainStage({ cookies, ipInfo }) {
const [openChat, setOpenChat] = useState(true);
const isSmallScreen = useMediaQuery('(max-width: 992px)');
const [streamLink, setStreamLink] = useState("https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_1MB.mp4")
const isSmallScreen = useMediaQuery("(max-width: 992px)");
const [streamLink, setStreamLink] = useState(asiaLink);

const handleOpenChat = () => {
setOpenChat((prevState) => !prevState);
};

useEffect(() => {
if (ipInfo.timezone.split('/')[0] == "Asia") {
setStreamLink(asiaLink)
}
else {
setStreamLink(otherLink)
try {
if (
ipInfo == null ||
ipInfo.timezone == undefined ||
ipInfo.timezone == null
) {
return;
}
if (ipInfo.timezone.split("/")[0] == "Asia") {
setStreamLink(asiaLink);
} else {
setStreamLink(otherLink);
}
} catch {
return;
}
}, [])

}, []);

return (
<>
<div className='d-flex flex-column flex-lg-row '>
<div className="d-flex flex-column flex-lg-row ">
<Head>
<title>Virtual Conference Main Stage</title>
<meta
name='description'
content='Demonstration main stage for a virtual conference'
name="description"
content="Demonstration main stage for a virtual conference"
/>
</Head>
<Container fluid className={styles.videoContainer}>
<Videostreamer
poster='/gsocsmall.jpg'
poster="/gsocsmall.jpg"
src={streamLink}
type='application/vnd.apple.mpegurl'
type="application/vnd.apple.mpegurl"
></Videostreamer>
</Container>
{isSmallScreen ? (
Expand All @@ -68,8 +77,11 @@ export default function ConfMainStage({ cookies, ipInfo }) {
}

ConfMainStage.getInitialProps = async (ctx) => {
const res = await getIPInfo()

return { ipInfo: res.data }
}
try {
const res = await getIPInfo();

return { ipInfo: res.data };
} catch {
return { ipInfo: null };
}
};

0 comments on commit c9cfb77

Please sign in to comment.