From 2f18222e990eeea34d9e105b0ae75aee06c4a525 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Wed, 8 Apr 2020 19:56:14 +1000 Subject: [PATCH] Moved to audio only, handled stream closure and added mute button to name --- src/components/Nickname.js | 40 ++++++++++++++++-- src/components/Party.js | 15 +++---- src/components/Stream.js | 16 ++----- src/helpers/shared.js | 5 +++ src/helpers/useSession.js | 19 +++++++-- src/routes/Game.js | 87 ++++++++++++++++++++++++++++++++------ 6 files changed, 139 insertions(+), 43 deletions(-) diff --git a/src/components/Nickname.js b/src/components/Nickname.js index e384e1e..94fe404 100644 --- a/src/components/Nickname.js +++ b/src/components/Nickname.js @@ -1,7 +1,11 @@ -import React from "react"; -import { Text } from "theme-ui"; +import React, { useState } from "react"; +import { Text, IconButton } from "theme-ui"; + +import Stream from "./Stream"; + +function Nickname({ nickname, stream }) { + const [streamMuted, setStreamMuted] = useState(false); -function Nickname({ nickname }) { return ( stream && setStreamMuted(!streamMuted)} > {nickname} + {stream && ( + + + {streamMuted ? ( + + ) : ( + + )} + + + )} + {stream && } ); } diff --git a/src/components/Party.js b/src/components/Party.js index 27a552f..20b10b0 100644 --- a/src/components/Party.js +++ b/src/components/Party.js @@ -3,7 +3,6 @@ import { Flex, Box, Text } from "theme-ui"; import AddPartyMemberButton from "./AddPartyMemberButton"; import Nickname from "./Nickname"; -import Stream from "./Stream"; import ChangeNicknameButton from "./ChangeNicknameButton"; import StartStreamButton from "./StartStreamButton"; @@ -45,16 +44,12 @@ function Party({ > {Object.entries(partyNicknames).map(([id, partyNickname]) => ( - + ))} - {(stream || Object.keys(partyStreams).length !== 0) && ( - Streams - )} - {stream && } - {partyStreams && - Object.entries(partyStreams).map(([id, partyStream]) => ( - - ))} diff --git a/src/components/Stream.js b/src/components/Stream.js index be7626e..95994c1 100644 --- a/src/components/Stream.js +++ b/src/components/Stream.js @@ -1,22 +1,14 @@ import React, { useRef, useEffect } from "react"; function Stream({ stream, muted }) { - const videoRef = useRef(); + const audioRef = useRef(); useEffect(() => { - if (videoRef.current) { - videoRef.current.srcObject = stream; + if (audioRef.current) { + audioRef.current.srcObject = stream; } }, [stream]); - return ( -