Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(calls): blur intensity & background image support (#2880)

dev-rbcf7e59de35e5
diff --git a/js/app/packages/channel/Call/CallContext.tsx b/js/app/packages/channel/Call/CallContext.tsx
index 2333c50687..822670810a 100644
--- a/js/app/packages/channel/Call/CallContext.tsx
+++ b/js/app/packages/channel/Call/CallContext.tsx
@@ -36,6 +36,24 @@ export type MediaDeviceInfo = {
kind: MediaDeviceKind;
};
+export type BlurIntensity = 'light' | 'medium' | 'heavy';
+
+export type BackgroundEffect =
+ | { type: 'none' }
+ | { type: 'blur'; intensity: BlurIntensity }
+ | { type: 'image'; id: string; path: string };
+
+export const BLUR_RADIUS: Record<BlurIntensity, number> = {
+ light: 5,
+ medium: 10,
+ heavy: 20,
+};
+
+type ImageBackgroundEffect = Extract<BackgroundEffect, { type: 'image' }>;
+
+export const BACKGROUND_IMAGES: (ImageBackgroundEffect & { label: string })[] =
+ [];
+
type CallStoreState = {
connectionState: ConnectionState;
activeChannelId: string | null;
@@ -53,7 +71,7 @@ type CallStoreState = {
activeAudioOutputDeviceId: string | null;
activeVideoInputDeviceId: string | null;
isNoiseSuppressed: boolean;
- isBackgroundBlurred: boolean;
+ backgroundEffect: BackgroundEffect;
// Mirrors the call's `share_with_team` flag. Defaults to true to match the
// server-side default for newly-created calls; synced from the toggle
// endpoint's response on each flip.
@@ -77,16 +95,34 @@ const initialState: CallStoreState = {
activeAudioOutputDeviceId: null,
activeVideoInputDeviceId: null,
isNoiseSuppressed: false,
- isBackgroundBlurred: false,
+ backgroundEffect: { type: 'none' },
isSharedWithTeam: true,
};
-// Persisted across reloads — blur is a privacy preference users expect to
-// stick. Feature-detect at attach time; an unsupported browser simply
-// ignores a truthy stored value.
-const [persistedBlurPref, setPersistedBlurPref] = makePersisted(
- createSignal<boolean>(false),
- { name: 'call.backgroundBlur' }
+// Persisted across reloads — background effect is a privacy preference users
+// expect to stick. Feature-detect at attach time; an unsupported browser
+// simply ignores a stored value.
+const [persistedBackgroundEffect, setPersistedBackgroundEffect] = makePersisted(
+ createSignal<BackgroundEffect>({ type: 'none' }),
+ {
+ name: 'call.backgroundEffect',
+ // This custom deserialize is to handle the previous boolean format
+ deserialize(data) {
+ try {
+ const value = JSON.parse(data);
+
+ if (typeof value === 'boolean') {
+ return value
+ ? { type: 'blur', intensity: 'light' }
+ : { type: 'none' };
+ }
+
+ return value;
+ } catch {
+ return { type: 'none' };
+ }
+ },
+ }
);
// Persisted across reloads — users with hardware noise cancellation (e.g.
@@ -154,10 +190,10 @@ export type CallState = {
isNoiseSuppressed: () => boolean;
/** Toggle Krisp noise suppression on/off */
toggleNoiseSuppression: () => Promise<void>;
- /** Whether background blur is active on the local camera track */
- isBackgroundBlurred: () => boolean;
- /** Toggle background blur on/off for the local camera track */
- toggleBackgroundBlur: () => Promise<void>;
+ /** Current background effect (none, blur, or image) */
+ backgroundEffect: () => BackgroundEffect;
+ /** Set the background effect (blur with intensity or image background) */
+ setBackgroundEffect: (effect: BackgroundEffect) => Promise<void>;
/** Whether the call is currently shared with the creator's team */
isSharedWithTeam: () => boolean;
/** Update the locally-cached share-with-team flag (call after a toggle RPC) */
@@ -186,7 +222,7 @@ function createCallState() {
const [room, setRoom] = createSignal<Room | null>(null);
const [store, setStore] = createStore<CallStoreState>({
...initialState,
- isBackgroundBlurred: persistedBlurPref(),
+ backgroundEffect: persistedBackgroundEffect(),
isNoiseSuppressed: persistedNoiseSuppressionPref(),
});
const [krispFilter, setKrispFilter] = createSignal<ReturnType<
@@ -246,47 +282,71 @@ function createCallState() {
}
/**
- * (Re-)attach the background blur processor to the current camera track.
+ * (Re-)attach the background effect processor to the current camera track.
* Dynamic-imports @livekit/track-processors so the MediaPipe WASM/model
- * payload is only fetched when the user actually enables blur.
+ * payload is only fetched when the user actually enables an effect.
+ *
+ * If a processor already exists and forceRecreate is false, uses switchTo()
+ * for seamless transitions. When the track changes (camera switch, video
+ * toggle), pass forceRecreate=true to destroy and recreate the processor.
*
* Returns true on success or when there's no live camera track yet (the
* processor will be attached later by the video-(un)mute / device-switch
* paths). Returns false when the browser does not actually support the
* processor at runtime, or attachment throws — callers that set
- * `isBackgroundBlurred` optimistically should revert it in that case.
+ * backgroundEffect optimistically should revert it in that case.
*/
- async function ensureBlurOnCameraTrack(r: Room): Promise<boolean> {
- if (!store.isBackgroundBlurred) return true;
+ async function ensureBackgroundEffectOnCameraTrack(
+ r: Room,
+ forceRecreate = false
+ ): Promise<boolean> {
+ const effect = store.backgroundEffect;
+ if (effect.type === 'none') return true;
const camPub = r.localParticipant.getTrackPublication(Track.Source.Camera);
if (!camPub?.track) return true;
+ const processorOptions =
+ effect.type === 'blur'
+ ? {
+ mode: 'background-blur' as const,
+ blurRadius: BLUR_RADIUS[effect.intensity],
+ }
+ : { mode: 'virtual-background' as const, imagePath: effect.path };
+
try {
- // Destroy the old instance — processors are bound to a specific
- // MediaStreamTrack instance, so a fresh track needs a fresh processor.
- const prev = blurProcessor();
- if (prev) await prev.destroy();
+ const existing = blurProcessor();
+ // If we have a processor and the track hasn't changed, use switchTo()
+ // for a seamless transition without destroying and recreating.
+ if (existing && !forceRecreate) {
+ await existing.switchTo(processorOptions);
+ return true;
+ }
+
+ // Destroy old processor if it exists (track changed or force recreate)
+ if (existing) {
+ await existing.destroy();
+ setBlurProcessor(null);
+ }
+
+ // Create and attach a new processor.
const { BackgroundProcessor, ProcessorWrapper } = await import(
'@livekit/track-processors'
);
if (!ProcessorWrapper.isSupported) return false;
- const processor = BackgroundProcessor({
- mode: 'background-blur',
- blurRadius: 10,
- });
+ const processor = BackgroundProcessor(processorOptions);
await (camPub.track as LocalTrack).setProcessor(processor);
setBlurProcessor(processor);
return true;
} catch (e) {
- console.error('failed to attach background blur processor', e);
+ console.error('failed to attach background effect processor', e);
return false;
}
}
- async function detachBlurFromCameraTrack(r: Room) {
+ async function detachBackgroundEffectFromCameraTrack(r: Room) {
const prev = blurProcessor();
if (prev) {
try {
@@ -298,7 +358,7 @@ function createCallState() {
}
await prev.destroy();
} catch (e) {
- console.error('failed to detach background blur processor', e);
+ console.error('failed to detach background effect processor', e);
}
setBlurProcessor(null);
}
@@ -316,7 +376,7 @@ function createCallState() {
function resetState() {
setStore({
...initialState,
- isBackgroundBlurred: persistedBlurPref(),
+ backgroundEffect: persistedBackgroundEffect(),
isNoiseSuppressed: persistedNoiseSuppressionPref(),
});
}
@@ -501,8 +561,8 @@ function createCallState() {
await r.localParticipant.setCameraEnabled(true, {
deviceId: { exact: deviceId },
});
- // New track was created — re-attach the blur processor if enabled.
- await ensureBlurOnCameraTrack(r);
+ // New track was created — re-attach the background effect processor if enabled.
+ await ensureBackgroundEffectOnCameraTrack(r, true);
}
} catch (e) {
console.error('failed to switch video input device', e);
@@ -641,8 +701,8 @@ function createCallState() {
setStore('activeVideoInputDeviceId', settings.deviceId);
}
}
- // New camera track was created — attach blur processor if preference is on.
- await ensureBlurOnCameraTrack(r);
+ // New camera track was created — attach background effect processor if preference is on.
+ await ensureBackgroundEffectOnCameraTrack(r, true);
}
setStore('isVideoMuted', newMuted);
} catch (e) {
@@ -685,24 +745,24 @@ function createCallState() {
}
}
- async function toggleBackgroundBlur() {
- const newEnabled = !store.isBackgroundBlurred;
- setStore('isBackgroundBlurred', newEnabled);
- setPersistedBlurPref(newEnabled);
+ async function setBackgroundEffect(effect: BackgroundEffect) {
+ const prevEffect = store.backgroundEffect;
+ setStore('backgroundEffect', effect);
+ setPersistedBackgroundEffect(effect);
const r = room();
if (!r) return;
- if (newEnabled) {
- const attached = await ensureBlurOnCameraTrack(r);
+ if (effect.type !== 'none') {
+ const attached = await ensureBackgroundEffectOnCameraTrack(r);
if (!attached) {
// Processor is unsupported or failed to attach — revert so the UI
- // doesn't show "blur on" with no processor actually active.
- setStore('isBackgroundBlurred', false);
- setPersistedBlurPref(false);
+ // doesn't show an effect with no processor actually active.
+ setStore('backgroundEffect', prevEffect);
+ setPersistedBackgroundEffect(prevEffect);
}
} else {
- await detachBlurFromCameraTrack(r);
+ await detachBackgroundEffectFromCameraTrack(r);
}
}
@@ -771,8 +831,8 @@ function createCallState() {
switchVideoInput,
isNoiseSuppressed: () => store.isNoiseSuppressed,
toggleNoiseSuppression,
- isBackgroundBlurred: () => store.isBackgroundBlurred,
- toggleBackgroundBlur,
+ backgroundEffect: () => store.backgroundEffect,
+ setBackgroundEffect,
isSharedWithTeam: () => store.isSharedWithTeam,
setSharedWithTeam,
};
diff --git a/js/app/packages/channel/Call/CallOverlay.tsx b/js/app/packages/channel/Call/CallOverlay.tsx
index 349c59cde4..96fc78a903 100644
--- a/js/app/packages/channel/Call/CallOverlay.tsx
+++ b/js/app/packages/channel/Call/CallOverlay.tsx
@@ -21,7 +21,11 @@ import {
} from '@core/component/Menu';
import { Tooltip } from '@core/component/Tooltip';
import { tryMacroId, useDisplayName } from '@core/user';
-import { useCallContext, type MediaDeviceInfo } from './CallContext';
+import {
+ useCallContext,
+ type MediaDeviceInfo,
+ BACKGROUND_IMAGES,
+} from './CallContext';
// Mirrors @livekit/track-processors' supportsBackgroundProcessors() =
// BackgroundProcessor.isSupported && ProcessorWrapper.isSupported. Kept local so the
@@ -220,6 +224,100 @@ function DeviceList(props: {
);
}
+function BackgroundEffectSelector() {
+ const callCtx = useCallContext();
+
+ const currentEffectValue = () => {
+ const effect = callCtx.backgroundEffect();
+ if (effect.type === 'none') return 'none';
+ if (effect.type === 'blur') return `blur-${effect.intensity}`;
+ return `image-${effect.id}`;
+ };
+
+ const handleChange = (value: string) => {
+ if (value === 'none') {
+ callCtx.setBackgroundEffect({ type: 'none' });
+ return;
+ }
+
+ if (value.startsWith('blur-')) {
+ const intensity = value.replace('blur-', '') as
+ | 'light'
+ | 'medium'
+ | 'heavy';
+
+ callCtx.setBackgroundEffect({ type: 'blur', intensity });
+ return;
+ }
+
+ if (value.startsWith('image-')) {
+ const id = value.replace('image-', '');
+ const bg = BACKGROUND_IMAGES.find((b) => b.id === id);
+
+ if (!bg) return;
+
+ callCtx.setBackgroundEffect({
+ type: 'image',
+ id: bg.id,
+ path: bg.path,
+ });
+ }
+ };
+
+ return (
+ <DropdownMenu.RadioGroup
+ value={currentEffectValue()}
+ onChange={handleChange}
+ >
+ <MenuGroup>
+ <GroupLabel>Background</GroupLabel>
+ <MenuItem
+ text="None"
+ selectorType="radio"
+ value="none"
+ groupValue={currentEffectValue()}
+ />
+ </MenuGroup>
+ <MenuGroup>
+ <GroupLabel>Blur</GroupLabel>
+ <MenuItem
+ text="Light"
+ selectorType="radio"
+ value="blur-light"
+ groupValue={currentEffectValue()}
+ />
+ <MenuItem
+ text="Medium"
+ selectorType="radio"
+ value="blur-medium"
+ groupValue={currentEffectValue()}
+ />
+ <MenuItem
+ text="Heavy"
+ selectorType="radio"
+ value="blur-heavy"
+ groupValue={currentEffectValue()}
+ />
+ </MenuGroup>
+ <Show when={BACKGROUND_IMAGES.length}>
+ <MenuGroup>
+ <GroupLabel>Image</GroupLabel>
+ <For each={BACKGROUND_IMAGES}>
+ {(bg) => (
+ <MenuItem
+ text={bg.label}
+ selectorType="radio"
+ value={`image-${bg.id}`}
+ groupValue={currentEffectValue()}
+ />
+ )}
+ </For>
+ </MenuGroup>
+ </Show>
+ </DropdownMenu.RadioGroup>
+ );
+}
+
function ScreenShareTile(props: { participant: RemoteParticipant }) {
const callCtx = useCallContext();
const macroId = () => tryMacroId(props.participant.identity);
@@ -404,16 +502,7 @@ export function CallOverlay(props: { onLeave: () => void }) {
/>
<Show when={isBackgroundBlurSupported()}>
<MenuSeparator />
- <MenuGroup>
- <GroupLabel>Effects</GroupLabel>
- <MenuItem
- text="Blur background"
- selectorType="checkbox"
- checked={callCtx.isBackgroundBlurred()}
- closeOnSelect={false}
- onClick={() => callCtx.toggleBackgroundBlur()}
- />
- </MenuGroup>
+ <BackgroundEffectSelector />
</Show>
</>
}