fix(webrtc): add error handling and ui alerts for background processor initialization

This commit is contained in:
2026-07-06 13:16:01 +00:00
parent e10cb22811
commit b1b41ca5e1
+21 -14
View File
@@ -336,23 +336,30 @@ export const useVoiceStore = create<VoiceState>((set, get) => ({
} }
if (processor) { if (processor) {
if (mode === 'disabled') { try {
await processor.switchTo({ mode: 'disabled' }); if (mode === 'disabled') {
} else if (mode === 'background-blur') { await processor.switchTo({ mode: 'disabled' });
await processor.switchTo({ mode: 'background-blur', blurRadius: 10 }); } else if (mode === 'background-blur') {
} else if (mode === 'virtual-background') { await processor.switchTo({ mode: 'background-blur', blurRadius: 10 });
await processor.switchTo({ mode: 'virtual-background', imagePath: imagePath || 'https://images.unsplash.com/photo-1579546929518-9e396f3cc809' }); } else if (mode === 'virtual-background') {
} await processor.switchTo({ mode: 'virtual-background', imagePath: imagePath || 'https://images.unsplash.com/photo-1579546929518-9e396f3cc809' });
}
// attach to camera track if it's running // attach to camera track if it's running
const pub = room.localParticipant.getTrackPublication(Track.Source.Camera); const pub = room.localParticipant.getTrackPublication(Track.Source.Camera);
const track = pub?.track as any; const track = pub?.track as any;
if (track && track.setProcessor) { if (track && track.setProcessor) {
await track.setProcessor(processor); await track.setProcessor(processor);
}
set({ bgMode: mode });
} catch (err) {
console.error('[voice] setBgMode failed:', err);
alert(`Failed to set background effect: ${err instanceof Error ? err.message : err}`);
set({ bgMode: 'disabled' });
} }
} else {
set({ bgMode: mode });
} }
set({ bgMode: mode });
}, },
toggleScreenShare: async () => { toggleScreenShare: async () => {