1
0

Pass in game instead of table

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-03-08 16:22:09 -08:00
parent 44c2a22ff1
commit fa4f9751b6
2 changed files with 11 additions and 23 deletions

View File

@ -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 }) => {
</div>;
}
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 <div className="MediaControl"/>;
}
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) => {

View File

@ -301,7 +301,7 @@ const Players = ({ table }) => {
onClick={() => { inLobby && selectable && toggleSelected(color) }}
key={`player-${color}`}>
<PlayerColor color={color}/>{name}
<MediaControl color={color} table={table}/>
<MediaControl color={color} game={table.game}/>
</div>
));
}