mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 18:10:47 -04:00
yay!
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||||
<title>Multi Roomba Rover</title>
|
<title>Multi Roomba Rover</title>
|
||||||
<script type="module" crossorigin src="/assets/index-DcrX1ADu.js"></script>
|
<script type="module" crossorigin src="/assets/index-frHSA8Fb.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-Dx4QsRNa.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-Dx4QsRNa.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ export default function VipAudioUploadCard({
|
|||||||
const [micState, setMicState] = useState('idle');
|
const [micState, setMicState] = useState('idle');
|
||||||
const [message, setMessage] = useState('');
|
const [message, setMessage] = useState('');
|
||||||
const streamRef = useRef(null);
|
const streamRef = useRef(null);
|
||||||
|
const audioTrackRef = useRef(null);
|
||||||
const whipPcRef = useRef(null);
|
const whipPcRef = useRef(null);
|
||||||
const micActiveRef = useRef(false);
|
const micActiveRef = useRef(false);
|
||||||
const activeRoverRef = useRef('');
|
const activeRoverRef = useRef('');
|
||||||
@@ -258,6 +259,7 @@ export default function VipAudioUploadCard({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
streamRef.current = null;
|
streamRef.current = null;
|
||||||
|
audioTrackRef.current = null;
|
||||||
if (target) {
|
if (target) {
|
||||||
try {
|
try {
|
||||||
await stopMicWhip?.(target);
|
await stopMicWhip?.(target);
|
||||||
@@ -291,6 +293,10 @@ export default function VipAudioUploadCard({
|
|||||||
streamRef.current = stream;
|
streamRef.current = stream;
|
||||||
|
|
||||||
const track = stream.getAudioTracks()?.[0];
|
const track = stream.getAudioTracks()?.[0];
|
||||||
|
audioTrackRef.current = track || null;
|
||||||
|
if (track) {
|
||||||
|
track.enabled = Boolean(openMicEnabled || pttActive);
|
||||||
|
}
|
||||||
if (track?.applyConstraints) {
|
if (track?.applyConstraints) {
|
||||||
try {
|
try {
|
||||||
await track.applyConstraints({
|
await track.applyConstraints({
|
||||||
@@ -307,6 +313,18 @@ export default function VipAudioUploadCard({
|
|||||||
|
|
||||||
const pc = new RTCPeerConnection(RTC_CONFIG);
|
const pc = new RTCPeerConnection(RTC_CONFIG);
|
||||||
whipPcRef.current = pc;
|
whipPcRef.current = pc;
|
||||||
|
pc.onconnectionstatechange = () => {
|
||||||
|
if (!micActiveRef.current) return;
|
||||||
|
const state = pc.connectionState;
|
||||||
|
if (state === 'connected') {
|
||||||
|
setMicState('live');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (state === 'failed' || state === 'disconnected' || state === 'closed') {
|
||||||
|
setMicState('error');
|
||||||
|
setMessage(`WHIP transport ${state}.`);
|
||||||
|
}
|
||||||
|
};
|
||||||
stream.getAudioTracks().forEach((audioTrack) => {
|
stream.getAudioTracks().forEach((audioTrack) => {
|
||||||
const sender = pc.addTrack(audioTrack, stream);
|
const sender = pc.addTrack(audioTrack, stream);
|
||||||
configureSenderForLowLatency(sender);
|
configureSenderForLowLatency(sender);
|
||||||
@@ -333,19 +351,19 @@ export default function VipAudioUploadCard({
|
|||||||
await waitForOutboundAudioFlow(pc, 6000);
|
await waitForOutboundAudioFlow(pc, 6000);
|
||||||
await readyMicWhip?.(target);
|
await readyMicWhip?.(target);
|
||||||
},
|
},
|
||||||
[readyMicWhip, startMicWhip],
|
[openMicEnabled, pttActive, readyMicWhip, startMicWhip],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const desiredActive = Boolean(openMicEnabled || pttActive);
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
async function syncMicState() {
|
async function syncMicState() {
|
||||||
if (!roverId || !desiredActive) {
|
if (!roverId) {
|
||||||
await stopMicCapture(roverId);
|
await stopMicCapture(activeRoverRef.current);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (micActiveRef.current && activeRoverRef.current === roverId) return;
|
if (micActiveRef.current && activeRoverRef.current === roverId) return;
|
||||||
|
if (!openMicEnabled && !pttActive) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setMicState('starting');
|
setMicState('starting');
|
||||||
@@ -371,6 +389,12 @@ export default function VipAudioUploadCard({
|
|||||||
};
|
};
|
||||||
}, [openMicEnabled, pttActive, roverId, startWhipMic, stopMicCapture]);
|
}, [openMicEnabled, pttActive, roverId, startWhipMic, stopMicCapture]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const track = audioTrackRef.current;
|
||||||
|
if (!track) return;
|
||||||
|
track.enabled = Boolean(openMicEnabled || pttActive);
|
||||||
|
}, [openMicEnabled, pttActive]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
stopMicCapture(activeRoverRef.current || roverId);
|
stopMicCapture(activeRoverRef.current || roverId);
|
||||||
|
|||||||
Reference in New Issue
Block a user