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