diff --git a/client/src/MediaControl.js b/client/src/MediaControl.js index 035222c..b3a0a6a 100644 --- a/client/src/MediaControl.js +++ b/client/src/MediaControl.js @@ -15,15 +15,13 @@ const ICE_SERVERS = [ {urls:"stun:stun.l.google.com:19302"} ]; -const MediaAgent = ({ table }) => { +const MediaAgent = ({ game, ws }) => { const [peers, setPeers] = useState({}); - if (!table.ws) { + if (!game || !ws) { return <>>; } - const ws = table.ws; - const addPeer = (config) => { console.log('Signaling server said to add peer:', config); const peer_id = config.peer_id; @@ -194,11 +192,11 @@ const MediaAgent = ({ table }) => { }); ws.addEventListener('error', (event) => { - console.error(`${table.game.name} WebSocket error`); + console.error(`${game.name} WebSocket error`); }); ws.addEventListener('close', (event) => { - console.log(`${table.game.name} Disconnected from signaling server`); + console.log(`${game.name} Disconnected from signaling server`); /* Tear down all of our peer connections and remove all the * media divs when we disconnect */ for (let peer_id in peers) { @@ -215,14 +213,10 @@ const MediaAgent = ({ table }) => { setup_local_media(() => { /* once the user has given us access to their * microphone/camcorder, join the channel and start peering up */ - join_chat_channel(ws, table.game.id, {'whatever-you-want-here': 'stuff'}); + join_chat_channel(ws, game.id, {'whatever-you-want-here': 'stuff'}); }); }); - if (!table.game) { - return <>>; - } - const setup_local_media = (callback, errorback) => { if (local_media_stream !== undefined) { /* ie, if we've already been initialized */ if (callback) callback(); @@ -300,30 +294,24 @@ const MediaAgent = ({ table }) => { ; } -const MediaControl = ({table, color }) => { +const MediaControl = ({game, color }) => { const [mute, setMute] = useState(false); const [mic, setMic] = useState(true); const [noAudio, setNoAudio] = useState(false); const [rtc, setRtc] = useState(undefined); - if (!table || !table.game) { + if (!game) { return <>>; } - /* - const player = table.game.player; - if (!player) { - return <>>; - } -*/ - if (table.game.players[color].status !== 'Active') { + if (game.players[color].status !== 'Active') { return
; } - const isSelf = table.game.color === color; + const isSelf = game.color === color; if (!rtc) { -// setRtc(RTC({ id: table.game.id })); +// setRtc(RTC({ id: game.id })); } const toggleMic = (event) => { diff --git a/client/src/Table.js b/client/src/Table.js index faf6c6d..45f5cf5 100755 --- a/client/src/Table.js +++ b/client/src/Table.js @@ -301,7 +301,7 @@ const Players = ({ table }) => { onClick={() => { inLobby && selectable && toggleSelected(color) }} key={`player-${color}`}>