Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(call): call video blur (#2788)
Will Hutchinson9f11c63cc369
diff --git a/js/app/package.json b/js/app/package.jsonindex 5a971798fd..e0d4b51193 100644--- a/js/app/package.json+++ b/js/app/package.json@@ -49,6 +49,7 @@"@lexical/table": "^0.32.1","@lexical/utils": "^0.32.1","@livekit/krisp-noise-filter": "^0.4.1",+ "@livekit/track-processors": "^0.7.2","@lukemorales/query-key-factory": "^1.3.4","@normy/query-core": "^0.21.0","@phosphor-icons/core": "^2.1.1",diff --git a/js/app/packages/channel/Call/CallContext.tsx b/js/app/packages/channel/Call/CallContext.tsxindex 85b5d3fbb5..c8e2e1d425 100644--- a/js/app/packages/channel/Call/CallContext.tsx+++ b/js/app/packages/channel/Call/CallContext.tsx@@ -11,6 +11,7 @@ import {KrispNoiseFilter,isKrispNoiseFilterSupported,} from '@livekit/krisp-noise-filter';+import type { BackgroundProcessorWrapper } from '@livekit/track-processors';import {createContext,createSignal,@@ -19,6 +20,7 @@ import {type ParentProps,} from 'solid-js';import { createStore } from 'solid-js/store';+import { makePersisted } from '@solid-primitives/storage';import type { CallTokenResponse } from '@service-call/client';export type CallParticipantInfo = {@@ -51,6 +53,7 @@ type CallStoreState = {activeAudioOutputDeviceId: string | null;activeVideoInputDeviceId: string | null;isNoiseSuppressed: boolean;+ isBackgroundBlurred: boolean;// 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.@@ -74,9 +77,18 @@ const initialState: CallStoreState = {activeAudioOutputDeviceId: null,activeVideoInputDeviceId: null,isNoiseSuppressed: false,+ isBackgroundBlurred: false,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' }+);+export type CallState = {/** The LiveKit Room instance, null when not in a call */room: () => Room | null;@@ -134,6 +146,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>;/** 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) */@@ -160,10 +176,15 @@ export function useCallContextOptional(): CallState | undefined {*/function createCallState() {const [room, setRoom] = createSignal<Room | null>(null);- const [store, setStore] = createStore<CallStoreState>({ ...initialState });+ const [store, setStore] = createStore<CallStoreState>({+ ...initialState,+ isBackgroundBlurred: persistedBlurPref(),+ });const [krispFilter, setKrispFilter] = createSignal<ReturnType<typeof KrispNoiseFilter> | null>(null);+ const [blurProcessor, setBlurProcessor] =+ createSignal<BackgroundProcessorWrapper | null>(null);// --- internal helpers ---@@ -196,6 +217,65 @@ function createCallState() {}}+ /**+ * (Re-)attach the background blur 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.+ *+ * 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.+ */+ async function ensureBlurOnCameraTrack(r: Room): Promise<boolean> {+ if (!store.isBackgroundBlurred) return true;++ const camPub = r.localParticipant.getTrackPublication(Track.Source.Camera);+ if (!camPub?.track) return true;++ 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 { BackgroundProcessor, ProcessorWrapper } = await import(+ '@livekit/track-processors'+ );+ if (!ProcessorWrapper.isSupported) return false;++ const processor = BackgroundProcessor({+ mode: 'background-blur',+ blurRadius: 10,+ });+ await (camPub.track as LocalTrack).setProcessor(processor);+ setBlurProcessor(processor);+ return true;+ } catch (e) {+ console.error('failed to attach background blur processor', e);+ return false;+ }+ }++ async function detachBlurFromCameraTrack(r: Room) {+ const prev = blurProcessor();+ if (prev) {+ try {+ const camPub = r.localParticipant.getTrackPublication(+ Track.Source.Camera+ );+ if (camPub?.track) {+ await (camPub.track as LocalTrack).stopProcessor();+ }+ await prev.destroy();+ } catch (e) {+ console.error('failed to detach background blur processor', e);+ }+ setBlurProcessor(null);+ }+ }+function bumpTrackVersion() {setStore('trackVersion', (v) => v + 1);}@@ -206,7 +286,7 @@ function createCallState() {}function resetState() {- setStore({ ...initialState });+ setStore({ ...initialState, isBackgroundBlurred: persistedBlurPref() });}function attachRoomListeners(r: Room) {@@ -241,6 +321,14 @@ function createCallState() {krisp.destroy();setKrispFilter(null);}+ const blur = blurProcessor();+ if (blur) {+ // Fire and forget — we're tearing down the room regardless.+ blur.destroy().catch((e) => {+ console.error('failed to destroy background blur processor', e);+ });+ setBlurProcessor(null);+ }const r = room();if (r) {r.removeAllListeners();@@ -381,6 +469,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);}} catch (e) {console.error('failed to switch video input device', e);@@ -497,6 +587,8 @@ function createCallState() {try {if (newMuted) {await r.localParticipant.setCameraEnabled(false);+ // Track is gone — drop our processor ref so the next enable starts clean.+ setBlurProcessor(null);} else {const deviceId = store.activeVideoInputDeviceId;await r.localParticipant.setCameraEnabled(@@ -515,6 +607,8 @@ function createCallState() {setStore('activeVideoInputDeviceId', settings.deviceId);}}+ // New camera track was created — attach blur processor if preference is on.+ await ensureBlurOnCameraTrack(r);}setStore('isVideoMuted', newMuted);} catch (e) {@@ -550,6 +644,27 @@ function createCallState() {}}+ async function toggleBackgroundBlur() {+ const newEnabled = !store.isBackgroundBlurred;+ setStore('isBackgroundBlurred', newEnabled);+ setPersistedBlurPref(newEnabled);++ const r = room();+ if (!r) return;++ if (newEnabled) {+ const attached = await ensureBlurOnCameraTrack(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);+ }+ } else {+ await detachBlurFromCameraTrack(r);+ }+ }+// --- cleanup ---const handleBeforeUnload = () => {@@ -615,6 +730,8 @@ function createCallState() {switchVideoInput,isNoiseSuppressed: () => store.isNoiseSuppressed,toggleNoiseSuppression,+ isBackgroundBlurred: () => store.isBackgroundBlurred,+ toggleBackgroundBlur,isSharedWithTeam: () => store.isSharedWithTeam,setSharedWithTeam,};diff --git a/js/app/packages/channel/Call/CallOverlay.tsx b/js/app/packages/channel/Call/CallOverlay.tsxindex 19d518f48c..d16ea46da4 100644--- a/js/app/packages/channel/Call/CallOverlay.tsx+++ b/js/app/packages/channel/Call/CallOverlay.tsx@@ -21,6 +21,35 @@ import {import { tryMacroId, useDisplayName } from '@core/user';import { useCallContext, type MediaDeviceInfo } from './CallContext';+// Mirrors @livekit/track-processors' supportsBackgroundProcessors() =+// BackgroundProcessor.isSupported && ProcessorWrapper.isSupported. Kept local so the+// toggle renders without statically importing the WASM/MediaPipe-bearing package.+function isBackgroundBlurSupported(): boolean {+ if (typeof window === 'undefined') return false;+ // BackgroundProcessor.isSupported: OffscreenCanvas, VideoFrame, createImageBitmap, WebGL2.+ if (+ !('OffscreenCanvas' in window) ||+ !('VideoFrame' in window) ||+ !('createImageBitmap' in window)+ ) {+ return false;+ }+ try {+ if (!document.createElement('canvas').getContext('webgl2')) return false;+ } catch {+ return false;+ }+ // ProcessorWrapper.isSupported: modern MediaStreamTrackProcessor API OR canvas+ // captureStream() fallback (Firefox 126+).+ const hasStreamProcessor =+ 'MediaStreamTrackProcessor' in window &&+ 'MediaStreamTrackGenerator' in window;+ const hasFallback =+ typeof HTMLCanvasElement !== 'undefined' &&+ 'captureStream' in HTMLCanvasElement.prototype;+ return hasStreamProcessor || hasFallback;+}+function ParticipantTile(props: { participant: RemoteParticipant }) {const callCtx = useCallContext();const macroId = () => tryMacroId(props.participant.identity);@@ -349,12 +378,27 @@ export function CallOverlay(props: { onLeave: () => void }) {onClick={() => callCtx.toggleVideo()}active={!callCtx.isVideoMuted()}dropdownContent={- <DeviceList- label="Camera"- devices={callCtx.videoInputDevices()}- activeDeviceId={callCtx.activeVideoInputDeviceId()}- onSelect={(id) => callCtx.switchVideoInput(id)}- />+ <>+ <DeviceList+ label="Camera"+ devices={callCtx.videoInputDevices()}+ activeDeviceId={callCtx.activeVideoInputDeviceId()}+ onSelect={(id) => callCtx.switchVideoInput(id)}+ />+ <Show when={isBackgroundBlurSupported()}>+ <MenuSeparator />+ <MenuGroup>+ <GroupLabel>Effects</GroupLabel>+ <MenuItem+ text="Blur background"+ selectorType="checkbox"+ checked={callCtx.isBackgroundBlurred()}+ closeOnSelect={false}+ onClick={() => callCtx.toggleBackgroundBlur()}+ />+ </MenuGroup>+ </Show>+ </>}><Showdiff --git a/js/bun.lock b/js/bun.lockindex 26f84b3199..748ea27c51 100644--- a/js/bun.lock+++ b/js/bun.lock@@ -40,6 +40,7 @@"@lexical/table": "^0.32.1","@lexical/utils": "^0.32.1","@livekit/krisp-noise-filter": "^0.4.1",+ "@livekit/track-processors": "^0.7.2","@lukemorales/query-key-factory": "^1.3.4","@normy/query-core": "^0.21.0","@phosphor-icons/core": "^2.1.1",@@ -832,6 +833,8 @@"@livekit/protocol": ["@livekit/[email protected]", "", { "dependencies": { "@bufbuild/protobuf": "^1.10.0" } }, "sha512-WmMxBTsy4dRBqcrswFwUUlgq3Z0nnhOqKR6tX749Rb/PcB1yBMUtrHxZvcsS6qi3/5+86zHeVG+exmu1sZqfJg=="],+ "@livekit/track-processors": ["@livekit/[email protected]", "", { "dependencies": { "@mediapipe/tasks-vision": "0.10.14" }, "peerDependencies": { "@types/dom-mediacapture-transform": "^0.1.9", "livekit-client": "^1.12.0 || ^2.1.0" } }, "sha512-lzARBKTbBwqycdR/SwTu6//N0l20BzfDd7grxCXl07676SwRApNtZAK1GJjL1m3dCM3KBqH1aVxjMpNcbOw5uQ=="],+"@lukemorales/query-key-factory": ["@lukemorales/[email protected]", "", { "peerDependencies": { "@tanstack/query-core": ">= 4.0.0", "@tanstack/react-query": ">= 4.0.0" } }, "sha512-A3frRDdkmaNNQi6mxIshsDk4chRXWoXa05US8fBo4kci/H+lVmujS6QrwQLLGIkNIRFGjMqp2uKjC4XsLdydRw=="],"@macro-inc/lexical-core": ["@macro-inc/lexical-core@workspace:lexical-core"],@@ -840,6 +843,8 @@"@marijn/find-cluster-break": ["@marijn/[email protected]", "", {}, "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g=="],+ "@mediapipe/tasks-vision": ["@mediapipe/[email protected]", "", {}, "sha512-vOifgZhkndgybdvoRITzRkIueWWSiCKuEUXXK6Q4FaJsFvRJuwgg++vqFUMlL0Uox62U5aEXFhHxlhV7Ja5e3Q=="],+"@napi-rs/wasm-runtime": ["@napi-rs/[email protected]", "", { "dependencies": { "@tybys/wasm-util": "^0.10.1" }, "peerDependencies": { "@emnapi/core": "^1.7.1", "@emnapi/runtime": "^1.7.1" } }, "sha512-3NQNNgA1YSlJb/kMH1ildASP9HW7/7kYnRI2szWJaofaS1hWmbGI4H+d3+22aGzXXN9IJ+n+GiFVcGipJP18ow=="],"@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],@@ -1348,6 +1353,10 @@"@types/dom-mediacapture-record": ["@types/[email protected]", "", {}, "sha512-mUMZLK3NvwRLcAAT9qmcK+9p7tpU2FHdDsntR3YI4+GY88XrgG4XiE7u1Q2LAN2/FZOz/tdMDC3GQCR4T8nFuw=="],+ "@types/dom-mediacapture-transform": ["@types/[email protected]", "", { "dependencies": { "@types/dom-webcodecs": "*" } }, "sha512-Y2p+nGf1bF2XMttBnsVPHUWzRRZzqUoJAKmiP10b5umnO6DDrWI0BrGDJy1pOHoOULVmGSfFNkQrAlC5dcj6nQ=="],++ "@types/dom-webcodecs": ["@types/[email protected]", "", {}, "sha512-vAvE8C9DGWR+tkb19xyjk1TSUlJ7RUzzp4a9Anu7mwBT+fpyePWK1UxmH14tMO5zHmrnrRIMg5NutnnDztLxgg=="],+"@types/es-aggregate-error": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-qJ7LIFp06h1QE1aVxbVd+zJP2wdaugYXYfd6JxsyRMrYHaxb6itXPogW2tz+ylUJ1n1b+JF1PHyYCfYHm0dvUg=="],"@types/estree": ["@types/[email protected]", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="],