fix(webrtc): add error handling and ui alerts for background processor initialization
This commit is contained in:
+21
-14
@@ -336,23 +336,30 @@ export const useVoiceStore = create<VoiceState>((set, get) => ({
|
||||
}
|
||||
|
||||
if (processor) {
|
||||
if (mode === 'disabled') {
|
||||
await processor.switchTo({ mode: 'disabled' });
|
||||
} else if (mode === 'background-blur') {
|
||||
await processor.switchTo({ mode: 'background-blur', blurRadius: 10 });
|
||||
} else if (mode === 'virtual-background') {
|
||||
await processor.switchTo({ mode: 'virtual-background', imagePath: imagePath || 'https://images.unsplash.com/photo-1579546929518-9e396f3cc809' });
|
||||
}
|
||||
try {
|
||||
if (mode === 'disabled') {
|
||||
await processor.switchTo({ mode: 'disabled' });
|
||||
} else if (mode === 'background-blur') {
|
||||
await processor.switchTo({ mode: 'background-blur', blurRadius: 10 });
|
||||
} 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
|
||||
const pub = room.localParticipant.getTrackPublication(Track.Source.Camera);
|
||||
const track = pub?.track as any;
|
||||
if (track && track.setProcessor) {
|
||||
await track.setProcessor(processor);
|
||||
// attach to camera track if it's running
|
||||
const pub = room.localParticipant.getTrackPublication(Track.Source.Camera);
|
||||
const track = pub?.track as any;
|
||||
if (track && track.setProcessor) {
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user