From 1c978c999c6d3f6ca2d914c449688b45ff88b89c Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 9 Apr 2020 12:12:53 +1000 Subject: [PATCH] Removed stream component and set muted state when stream is loaded --- src/components/Nickname.js | 16 ++++++++++++---- src/components/Stream.js | 19 ------------------- 2 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 src/components/Stream.js diff --git a/src/components/Nickname.js b/src/components/Nickname.js index 507dc8a..f91c895 100644 --- a/src/components/Nickname.js +++ b/src/components/Nickname.js @@ -1,10 +1,16 @@ -import React, { useState } from "react"; +import React, { useState, useRef, useEffect } from "react"; import { Text, IconButton } from "theme-ui"; -import Stream from "./Stream"; - function Nickname({ nickname, stream }) { const [streamMuted, setStreamMuted] = useState(false); + const audioRef = useRef(); + + useEffect(() => { + if (audioRef.current) { + audioRef.current.srcObject = stream; + setStreamMuted(audioRef.current.defaultMuted); + } + }, [stream]); return ( )} - {stream && } + {stream && ( + ); } diff --git a/src/components/Stream.js b/src/components/Stream.js deleted file mode 100644 index 5204684..0000000 --- a/src/components/Stream.js +++ /dev/null @@ -1,19 +0,0 @@ -import React, { useRef, useEffect } from "react"; - -function Stream({ stream, muted }) { - const audioRef = useRef(); - useEffect(() => { - if (audioRef.current) { - audioRef.current.srcObject = stream; - audioRef.current.play(); - } - }, [stream]); - - return