Pass in game instead of table
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
44c2a22ff1
commit
fa4f9751b6
@ -15,15 +15,13 @@ const ICE_SERVERS = [
|
|||||||
{urls:"stun:stun.l.google.com:19302"}
|
{urls:"stun:stun.l.google.com:19302"}
|
||||||
];
|
];
|
||||||
|
|
||||||
const MediaAgent = ({ table }) => {
|
const MediaAgent = ({ game, ws }) => {
|
||||||
const [peers, setPeers] = useState({});
|
const [peers, setPeers] = useState({});
|
||||||
|
|
||||||
if (!table.ws) {
|
if (!game || !ws) {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ws = table.ws;
|
|
||||||
|
|
||||||
const addPeer = (config) => {
|
const addPeer = (config) => {
|
||||||
console.log('Signaling server said to add peer:', config);
|
console.log('Signaling server said to add peer:', config);
|
||||||
const peer_id = config.peer_id;
|
const peer_id = config.peer_id;
|
||||||
@ -194,11 +192,11 @@ const MediaAgent = ({ table }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener('error', (event) => {
|
ws.addEventListener('error', (event) => {
|
||||||
console.error(`${table.game.name} WebSocket error`);
|
console.error(`${game.name} WebSocket error`);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener('close', (event) => {
|
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
|
/* Tear down all of our peer connections and remove all the
|
||||||
* media divs when we disconnect */
|
* media divs when we disconnect */
|
||||||
for (let peer_id in peers) {
|
for (let peer_id in peers) {
|
||||||
@ -215,14 +213,10 @@ const MediaAgent = ({ table }) => {
|
|||||||
setup_local_media(() => {
|
setup_local_media(() => {
|
||||||
/* once the user has given us access to their
|
/* once the user has given us access to their
|
||||||
* microphone/camcorder, join the channel and start peering up */
|
* 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) => {
|
const setup_local_media = (callback, errorback) => {
|
||||||
if (local_media_stream !== undefined) { /* ie, if we've already been initialized */
|
if (local_media_stream !== undefined) { /* ie, if we've already been initialized */
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
@ -300,30 +294,24 @@ const MediaAgent = ({ table }) => {
|
|||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MediaControl = ({table, color }) => {
|
const MediaControl = ({game, color }) => {
|
||||||
const [mute, setMute] = useState(false);
|
const [mute, setMute] = useState(false);
|
||||||
const [mic, setMic] = useState(true);
|
const [mic, setMic] = useState(true);
|
||||||
const [noAudio, setNoAudio] = useState(false);
|
const [noAudio, setNoAudio] = useState(false);
|
||||||
const [rtc, setRtc] = useState(undefined);
|
const [rtc, setRtc] = useState(undefined);
|
||||||
|
|
||||||
if (!table || !table.game) {
|
if (!game) {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (game.players[color].status !== 'Active') {
|
||||||
const player = table.game.player;
|
|
||||||
if (!player) {
|
|
||||||
return <></>;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (table.game.players[color].status !== 'Active') {
|
|
||||||
return <div className="MediaControl"/>;
|
return <div className="MediaControl"/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSelf = table.game.color === color;
|
const isSelf = game.color === color;
|
||||||
|
|
||||||
if (!rtc) {
|
if (!rtc) {
|
||||||
// setRtc(RTC({ id: table.game.id }));
|
// setRtc(RTC({ id: game.id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleMic = (event) => {
|
const toggleMic = (event) => {
|
||||||
|
@ -301,7 +301,7 @@ const Players = ({ table }) => {
|
|||||||
onClick={() => { inLobby && selectable && toggleSelected(color) }}
|
onClick={() => { inLobby && selectable && toggleSelected(color) }}
|
||||||
key={`player-${color}`}>
|
key={`player-${color}`}>
|
||||||
<PlayerColor color={color}/>{name}
|
<PlayerColor color={color}/>{name}
|
||||||
<MediaControl color={color} table={table}/>
|
<MediaControl color={color} game={table.game}/>
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user