bug fixed
This commit is contained in:
@@ -164,35 +164,53 @@ export function PhoneSimulator({
|
||||
const enteringMode = (mode: typeof phoneMode) =>
|
||||
phoneMode === mode && lastPhoneMode.current !== mode;
|
||||
|
||||
// Entering important message / capture / hand_off: remember mic state and mute if needed
|
||||
if (enteringMode("important_message") || enteringMode("capture") || enteringMode("hand_off")) {
|
||||
wasMicEnabledRef.current = isMicEnabled;
|
||||
if (isMicEnabled) {
|
||||
localParticipant.setMicrophoneEnabled(false);
|
||||
}
|
||||
}
|
||||
// Exiting important message mode or hand off mode or capture mode
|
||||
else if (
|
||||
(phoneMode !== "important_message" && lastPhoneMode.current === "important_message") ||
|
||||
(phoneMode !== "hand_off" && lastPhoneMode.current === "hand_off") ||
|
||||
(phoneMode !== "capture" && lastPhoneMode.current === "capture")
|
||||
) {
|
||||
// Restore mic to previous state
|
||||
localParticipant.setMicrophoneEnabled(wasMicEnabledRef.current);
|
||||
// Only proceed if connected and localParticipant is available
|
||||
if (roomState !== ConnectionState.Connected || !localParticipant) return;
|
||||
|
||||
// If exiting capture mode, clear processing image
|
||||
if (lastPhoneMode.current === "capture") {
|
||||
setProcessingImage(null);
|
||||
setProcessingSource(null);
|
||||
const updateMicState = async () => {
|
||||
// Entering important message / capture / hand_off: remember mic state and mute if needed
|
||||
if (enteringMode("important_message") || enteringMode("capture") || enteringMode("hand_off")) {
|
||||
wasMicEnabledRef.current = isMicEnabled;
|
||||
if (isMicEnabled) {
|
||||
try {
|
||||
await localParticipant.setMicrophoneEnabled(false);
|
||||
} catch (error) {
|
||||
console.error("Failed to disable microphone:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Enforce mic off in important message mode, hand off mode, or capture mode
|
||||
else if ((phoneMode === "important_message" || phoneMode === "hand_off" || phoneMode === "capture") && isMicEnabled) {
|
||||
localParticipant.setMicrophoneEnabled(false);
|
||||
}
|
||||
// Exiting important message mode or hand off mode or capture mode
|
||||
else if (
|
||||
(phoneMode !== "important_message" && lastPhoneMode.current === "important_message") ||
|
||||
(phoneMode !== "hand_off" && lastPhoneMode.current === "hand_off") ||
|
||||
(phoneMode !== "capture" && lastPhoneMode.current === "capture")
|
||||
) {
|
||||
// Restore mic to previous state
|
||||
try {
|
||||
await localParticipant.setMicrophoneEnabled(wasMicEnabledRef.current);
|
||||
} catch (error) {
|
||||
console.error("Failed to restore microphone:", error);
|
||||
}
|
||||
|
||||
// If exiting capture mode, clear processing image
|
||||
if (lastPhoneMode.current === "capture") {
|
||||
setProcessingImage(null);
|
||||
setProcessingSource(null);
|
||||
}
|
||||
}
|
||||
// Enforce mic off in important message mode, hand off mode, or capture mode
|
||||
else if ((phoneMode === "important_message" || phoneMode === "hand_off" || phoneMode === "capture") && isMicEnabled) {
|
||||
try {
|
||||
await localParticipant.setMicrophoneEnabled(false);
|
||||
} catch (error) {
|
||||
console.error("Failed to disable microphone:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
updateMicState();
|
||||
lastPhoneMode.current = phoneMode;
|
||||
}, [phoneMode, isMicEnabled, localParticipant]);
|
||||
}, [phoneMode, isMicEnabled, localParticipant, roomState]);
|
||||
|
||||
useEffect(() => {
|
||||
const updateTime = () => {
|
||||
@@ -218,10 +236,17 @@ export function PhoneSimulator({
|
||||
);
|
||||
|
||||
const handleMicToggle = async () => {
|
||||
if (isMicEnabled) {
|
||||
await localParticipant.setMicrophoneEnabled(false);
|
||||
} else {
|
||||
await localParticipant.setMicrophoneEnabled(true);
|
||||
if (roomState !== ConnectionState.Connected || !localParticipant) return;
|
||||
|
||||
try {
|
||||
if (isMicEnabled) {
|
||||
await localParticipant.setMicrophoneEnabled(false);
|
||||
} else {
|
||||
await localParticipant.setMicrophoneEnabled(true);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to toggle microphone:", error);
|
||||
// Silently handle the error to avoid disrupting user experience
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -118,9 +118,25 @@ export default function Playground({
|
||||
}, [onConnect, cleanupRpcResolvers]);
|
||||
|
||||
useEffect(() => {
|
||||
if (roomState === ConnectionState.Connected) {
|
||||
localParticipant.setCameraEnabled(config.settings.inputs.camera);
|
||||
localParticipant.setMicrophoneEnabled(config.settings.inputs.mic);
|
||||
if (roomState === ConnectionState.Connected && localParticipant) {
|
||||
try {
|
||||
localParticipant.setCameraEnabled(config.settings.inputs.camera);
|
||||
localParticipant.setMicrophoneEnabled(config.settings.inputs.mic);
|
||||
} catch (error) {
|
||||
console.error("Failed to set camera/microphone:", error);
|
||||
// Retry after a short delay if connection might not be fully ready
|
||||
const retryTimeout = setTimeout(() => {
|
||||
if (roomState === ConnectionState.Connected && localParticipant) {
|
||||
try {
|
||||
localParticipant.setCameraEnabled(config.settings.inputs.camera);
|
||||
localParticipant.setMicrophoneEnabled(config.settings.inputs.mic);
|
||||
} catch (retryError) {
|
||||
console.error("Failed to set camera/microphone on retry:", retryError);
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
return () => clearTimeout(retryTimeout);
|
||||
}
|
||||
}
|
||||
}, [config.settings.inputs.camera, config.settings.inputs.mic, localParticipant, roomState]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user