Audio working for mute / unmute
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
f6b2ada2ee
commit
ea341902c2
@ -9,7 +9,7 @@ import Mic from '@mui/icons-material/Mic';
|
||||
import { GlobalContext } from "./GlobalContext.js";
|
||||
|
||||
/* Proxy object so we can pass in srcObject to <audio> */
|
||||
const Audio = ({ srcObject, paused, muted, ...props }) => {
|
||||
const Audio = ({ srcObject, ...props }) => {
|
||||
const refAudio = useRef(null);
|
||||
useEffect(() => {
|
||||
if (!refAudio.current) {
|
||||
@ -23,7 +23,7 @@ const Audio = ({ srcObject, paused, muted, ...props }) => {
|
||||
refAudio.current.srcObject = undefined;
|
||||
}
|
||||
};
|
||||
}, [srcObject, paused, muted]);
|
||||
}, [srcObject]);
|
||||
return <audio ref={refAudio} {...props} />;
|
||||
}
|
||||
|
||||
@ -87,8 +87,6 @@ const MediaAgent = () => {
|
||||
peers[peer_id] = {
|
||||
connection,
|
||||
attributes: {
|
||||
local: false,
|
||||
muted: false
|
||||
}
|
||||
};
|
||||
console.log(`MediaAgent - addPeer - remote`, peers);
|
||||
@ -285,8 +283,6 @@ const MediaAgent = () => {
|
||||
peers[name] = {
|
||||
local: true,
|
||||
attributes: {
|
||||
local: true,
|
||||
muted: false
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -356,7 +352,7 @@ const MediaAgent = () => {
|
||||
peer.attributes.srcObject = stream;
|
||||
if (peer.attributes.srcObject) {
|
||||
peer.attributes.srcObject.getAudioTracks().forEach((track) => {
|
||||
track.enabled = !peer.attributes.muted;
|
||||
track.enabled = !peer.muted;
|
||||
});
|
||||
}
|
||||
audioPeers.push(
|
||||
@ -365,6 +361,18 @@ const MediaAgent = () => {
|
||||
key={`Peer-${id}`}
|
||||
autoPlay='autoplay'
|
||||
controls
|
||||
muted
|
||||
{...peer.attributes}/>
|
||||
);
|
||||
} else {
|
||||
if (peer.muted) {
|
||||
audioPeers.push(
|
||||
<Audio
|
||||
className={peer.local ? 'Local' : 'Remote'}
|
||||
key={`Peer-${id}`}
|
||||
autoPlay='autoplay'
|
||||
controls
|
||||
muted
|
||||
{...peer.attributes}/>
|
||||
);
|
||||
} else {
|
||||
@ -374,11 +382,11 @@ const MediaAgent = () => {
|
||||
key={`Peer-${id}`}
|
||||
autoPlay='autoplay'
|
||||
controls
|
||||
muted={peer.attributes.muted}
|
||||
{...peer.attributes}/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return <div className="MediaAgent">
|
||||
{ audioPeers }
|
||||
@ -399,11 +407,7 @@ const MediaControl = ({isSelf, peer}) => {
|
||||
control.muted = !control.muted;
|
||||
}
|
||||
const update = Object.assign({}, peers);
|
||||
if (isSelf) {
|
||||
update[peer].attributes.muted = control.muted;
|
||||
} else {
|
||||
update[peer].attributes.muted = control.muted;
|
||||
}
|
||||
update[peer].muted = control.muted;
|
||||
console.log(`MediaControl - toggleMute`, update);
|
||||
setPeers(update);
|
||||
event.stopPropagation();
|
||||
|
Loading…
x
Reference in New Issue
Block a user