From 6cee42845db8e8112d2766cb5da0794bec95a581 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Fri, 11 Mar 2022 01:20:56 -0800 Subject: [PATCH] Audio is now working, although there are loading race conditions :( Signed-off-by: James Ketrenos --- client/src/App.js | 1 + client/src/MediaControl.css | 2 +- client/src/MediaControl.js | 40 ++++--- client/src/PlayerList.css | 13 +++ client/src/PlayerList.js | 17 ++- server/routes/games.js | 212 ++++++++++++++++++++++++------------ 6 files changed, 189 insertions(+), 96 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 2f4de51..bf42f84 100755 --- a/client/src/App.js +++ b/client/src/App.js @@ -46,6 +46,7 @@ const Table = () => { const data = JSON.parse(event.data); switch (data.type) { case 'game-update': + console.log(`ws: message - ${data.type}`, data.update); if ('name' in data.update && data.update.name !== name) { console.log(`Updating name to ${data.update.name}`); setName(data.update.name); diff --git a/client/src/MediaControl.css b/client/src/MediaControl.css index d7f6afe..1349b5f 100644 --- a/client/src/MediaControl.css +++ b/client/src/MediaControl.css @@ -1,6 +1,6 @@ .MediaAgent { position: absolute; - display: flex; + display: none; top: 0; left: 0; z-index: 50000; diff --git a/client/src/MediaControl.js b/client/src/MediaControl.js index f383c41..237e186 100644 --- a/client/src/MediaControl.js +++ b/client/src/MediaControl.js @@ -278,13 +278,15 @@ const MediaAgent = () => { return; } let update = false; - if (!(name in peers)) { - update = true; - peers[name] = { - local: true, - attributes: { - } - }; + if (stream) { + if (!(name in peers)) { + update = true; + peers[name] = { + local: true, + attributes: { + } + }; + } } for (let key in peers) { @@ -297,14 +299,14 @@ const MediaAgent = () => { console.log(`MediaAgent - Adding local`, peers); setPeers(Object.assign({}, peers)); } - }, [peers, name, setPeers]); + }, [peers, name, setPeers, stream]); - useEffect(() => { + useEffect(async () => { if (!ws) { return; } - const setup_local_media = async () => { + const setup_local_media = () => { /* Ask user for permission to use the computers microphone and/or camera, * attach it to an