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";
|
import { GlobalContext } from "./GlobalContext.js";
|
||||||
|
|
||||||
/* Proxy object so we can pass in srcObject to <audio> */
|
/* Proxy object so we can pass in srcObject to <audio> */
|
||||||
const Audio = ({ srcObject, paused, muted, ...props }) => {
|
const Audio = ({ srcObject, ...props }) => {
|
||||||
const refAudio = useRef(null);
|
const refAudio = useRef(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!refAudio.current) {
|
if (!refAudio.current) {
|
||||||
@ -23,7 +23,7 @@ const Audio = ({ srcObject, paused, muted, ...props }) => {
|
|||||||
refAudio.current.srcObject = undefined;
|
refAudio.current.srcObject = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [srcObject, paused, muted]);
|
}, [srcObject]);
|
||||||
return <audio ref={refAudio} {...props} />;
|
return <audio ref={refAudio} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +87,6 @@ const MediaAgent = () => {
|
|||||||
peers[peer_id] = {
|
peers[peer_id] = {
|
||||||
connection,
|
connection,
|
||||||
attributes: {
|
attributes: {
|
||||||
local: false,
|
|
||||||
muted: false
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log(`MediaAgent - addPeer - remote`, peers);
|
console.log(`MediaAgent - addPeer - remote`, peers);
|
||||||
@ -285,8 +283,6 @@ const MediaAgent = () => {
|
|||||||
peers[name] = {
|
peers[name] = {
|
||||||
local: true,
|
local: true,
|
||||||
attributes: {
|
attributes: {
|
||||||
local: true,
|
|
||||||
muted: false
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -356,7 +352,7 @@ const MediaAgent = () => {
|
|||||||
peer.attributes.srcObject = stream;
|
peer.attributes.srcObject = stream;
|
||||||
if (peer.attributes.srcObject) {
|
if (peer.attributes.srcObject) {
|
||||||
peer.attributes.srcObject.getAudioTracks().forEach((track) => {
|
peer.attributes.srcObject.getAudioTracks().forEach((track) => {
|
||||||
track.enabled = !peer.attributes.muted;
|
track.enabled = !peer.muted;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
audioPeers.push(
|
audioPeers.push(
|
||||||
@ -365,18 +361,30 @@ const MediaAgent = () => {
|
|||||||
key={`Peer-${id}`}
|
key={`Peer-${id}`}
|
||||||
autoPlay='autoplay'
|
autoPlay='autoplay'
|
||||||
controls
|
controls
|
||||||
|
muted
|
||||||
{...peer.attributes}/>
|
{...peer.attributes}/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
audioPeers.push(
|
if (peer.muted) {
|
||||||
<Audio
|
audioPeers.push(
|
||||||
className={peer.local ? 'Local' : 'Remote'}
|
<Audio
|
||||||
key={`Peer-${id}`}
|
className={peer.local ? 'Local' : 'Remote'}
|
||||||
autoPlay='autoplay'
|
key={`Peer-${id}`}
|
||||||
controls
|
autoPlay='autoplay'
|
||||||
muted={peer.attributes.muted}
|
controls
|
||||||
{...peer.attributes}/>
|
muted
|
||||||
);
|
{...peer.attributes}/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
audioPeers.push(
|
||||||
|
<Audio
|
||||||
|
className={peer.local ? 'Local' : 'Remote'}
|
||||||
|
key={`Peer-${id}`}
|
||||||
|
autoPlay='autoplay'
|
||||||
|
controls
|
||||||
|
{...peer.attributes}/>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,11 +407,7 @@ const MediaControl = ({isSelf, peer}) => {
|
|||||||
control.muted = !control.muted;
|
control.muted = !control.muted;
|
||||||
}
|
}
|
||||||
const update = Object.assign({}, peers);
|
const update = Object.assign({}, peers);
|
||||||
if (isSelf) {
|
update[peer].muted = control.muted;
|
||||||
update[peer].attributes.muted = control.muted;
|
|
||||||
} else {
|
|
||||||
update[peer].attributes.muted = control.muted;
|
|
||||||
}
|
|
||||||
console.log(`MediaControl - toggleMute`, update);
|
console.log(`MediaControl - toggleMute`, update);
|
||||||
setPeers(update);
|
setPeers(update);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user