@memberjunction/ng-conversations 6.2.0-edge.4 → 6.2.0-edge.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/lib/components/attachment/image-viewer.component.d.ts +3 -1
- package/dist/lib/components/attachment/image-viewer.component.d.ts.map +1 -1
- package/dist/lib/components/attachment/image-viewer.component.js +5 -1
- package/dist/lib/components/attachment/image-viewer.component.js.map +1 -1
- package/dist/lib/components/conversation/conversation-agent-picker.component.d.ts +1 -1
- package/dist/lib/components/conversation/conversation-agent-picker.component.js +3 -3
- package/dist/lib/components/conversation/conversation-agent-picker.component.js.map +1 -1
- package/dist/lib/components/conversation/conversation-chat-area.component.d.ts +88 -20
- package/dist/lib/components/conversation/conversation-chat-area.component.d.ts.map +1 -1
- package/dist/lib/components/conversation/conversation-chat-area.component.js +785 -387
- package/dist/lib/components/conversation/conversation-chat-area.component.js.map +1 -1
- package/dist/lib/components/message/message-input.component.d.ts +60 -20
- package/dist/lib/components/message/message-input.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-input.component.js +290 -389
- package/dist/lib/components/message/message-input.component.js.map +1 -1
- package/dist/lib/components/message/message-item.component.d.ts +153 -17
- package/dist/lib/components/message/message-item.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-item.component.js +1400 -299
- package/dist/lib/components/message/message-item.component.js.map +1 -1
- package/dist/lib/components/message/message-list.component.d.ts +25 -2
- package/dist/lib/components/message/message-list.component.d.ts.map +1 -1
- package/dist/lib/components/message/message-list.component.js +79 -40
- package/dist/lib/components/message/message-list.component.js.map +1 -1
- package/dist/lib/components/overlay/chat-overlay.component.d.ts +19 -0
- package/dist/lib/components/overlay/chat-overlay.component.d.ts.map +1 -1
- package/dist/lib/components/overlay/chat-overlay.component.js +125 -13
- package/dist/lib/components/overlay/chat-overlay.component.js.map +1 -1
- package/dist/lib/components/project/project-form-modal.component.js +2 -2
- package/dist/lib/components/project/project-form-modal.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts +6 -1
- package/dist/lib/components/realtime/realtime-agent-banner.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-agent-banner.component.js +110 -82
- package/dist/lib/components/realtime/realtime-agent-banner.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-call-failure-notice.d.ts +13 -0
- package/dist/lib/components/realtime/realtime-call-failure-notice.d.ts.map +1 -0
- package/dist/lib/components/realtime/realtime-call-failure-notice.js +21 -0
- package/dist/lib/components/realtime/realtime-call-failure-notice.js.map +1 -0
- package/dist/lib/components/realtime/realtime-composer.component.js +114 -102
- package/dist/lib/components/realtime/realtime-composer.component.js.map +1 -1
- package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts +21 -2
- package/dist/lib/components/realtime/realtime-session-overlay.component.d.ts.map +1 -1
- package/dist/lib/components/realtime/realtime-session-overlay.component.js +113 -76
- package/dist/lib/components/realtime/realtime-session-overlay.component.js.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.d.ts.map +1 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js +7 -1
- package/dist/lib/components/realtime/remote-browser/remote-browser-channel.js.map +1 -1
- package/dist/lib/components/sidebar/routines-section.component.js +1 -1
- package/dist/lib/components/sidebar/routines-section.component.js.map +1 -1
- package/dist/lib/components/task/tasks-full-view.component.d.ts +152 -31
- package/dist/lib/components/task/tasks-full-view.component.d.ts.map +1 -1
- package/dist/lib/components/task/tasks-full-view.component.js +2227 -214
- package/dist/lib/components/task/tasks-full-view.component.js.map +1 -1
- package/dist/lib/components/tasks/tasks-dropdown.component.js +4 -4
- package/dist/lib/components/tasks/tasks-dropdown.component.js.map +1 -1
- package/dist/lib/components/workspace/conversation-workspace.component.d.ts +11 -1
- package/dist/lib/components/workspace/conversation-workspace.component.d.ts.map +1 -1
- package/dist/lib/components/workspace/conversation-workspace.component.js +25 -28
- package/dist/lib/components/workspace/conversation-workspace.component.js.map +1 -1
- package/dist/lib/services/agent-state.service.d.ts.map +1 -1
- package/dist/lib/services/agent-state.service.js +8 -8
- package/dist/lib/services/agent-state.service.js.map +1 -1
- package/dist/lib/services/browser-realtime-media-host.d.ts +7 -7
- package/dist/lib/services/browser-realtime-media-host.js +8 -78
- package/dist/lib/services/browser-realtime-media-host.js.map +1 -1
- package/dist/lib/services/conversation-agent.service.d.ts +53 -20
- package/dist/lib/services/conversation-agent.service.d.ts.map +1 -1
- package/dist/lib/services/conversation-agent.service.js +108 -54
- package/dist/lib/services/conversation-agent.service.js.map +1 -1
- package/dist/lib/services/conversation-detail-window.store.d.ts +5 -0
- package/dist/lib/services/conversation-detail-window.store.d.ts.map +1 -1
- package/dist/lib/services/conversation-detail-window.store.js +52 -5
- package/dist/lib/services/conversation-detail-window.store.js.map +1 -1
- package/dist/lib/services/conversation-naming.d.ts.map +1 -1
- package/dist/lib/services/conversation-naming.js +9 -2
- package/dist/lib/services/conversation-naming.js.map +1 -1
- package/dist/lib/services/conversation-tasks-filter.d.ts +15 -0
- package/dist/lib/services/conversation-tasks-filter.d.ts.map +1 -0
- package/dist/lib/services/conversation-tasks-filter.js +69 -0
- package/dist/lib/services/conversation-tasks-filter.js.map +1 -0
- package/dist/lib/services/realtime-audio-recorder.d.ts +94 -86
- package/dist/lib/services/realtime-audio-recorder.d.ts.map +1 -1
- package/dist/lib/services/realtime-audio-recorder.js +222 -195
- package/dist/lib/services/realtime-audio-recorder.js.map +1 -1
- package/dist/lib/services/realtime-session.service.d.ts +30 -2
- package/dist/lib/services/realtime-session.service.d.ts.map +1 -1
- package/dist/lib/services/realtime-session.service.js +35 -7
- package/dist/lib/services/realtime-session.service.js.map +1 -1
- package/dist/lib/services/recording/libopus-wasm-binary.d.ts +3 -0
- package/dist/lib/services/recording/libopus-wasm-binary.d.ts.map +1 -0
- package/dist/lib/services/recording/libopus-wasm-binary.js +489 -0
- package/dist/lib/services/recording/libopus-wasm-binary.js.map +1 -0
- package/dist/lib/services/recording/libopus-worker-source.d.ts +48 -0
- package/dist/lib/services/recording/libopus-worker-source.d.ts.map +1 -0
- package/dist/lib/services/recording/libopus-worker-source.js +170 -0
- package/dist/lib/services/recording/libopus-worker-source.js.map +1 -0
- package/dist/lib/services/recording/linear-resampler.d.ts +45 -0
- package/dist/lib/services/recording/linear-resampler.d.ts.map +1 -0
- package/dist/lib/services/recording/linear-resampler.js +85 -0
- package/dist/lib/services/recording/linear-resampler.js.map +1 -0
- package/dist/lib/services/recording/opus-packet-encoder.d.ts +50 -0
- package/dist/lib/services/recording/opus-packet-encoder.d.ts.map +1 -0
- package/dist/lib/services/recording/opus-packet-encoder.js +41 -0
- package/dist/lib/services/recording/opus-packet-encoder.js.map +1 -0
- package/dist/lib/services/recording/wasm-opus-encoder.d.ts +86 -0
- package/dist/lib/services/recording/wasm-opus-encoder.d.ts.map +1 -0
- package/dist/lib/services/recording/wasm-opus-encoder.js +232 -0
- package/dist/lib/services/recording/wasm-opus-encoder.js.map +1 -0
- package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts +39 -0
- package/dist/lib/services/recording/webcodecs-opus-encoder.d.ts.map +1 -0
- package/dist/lib/services/recording/webcodecs-opus-encoder.js +101 -0
- package/dist/lib/services/recording/webcodecs-opus-encoder.js.map +1 -0
- package/dist/lib/services/search.service.d.ts.map +1 -1
- package/dist/lib/services/search.service.js +3 -16
- package/dist/lib/services/search.service.js.map +1 -1
- package/dist/lib/utils/agent-failure-display.d.ts +14 -0
- package/dist/lib/utils/agent-failure-display.d.ts.map +1 -0
- package/dist/lib/utils/agent-failure-display.js +26 -0
- package/dist/lib/utils/agent-failure-display.js.map +1 -0
- package/dist/lib/utils/distinct-artifacts.d.ts +9 -3
- package/dist/lib/utils/distinct-artifacts.d.ts.map +1 -1
- package/dist/lib/utils/distinct-artifacts.js +24 -5
- package/dist/lib/utils/distinct-artifacts.js.map +1 -1
- package/dist/lib/utils/message-list-order.d.ts +13 -0
- package/dist/lib/utils/message-list-order.d.ts.map +1 -0
- package/dist/lib/utils/message-list-order.js +31 -0
- package/dist/lib/utils/message-list-order.js.map +1 -0
- package/dist/lib/utils/pin-state.d.ts +11 -0
- package/dist/lib/utils/pin-state.d.ts.map +1 -0
- package/dist/lib/utils/pin-state.js +9 -0
- package/dist/lib/utils/pin-state.js.map +1 -0
- package/dist/public-api.d.ts +1 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +1 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +36 -36
- package/dist/lib/services/browser-recording-unload-guard.d.ts +0 -30
- package/dist/lib/services/browser-recording-unload-guard.d.ts.map +0 -1
- package/dist/lib/services/browser-recording-unload-guard.js +0 -43
- package/dist/lib/services/browser-recording-unload-guard.js.map +0 -1
- package/dist/lib/services/realtime-pcm-wav.d.ts +0 -79
- package/dist/lib/services/realtime-pcm-wav.d.ts.map +0 -1
- package/dist/lib/services/realtime-pcm-wav.js +0 -213
- package/dist/lib/services/realtime-pcm-wav.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-audio-recorder.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-audio-recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,qBAAqB;IAC9B,2EAA2E;IACnE,MAAM,CAAU,WAAW,GAAG,WAAW,CAAC;IAClD,4EAA4E;IACpE,MAAM,CAAU,WAAW,GAAG,GAAG,CAAC;IAC1C,mGAAmG;IAC3F,MAAM,CAAU,yBAAyB,GAAG,IAAI,CAAC;IACzD,kGAAkG;IAC1F,MAAM,CAAU,sBAAsB,GAAG;;;;;;;;;;;;KAYhD,CAAC;IAEM,YAAY,GAAwB,IAAI,CAAC;IACzC,WAAW,GAA2C,IAAI,CAAC;IAC3D,WAAW,GAA4B,IAAI,CAAC;IAC5C,UAAU,GAA+B,IAAI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;IACL,CAAC","sourcesContent":["import { EncodePcm16Wav, PeakAccumulator } from './realtime-pcm-wav';\n\n/**\n * Browser-side audio recorder for a CLIENT-DIRECT realtime voice session.\n *\n * Mixes the user's microphone stream with the agent's remote-audio stream (every driver exposes\n * one via `GetRemoteMediaStream()`: WebRTC drivers publish their remote track, PCM drivers —\n * Gemini, ElevenLabs, AssemblyAI, xAI, HuggingFace — publish their playout engine's output) into a\n * single mono **WAV** (16-bit PCM) blob via the Web Audio API. Rather than a `MediaRecorder` (which only emits webm/opus —\n * header-less, no duration/cues, so HTTP-range seeking is unreliable), the mix is routed into an\n * {@link AudioWorkletNode} (preferred) or a {@link ScriptProcessorNode} (fallback) that captures\n * Float32 PCM frames. PCM is accumulated in memory and encoded as a seekable RIFF/WAVE file at\n * {@link Stop}. WAV's header carries the exact duration and maps byte-offset → time linearly, so\n * range seeking is exact and waveform peaks are computed cheaply during capture. The tradeoff is\n * size (PCM WAV is larger than opus) — acceptable for these short session recordings.\n *\n * Robust + MVP by design — every step degrades gracefully:\n * - No `AudioContext` (server-side render / unsupported env) → the recorder disables itself\n * ({@link IsRecording} stays `false`, {@link Stop} resolves `null`); the voice call proceeds.\n * - No `AudioWorkletNode` AND no `ScriptProcessorNode` → disables itself rather than throwing.\n * - No remote stream yet (e.g. the WebRTC track hasn't landed) → records mic only until it does.\n * - A remote stream that can't be connected (e.g. a browser that rejects cross-sample-rate\n * `createMediaStreamSource` — the PCM playout context runs at 24 kHz, this one at the device\n * rate) → warns and records mic only; the mic recording is never lost to the agent stream.\n * - Any construction/start error is logged and disables the recorder rather than throwing into\n * the session-start path.\n *\n * Not an Angular service: it owns transient per-session media plumbing the\n * {@link RealtimeSessionService} creates and discards per call, so a plain class is the right\n * shape (no DI, no singleton).\n */\nexport class RealtimeAudioRecorder {\n /** The container/codec we now produce — a seekable mono 16-bit PCM WAV. */\n private static readonly wavMimeType = 'audio/wav';\n /** Target waveform-peak resolution (buckets) across the whole recording. */\n private static readonly peakBuckets = 600;\n /** PCM frame size for the ScriptProcessor fallback (worklet uses its native 128-frame quantum). */\n private static readonly scriptProcessorBufferSize = 4096;\n /** Inline AudioWorklet processor: forwards each 128-frame mono input block to the main thread. */\n private static readonly workletProcessorSource = `\n class MJPcmCaptureProcessor extends AudioWorkletProcessor {\n process(inputs) {\n const input = inputs[0];\n if (input && input[0] && input[0].length > 0) {\n // Copy out of the reused worklet buffer before posting.\n this.port.postMessage(input[0].slice(0));\n }\n return true;\n }\n }\n registerProcessor('mj-pcm-capture', MJPcmCaptureProcessor);\n `;\n\n private audioContext: AudioContext | null = null;\n private destination: MediaStreamAudioDestinationNode | null = null;\n private workletNode: AudioWorkletNode | null = null;\n private scriptNode: ScriptProcessorNode | null = null;\n /** Captured mono Float32 PCM frames (in capture order); concatenated + encoded to WAV at Stop. */\n private pcmFrames: Float32Array[] = [];\n /** Total captured sample count across {@link pcmFrames} (kept in step to avoid re-summing). */\n private totalSamples = 0;\n /** Streaming waveform-peak accumulator — bounded regardless of recording length. */\n private peaks = new PeakAccumulator(RealtimeAudioRecorder.peakBuckets);\n /** Final normalized peaks, snapshotted at {@link Stop} so {@link GetPeaks} survives cleanup. */\n private finalPeaks: number[] = [];\n private recording = false;\n\n /** True once the agent's remote stream has been wired into the mix (prevents double-attach). */\n private remoteAttached = false;\n /** A remote stream handed to AttachRemoteStream before the audio graph was ready; wired at setup. */\n private pendingRemoteStream: MediaStream | null = null;\n /** The microphone to record: the latest stream given to Start or ReplaceMicrophone. Setup connects it. */\n private micStream: MediaStream | null = null;\n /** The source node reading the microphone, swapped by ReplaceMicrophone. */\n private micSource: MediaStreamAudioSourceNode | null = null;\n\n /** Sample index up to which crash-recovery shards have already been emitted (the segment cursor). */\n private flushedSampleCount = 0;\n\n /** Wall-clock ms at recording start; anchors {@link NowOffsetMs}. 0 before {@link Start}. */\n private startedAtMs = 0;\n\n /** Sample rate of the capturing {@link AudioContext}; 0 before {@link Start}. Needed to wrap shards. */\n private sampleRate = 0;\n\n /**\n * Bumped by {@link cleanup}. The async setup snapshots it and, after each await, gives up if it moved:\n * a {@link Stop} that lands mid-setup can only release what setup has already published, so setup\n * must release the rest itself rather than build a live graph on a stopped recorder.\n */\n private setupGeneration = 0;\n\n /** True while a recorder is actively capturing. */\n public get IsRecording(): boolean {\n return this.recording;\n }\n\n /** Wall-clock ms when recording started (0 before {@link Start}). */\n public get StartedAtMs(): number {\n return this.startedAtMs;\n }\n\n /**\n * The container/codec the active recording uses. Always `'audio/wav'` once recording (empty\n * string before {@link Start} / when disabled) — the consolidated upload and the WAV-wrapped\n * crash-recovery shards are all 16-bit PCM WAV.\n */\n public get MimeType(): string {\n return this.recording ? RealtimeAudioRecorder.wavMimeType : '';\n }\n\n /**\n * The captured AudioContext sample rate (0 before {@link Start} / when disabled). Exposed so a\n * recovery path can WAV-wrap the raw-PCM shards with the correct rate.\n */\n public get SampleRate(): number {\n return this.sampleRate;\n }\n\n /**\n * Begins recording a mix of `micStream` and (when present) `remoteStream`. Best-effort:\n * a missing `AudioContext` / no worklet+scriptprocessor support / any setup failure disables\n * the recorder silently (logged) so the live call is never blocked.\n *\n * @param micStream The user's microphone capture stream (required).\n * @param remoteStream The agent's remote-audio stream, or `null` for mic-only capture.\n */\n public Start(micStream: MediaStream, remoteStream: MediaStream | null): void {\n if (this.recording) {\n return;\n }\n if (typeof AudioContext === 'undefined') {\n console.warn('[RealtimeAudioRecorder] AudioContext unavailable — recording disabled for this session.');\n return;\n }\n // Mark recording + stamp t0 SYNCHRONOUSLY so a caller that checks IsRecording immediately after\n // Start() (the session service does) sees `true`, even though the audio-graph setup\n // (AudioContext.resume + worklet module load) completes asynchronously below. Without this the\n // caller discards the recorder before it finishes starting and nothing is ever uploaded.\n this.startedAtMs = Date.now();\n this.finalPeaks = [];\n this.recording = true;\n this.micStream = micStream;\n // Fire-and-forget the async setup (it must `await audioContext.resume()` + worklet load); any\n // failure disables the recorder rather than throwing into the session-start path.\n void this.startMixedRecording(micStream, remoteStream).catch((error) => {\n console.warn('[RealtimeAudioRecorder] Failed to start recording — disabling for this session:', error);\n this.cleanup();\n });\n }\n\n /**\n * Wires the agent's remote-audio stream into the live mix once it arrives. The WebRTC\n * `ontrack` that delivers the agent voice usually lands AFTER recording has already begun\n * (mic-only), so the session attaches it here when it lands. Idempotent, and safe to call\n * before the audio graph finishes its async setup (the stream is connected once ready).\n */\n public AttachRemoteStream(stream: MediaStream): void {\n if (this.remoteAttached || stream.getAudioTracks().length === 0) {\n return;\n }\n if (this.audioContext && this.captureNode()) {\n this.remoteAttached = this.connectRemoteStream(this.audioContext, stream);\n } else {\n // Audio-graph setup still in flight (awaiting resume / worklet load) — connect at setup.\n this.pendingRemoteStream = stream;\n }\n }\n\n /**\n * Records the microphone stream's current track from now on: call it after the track changes (a\n * device switch). A source node reads the track it was created with, so the recording would otherwise\n * carry silence from the old device. Safe before the audio graph is ready (setup connects the latest\n * stream, and Start replaces it); a stream without an audio track keeps the current one.\n */\n public ReplaceMicrophone(micStream: MediaStream): void {\n this.micStream = micStream;\n if (!this.audioContext || !this.captureNode()) {\n return;\n }\n const replacement = this.connectStream(this.audioContext, micStream);\n if (replacement) {\n this.micSource?.disconnect();\n this.micSource = replacement;\n }\n }\n\n /**\n * Returns a Blob of the raw PCM captured since the last call (a window of header-less,\n * little-endian PCM16 bytes), advancing the segment cursor. `null` when nothing new. Used to\n * upload crash-recovery shards mid-call. NOTE: shards are header-less raw PCM (NOT individually\n * playable WAV) — recovery is concatenation in order, then WAV-wrapping with {@link SampleRate}.\n * The canonical consolidated file is still authored as a single WAV from full memory at {@link Stop}.\n */\n public SnapshotNewSegment(): Blob | null {\n if (!this.recording || this.flushedSampleCount >= this.totalSamples) {\n return null;\n }\n const fresh = this.collectSamples(this.flushedSampleCount, this.totalSamples);\n this.flushedSampleCount = this.totalSamples;\n if (fresh.length === 0) {\n return null;\n }\n const pcm16 = this.floatToPcm16Bytes(fresh);\n return new Blob([pcm16], { type: 'application/octet-stream' });\n }\n\n /** Ms elapsed since recording started (>= 0); 0 when not recording. */\n public NowOffsetMs(): number {\n if (this.startedAtMs === 0) {\n return 0;\n }\n return Math.max(0, Date.now() - this.startedAtMs);\n }\n\n /**\n * The downsampled waveform peaks (each 0..1, max-abs per bucket, ~{@link RealtimeAudioRecorder.PeakBuckets}\n * buckets across the whole recording). Computed incrementally during capture so it's cheap and\n * bounded regardless of length. Returns `[]` before any audio / for a silent recording. Safe to\n * call after {@link Stop} — the peaks are snapshotted there before {@link cleanup} clears state.\n */\n public GetPeaks(): number[] {\n return this.recording ? this.peaks.Normalize() : this.finalPeaks;\n }\n\n /**\n * Stops recording and resolves the captured audio as a single mono 16-bit PCM **WAV**\n * {@link Blob}, then releases the audio graph. Resolves `null` when nothing was recorded\n * (recorder disabled, or no samples captured). Safe to call when not recording.\n */\n public async Stop(): Promise<Blob | null> {\n if (!this.recording) {\n this.cleanup();\n return null;\n }\n // Detach the capture node so no further frames arrive while we assemble the file. Snapshot the\n // peaks BEFORE cleanup so GetPeaks() still returns them for the post-Stop upload.\n this.recording = false;\n this.finalPeaks = this.peaks.Normalize();\n const blob = this.encodeWavBlob();\n this.cleanup();\n return blob;\n }\n\n /** Wires up the Web Audio mix graph + PCM capture node (worklet preferred) and starts capture. */\n private async startMixedRecording(micStream: MediaStream, remoteStream: MediaStream | null): Promise<void> {\n const generation = this.setupGeneration;\n const audioContext = new AudioContext();\n // CRITICAL: browsers create an AudioContext in the `suspended` state under the autoplay policy.\n // Without resuming it, the mix graph never processes audio and we capture only silence. Starting\n // a voice call is a user gesture, so resume() succeeds here.\n if (audioContext.state === 'suspended') {\n await audioContext.resume();\n }\n if (generation !== this.setupGeneration) {\n // Stopped while resuming: the context was never published, so cleanup() could not close it.\n void audioContext.close().catch(() => { /* already closed */ });\n return;\n }\n const destination = audioContext.createMediaStreamDestination();\n // Publish the context + sample rate BEFORE wiring the remote so a concurrent AttachRemoteStream()\n // (the agent track can land during the awaits above) sees a ready graph to connect to.\n this.audioContext = audioContext;\n this.destination = destination;\n this.sampleRate = audioContext.sampleRate;\n\n // Build the PCM capture node: AudioWorklet preferred, ScriptProcessor fallback. Either way the\n // node both pulls audio from the mix AND drives the destination so the graph keeps processing.\n await this.createCaptureNode(audioContext, destination);\n if (generation !== this.setupGeneration) {\n return; // Stopped while the capture node loaded: cleanup() already closed the published context.\n }\n\n // The microphone may have been replaced while the graph was being built.\n this.micSource = this.connectStream(audioContext, this.micStream ?? micStream);\n // Connect the agent's stream if it was passed now, or if AttachRemoteStream() stashed one while\n // we were setting up. Either way, capture the agent voice — not just the mic.\n const remote = remoteStream ?? this.pendingRemoteStream;\n this.pendingRemoteStream = null;\n if (remote && remote.getAudioTracks().length > 0) {\n this.remoteAttached = this.connectRemoteStream(audioContext, remote);\n }\n }\n\n /**\n * Connects the agent stream, degrading to mic-only on failure. Unlike the mic (whose failure\n * rightly disables the recorder), the agent stream is best-effort: a browser may reject it\n * (cross-sample-rate `NotSupportedError`) and that must not discard the user's recording.\n * Returns whether it was connected, so the caller only marks it attached on success.\n */\n private connectRemoteStream(audioContext: AudioContext, stream: MediaStream): boolean {\n try {\n this.connectStream(audioContext, stream);\n return true;\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] Could not mix the agent stream into the recording — continuing mic-only:', error);\n return false;\n }\n }\n\n /**\n * Creates the PCM capture node and inserts it into the graph: sources → captureNode → destination.\n * Prefers an {@link AudioWorkletNode} (off-main-thread, no deprecation); falls back to a\n * {@link ScriptProcessorNode} where worklets are unavailable. Throws when neither is supported\n * (caught by {@link Start}, which then disables the recorder).\n */\n private async createCaptureNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): Promise<void> {\n if (await this.tryCreateWorkletNode(audioContext, destination)) {\n return;\n }\n this.createScriptProcessorNode(audioContext, destination);\n }\n\n /** Attempts to build the AudioWorklet capture node; returns `false` (no throw) when unsupported. */\n private async tryCreateWorkletNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): Promise<boolean> {\n if (!audioContext.audioWorklet || typeof AudioWorkletNode === 'undefined' || typeof Blob === 'undefined') {\n return false;\n }\n try {\n const moduleUrl = URL.createObjectURL(\n new Blob([RealtimeAudioRecorder.workletProcessorSource], { type: 'application/javascript' }),\n );\n try {\n await audioContext.audioWorklet.addModule(moduleUrl);\n } finally {\n URL.revokeObjectURL(moduleUrl);\n }\n const node = new AudioWorkletNode(audioContext, 'mj-pcm-capture', { numberOfInputs: 1, numberOfOutputs: 1 });\n node.port.onmessage = (event: MessageEvent<Float32Array>) => this.captureFrame(event.data);\n node.connect(destination);\n this.workletNode = node;\n return true;\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] AudioWorklet unavailable — falling back to ScriptProcessor:', error);\n return false;\n }\n }\n\n /** Builds the ScriptProcessor fallback capture node and inserts it into the graph. */\n private createScriptProcessorNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): void {\n if (typeof audioContext.createScriptProcessor !== 'function') {\n throw new Error('Neither AudioWorklet nor ScriptProcessor is supported');\n }\n const node = audioContext.createScriptProcessor(RealtimeAudioRecorder.scriptProcessorBufferSize, 1, 1);\n node.onaudioprocess = (event: AudioProcessingEvent) => {\n // Copy out of the reused input buffer before retaining.\n this.captureFrame(event.inputBuffer.getChannelData(0).slice(0));\n };\n // ScriptProcessor only fires onaudioprocess while connected to the destination.\n node.connect(destination);\n this.scriptNode = node;\n }\n\n /** The active capture node (worklet or script processor), or `null` before setup. */\n private captureNode(): AudioNode | null {\n return this.workletNode ?? this.scriptNode;\n }\n\n /** Absorbs one captured PCM frame: accumulate samples + update the bounded peak array. */\n private captureFrame(frame: Float32Array): void {\n if (!this.recording || frame.length === 0) {\n return;\n }\n // Defensive copy — worklet/script buffers are reused by the engine.\n const copy = frame.slice(0);\n this.pcmFrames.push(copy);\n this.totalSamples += copy.length;\n this.peaks.Push(copy);\n }\n\n /** Routes one stream's audio tracks into the capture node; returns the source, or null when track-less / no node. */\n private connectStream(audioContext: AudioContext, stream: MediaStream): MediaStreamAudioSourceNode | null {\n const node = this.captureNode();\n if (!node || stream.getAudioTracks().length === 0) {\n return null;\n }\n const source = audioContext.createMediaStreamSource(stream);\n source.connect(node);\n return source;\n }\n\n /** Concatenates a half-open sample range [from, to) across the captured frames into one Float32Array. */\n private collectSamples(from: number, to: number): Float32Array {\n const out = new Float32Array(Math.max(0, to - from));\n if (out.length === 0) {\n return out;\n }\n let cursor = 0; // absolute sample index at the start of the current frame\n let written = 0;\n for (const frame of this.pcmFrames) {\n const frameStart = cursor;\n const frameEnd = cursor + frame.length;\n cursor = frameEnd;\n if (frameEnd <= from) {\n continue; // entirely before the window\n }\n if (frameStart >= to) {\n break; // entirely after the window\n }\n const sliceStart = Math.max(0, from - frameStart);\n const sliceEnd = Math.min(frame.length, to - frameStart);\n for (let i = sliceStart; i < sliceEnd; i++) {\n out[written++] = frame[i];\n }\n }\n return written === out.length ? out : out.subarray(0, written);\n }\n\n /**\n * Converts a mono Float32 buffer to a little-endian PCM16 `ArrayBuffer` (for raw crash-recovery\n * shards). Returns the backing `ArrayBuffer` directly so it's a valid `BlobPart`.\n */\n private floatToPcm16Bytes(samples: Float32Array): ArrayBuffer {\n const buffer = new ArrayBuffer(samples.length * 2);\n const view = new DataView(buffer);\n for (let i = 0; i < samples.length; i++) {\n const s = samples[i] < -1 ? -1 : samples[i] > 1 ? 1 : samples[i];\n view.setInt16(i * 2, s < 0 ? s * 0x8000 : s * 0x7fff, true);\n }\n return buffer;\n }\n\n /** Encodes all accumulated PCM into a single seekable WAV blob, or `null` when nothing captured. */\n private encodeWavBlob(): Blob | null {\n if (this.totalSamples === 0 || this.sampleRate === 0) {\n return null;\n }\n const all = this.collectSamples(0, this.totalSamples);\n const wav = EncodePcm16Wav(all, this.sampleRate);\n return new Blob([wav], { type: RealtimeAudioRecorder.wavMimeType });\n }\n\n /** Releases the audio graph + capture node and resets state. Idempotent. */\n private cleanup(): void {\n this.setupGeneration++;\n this.recording = false;\n this.pcmFrames = [];\n this.totalSamples = 0;\n this.flushedSampleCount = 0;\n this.sampleRate = 0;\n this.peaks = new PeakAccumulator(RealtimeAudioRecorder.peakBuckets);\n this.remoteAttached = false;\n this.pendingRemoteStream = null;\n this.micStream = null;\n this.micSource = null;\n if (this.workletNode) {\n this.workletNode.port.onmessage = null;\n try { this.workletNode.disconnect(); } catch { /* already disconnected */ }\n this.workletNode = null;\n }\n if (this.scriptNode) {\n this.scriptNode.onaudioprocess = null;\n try { this.scriptNode.disconnect(); } catch { /* already disconnected */ }\n this.scriptNode = null;\n }\n this.destination = null;\n if (this.audioContext) {\n void this.audioContext.close().catch(() => { /* already closed */ });\n this.audioContext = null;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"realtime-audio-recorder.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-audio-recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAsB,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,qBAAqB;IA+DD;IA9D7B,mGAAmG;IAC3F,MAAM,CAAU,yBAAyB,GAAG,IAAI,CAAC;IACzD;;;;OAIG;IACK,MAAM,CAAU,iBAAiB,GAAG,EAAE,GAAG,qBAAqB,CAAC;IACvE,kGAAkG;IAC1F,MAAM,CAAU,sBAAsB,GAAG;;;;;;;;;;;;KAYhD,CAAC;IAEM,YAAY,GAAwB,IAAI,CAAC;IACzC,WAAW,GAA2C,IAAI,CAAC;IAC3D,WAAW,GAA4B,IAAI,CAAC;IAC5C,UAAU,GAA+B,IAAI,CAAC;IACtD,6FAA6F;IACrF,SAAS,GAA2B,IAAI,CAAC;IACzC,SAAS,GAAG,KAAK,CAAC;IAE1B,gGAAgG;IACxF,cAAc,GAAG,KAAK,CAAC;IAC/B,qGAAqG;IAC7F,mBAAmB,GAAuB,IAAI,CAAC;IACvD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C;YACrC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACrC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC7B,CAAC;IACL,CAAC;IAEO,cAAc,CAAC,IAAe;QAClC,IAAI,CAAC;YACD,IAAI,CAAC,UAAU,EAAE,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,6FAA6F;YAC7F,OAAO,CAAC,KAAK,CAAC,0DAA0D,EAAE,KAAK,CAAC,CAAC;QACrF,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,YAA0B;QAC3C,KAAK,YAAY,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAC/C,mFAAmF;YACnF,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,KAAK,CAAC,CAAC;QAChF,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import { RECORDING_SAMPLE_RATE } from '@memberjunction/ai-core-plus';\nimport { IRealtimeSessionRecorder } from '@memberjunction/realtime-runtime';\nimport { LinearResampler } from './recording/linear-resampler';\nimport { IOpusPacketEncoder, SelectOpusPacketEncoder } from './recording/opus-packet-encoder';\n\n/**\n * Browser-side audio recorder for a CLIENT-DIRECT realtime voice session, implementing the\n * runtime's {@link IRealtimeSessionRecorder} contract directly.\n *\n * Mixes the user's microphone with the agent's remote-audio stream (every driver exposes one via\n * `GetRemoteMediaStream()`: WebRTC drivers publish their remote track, PCM drivers — Gemini,\n * ElevenLabs, AssemblyAI, xAI, HuggingFace — publish their playout engine's output) in a Web Audio\n * graph, captures the mix as mono Float32 frames through an {@link AudioWorkletNode} (preferred) or a\n * {@link ScriptProcessorNode} (fallback), and feeds them to ONE continuous Opus encoder for the whole\n * call. The runtime pulls the encoded packets with {@link TakeEncodedPackets}, cuts them into shards\n * and uploads them as the call goes, so nothing is held in memory until the end.\n *\n * Timing is the 48 kHz sample clock: the graph asks for a 48 kHz context, and when the browser\n * refuses (or reports another rate) every frame is resampled to 48 kHz before encoding. The\n * captured-sample count drives {@link NowOffsetMs} and is what {@link Stop} resolves.\n *\n * Robust by design — every step degrades gracefully:\n * - No `AudioContext` (server-side render / unsupported env) → the recorder disables itself\n * ({@link IsRecording} stays `false`, {@link Stop} resolves 0); the voice call proceeds.\n * - No `AudioWorkletNode` AND no `ScriptProcessorNode` → disables itself rather than throwing.\n * - A forced-48 kHz context that cannot take the microphone (Firefox rejects a source whose rate\n * differs from its context's) → rebuilt once at the device rate with resampling.\n * - No remote stream yet (e.g. the WebRTC track hasn't landed) → records mic only until it does.\n * - A remote stream that can't be connected (e.g. a cross-sample-rate `createMediaStreamSource`\n * rejection) → warns and records mic only; the mic recording is never lost to the agent stream.\n * - No usable encoder → logged, recording disabled for the call.\n *\n * Not an Angular service: it owns transient per-session media plumbing the runtime creates and\n * discards per call, so a plain class is the right shape (no DI, no singleton).\n */\nexport class RealtimeAudioRecorder implements IRealtimeSessionRecorder {\n /** PCM frame size for the ScriptProcessor fallback (worklet uses its native 128-frame quantum). */\n private static readonly scriptProcessorBufferSize = 4096;\n /**\n * Most 48 kHz audio held while the encoder is still being selected / loaded (10 s). Selection is\n * normally well under a second; past this the encoder is stuck, and later frames are dropped\n * (see {@link captureFrame} for why they are not counted either).\n */\n private static readonly maxPendingSamples = 10 * RECORDING_SAMPLE_RATE;\n /** Inline AudioWorklet processor: forwards each 128-frame mono input block to the main thread. */\n private static readonly workletProcessorSource = `\n class MJPcmCaptureProcessor extends AudioWorkletProcessor {\n process(inputs) {\n const input = inputs[0];\n if (input && input[0] && input[0].length > 0) {\n // Copy out of the reused worklet buffer before posting.\n this.port.postMessage(input[0].slice(0));\n }\n return true;\n }\n }\n registerProcessor('mj-pcm-capture', MJPcmCaptureProcessor);\n `;\n\n private audioContext: AudioContext | null = null;\n private destination: MediaStreamAudioDestinationNode | null = null;\n private workletNode: AudioWorkletNode | null = null;\n private scriptNode: ScriptProcessorNode | null = null;\n /** Converts the context's rate to 48 kHz; `null` when the context already runs at 48 kHz. */\n private resampler: LinearResampler | null = null;\n private recording = false;\n\n /** True once the agent's remote stream has been wired into the mix (prevents double-attach). */\n private remoteAttached = false;\n /** A remote stream handed to AttachRemoteStream before the audio graph was ready; wired at setup. */\n private pendingRemoteStream: MediaStream | null = null;\n /** The microphone to record: the latest stream given to Start or ReplaceMicrophone. Setup connects it. */\n private micStream: MediaStream | null = null;\n /** The source node reading the microphone, swapped by ReplaceMicrophone. */\n private micSource: MediaStreamAudioSourceNode | null = null;\n\n /** 48 kHz samples captured (post-resample) — the recording's clock. */\n private capturedSamples = 0;\n /** The call's encoder once selected; `null` while selecting, after a failure, or when not recording. */\n private encoder: IOpusPacketEncoder | null = null;\n /** Resolves to the encoder (or `null` on failure) — Stop awaits it so buffered audio still gets encoded. */\n private encoderReady: Promise<IOpusPacketEncoder | null> | null = null;\n /** 48 kHz frames captured before the encoder was ready, fed to it in order once it is. */\n private pendingFrames: Float32Array[] = [];\n private pendingSamples = 0;\n private pendingOverflowWarned = false;\n /** The first Stop's promise; later calls return it (idempotent). */\n private stopping: Promise<number> | null = null;\n\n /**\n * Bumped whenever the audio graph is released. The async graph setup snapshots it and, after each\n * await, gives up if it moved: a {@link Stop} that lands mid-setup can only release what setup has\n * already published, so setup must release the rest itself rather than build a live graph on a\n * stopped recorder.\n */\n private setupGeneration = 0;\n\n /** @param selectEncoder picks the call's Opus encoder; injectable for tests. */\n constructor(private readonly selectEncoder: () => Promise<IOpusPacketEncoder> = () => SelectOpusPacketEncoder()) {}\n\n /** True while a recorder is actively capturing. */\n public get IsRecording(): boolean {\n return this.recording;\n }\n\n /**\n * Begins recording a mix of `micStream` and (when present) `remoteStream`. Best-effort:\n * a missing `AudioContext` / no worklet+scriptprocessor support / any setup failure disables\n * the recorder (logged) so the live call is never blocked.\n *\n * @param micStream The user's microphone capture stream (required).\n * @param remoteStream The agent's remote-audio stream, or `null` for mic-only capture.\n */\n public Start(micStream: MediaStream, remoteStream: MediaStream | null): void {\n if (this.recording) {\n return;\n }\n if (typeof AudioContext === 'undefined') {\n console.warn('[RealtimeAudioRecorder] AudioContext unavailable — recording disabled for this session.');\n return;\n }\n // Mark recording SYNCHRONOUSLY so a caller that checks IsRecording immediately after Start()\n // (the runtime does) sees `true`, even though the audio graph and the encoder are set up\n // asynchronously below.\n this.recording = true;\n this.stopping = null;\n this.capturedSamples = 0;\n this.encoderReady = this.prepareEncoder();\n this.micStream = micStream;\n // Fire-and-forget the async setup (it must `await audioContext.resume()` + worklet load); any\n // failure disables the recorder rather than throwing into the session-start path.\n void this.startMixedRecording(micStream, remoteStream).catch((error) => {\n console.warn('[RealtimeAudioRecorder] Failed to start recording — disabling for this session:', error);\n this.disable();\n });\n }\n\n /**\n * Wires the agent's remote-audio stream into the live mix once it arrives. The WebRTC\n * `ontrack` that delivers the agent voice usually lands AFTER recording has already begun\n * (mic-only), so the session attaches it here when it lands. Idempotent, and safe to call\n * before the audio graph finishes its async setup (the stream is connected once ready).\n */\n public AttachRemoteStream(stream: MediaStream): void {\n if (this.remoteAttached || stream.getAudioTracks().length === 0) {\n return;\n }\n if (this.audioContext && this.captureNode()) {\n this.remoteAttached = this.connectRemoteStream(this.audioContext, stream);\n } else {\n // Audio-graph setup still in flight (awaiting resume / worklet load) — connect at setup.\n this.pendingRemoteStream = stream;\n }\n }\n\n /**\n * Records the microphone stream's current track from now on: call it after the track changes (a\n * device switch). A source node reads the track it was created with, so the recording would otherwise\n * carry silence from the old device. Safe before the audio graph is ready (setup connects the latest\n * stream, and Start replaces it); a stream without an audio track keeps the current one.\n */\n public ReplaceMicrophone(micStream: MediaStream): void {\n this.micStream = micStream;\n if (!this.audioContext || !this.captureNode()) {\n return;\n }\n const replacement = this.connectStream(this.audioContext, micStream);\n if (replacement) {\n this.micSource?.disconnect();\n this.micSource = replacement;\n }\n }\n\n /** Milliseconds of audio captured so far, on the 48 kHz sample clock (never wall clock). */\n public NowOffsetMs(): number {\n return (this.capturedSamples * 1000) / RECORDING_SAMPLE_RATE;\n }\n\n /** The Opus packets the encoder produced since the last call (also its final packets after {@link Stop}). */\n public TakeEncodedPackets(): Uint8Array[] {\n return this.encoder ? this.encoder.TakePackets() : [];\n }\n\n /**\n * Stops capture, waits for the encoder (encoding any audio buffered while it loaded), flushes and\n * closes it, and resolves the 48 kHz samples captured. The final packets stay available to\n * {@link TakeEncodedPackets}. Idempotent: every call resolves the same count; 0 when the recorder\n * never started.\n */\n public Stop(): Promise<number> {\n if (!this.stopping) {\n this.stopping = this.stopOnce();\n }\n return this.stopping;\n }\n\n private async stopOnce(): Promise<number> {\n this.recording = false;\n this.releaseGraph();\n const encoderReady = this.encoderReady;\n if (!encoderReady) {\n return this.capturedSamples;\n }\n const encoder = await encoderReady;\n if (encoder) {\n await encoder.Flush();\n encoder.Close();\n }\n return this.capturedSamples;\n }\n\n /**\n * Selects the encoder and feeds it what was captured meanwhile. A selection failure disables the\n * recorder: with no encoder nothing captured could ever reach the server.\n */\n private async prepareEncoder(): Promise<IOpusPacketEncoder | null> {\n let encoder: IOpusPacketEncoder;\n try {\n encoder = await this.selectEncoder();\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] No Opus encoder available — recording disabled for this session:', error);\n this.disable();\n // Nothing captured can be encoded now, so report nothing recorded rather than a count with no audio.\n this.pendingFrames = [];\n this.pendingSamples = 0;\n this.capturedSamples = 0;\n return null;\n }\n this.encoder = encoder;\n for (const frame of this.pendingFrames) {\n encoder.Encode(frame);\n }\n this.pendingFrames = [];\n this.pendingSamples = 0;\n return encoder;\n }\n\n /** Builds the mix graph + capture node, retrying once at the device rate if 48 kHz cannot take the mic. */\n private async startMixedRecording(micStream: MediaStream, remoteStream: MediaStream | null): Promise<void> {\n const built = await this.buildGraph(micStream, remoteStream, true);\n if (built === 'mic-rejected') {\n await this.buildGraph(micStream, remoteStream, false);\n }\n }\n\n /**\n * Wires up the Web Audio mix graph + PCM capture node (worklet preferred) and starts capture.\n * Resolves `'mic-rejected'` when a forced-48 kHz context refused the microphone source (the graph\n * is released so the caller can rebuild at the device rate); otherwise `'done'`.\n */\n private async buildGraph(micStream: MediaStream, remoteStream: MediaStream | null, prefer48k: boolean): Promise<'done' | 'mic-rejected'> {\n const generation = this.setupGeneration;\n const audioContext = this.createAudioContext(prefer48k);\n const forced48k = prefer48k && audioContext.sampleRate === RECORDING_SAMPLE_RATE;\n // CRITICAL: browsers create an AudioContext in the `suspended` state under the autoplay policy.\n // Without resuming it, the mix graph never processes audio and we capture only silence. Starting\n // a voice call is a user gesture, so resume() succeeds here.\n if (audioContext.state === 'suspended') {\n await audioContext.resume();\n }\n if (generation !== this.setupGeneration) {\n // Stopped while resuming: the context was never published, so releaseGraph() could not close it.\n this.closeContext(audioContext);\n return 'done';\n }\n const destination = audioContext.createMediaStreamDestination();\n // Publish the context BEFORE wiring the remote so a concurrent AttachRemoteStream() (the agent\n // track can land during the awaits above) sees a ready graph to connect to.\n this.audioContext = audioContext;\n this.destination = destination;\n this.resampler = audioContext.sampleRate === RECORDING_SAMPLE_RATE ? null : new LinearResampler(audioContext.sampleRate, RECORDING_SAMPLE_RATE);\n\n // Build the PCM capture node: AudioWorklet preferred, ScriptProcessor fallback. Either way the\n // node both pulls audio from the mix AND drives the destination so the graph keeps processing.\n await this.createCaptureNode(audioContext, destination);\n if (generation !== this.setupGeneration) {\n return 'done'; // Stopped while the capture node loaded: releaseGraph() already closed the published context.\n }\n\n try {\n // The microphone may have been replaced while the graph was being built.\n this.micSource = this.connectStream(audioContext, this.micStream ?? micStream);\n } catch (error) {\n if (!forced48k) {\n throw error;\n }\n console.warn('[RealtimeAudioRecorder] The 48 kHz context rejected the microphone — rebuilding at the device rate with resampling:', error);\n // releaseGraph() forgets a stashed agent stream and a replaced microphone; the rebuild still has to connect both.\n const stashedRemote = this.pendingRemoteStream;\n const stashedMic = this.micStream;\n this.releaseGraph();\n this.pendingRemoteStream = stashedRemote;\n this.micStream = stashedMic;\n return 'mic-rejected';\n }\n // Connect the agent's stream if it was passed now, or if AttachRemoteStream() stashed one while\n // we were setting up. Either way, capture the agent voice — not just the mic.\n const remote = remoteStream ?? this.pendingRemoteStream;\n this.pendingRemoteStream = null;\n if (remote && remote.getAudioTracks().length > 0) {\n this.remoteAttached = this.connectRemoteStream(audioContext, remote);\n }\n return 'done';\n }\n\n /**\n * A 48 kHz context when asked for and the browser allows it, else the device-rate default. A\n * browser that silently picks another rate is fine too: the resampler is chosen from the rate the\n * context actually reports.\n */\n private createAudioContext(prefer48k: boolean): AudioContext {\n if (prefer48k) {\n try {\n return new AudioContext({ sampleRate: RECORDING_SAMPLE_RATE });\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] 48 kHz AudioContext refused — capturing at the device rate with resampling:', error);\n }\n }\n return new AudioContext();\n }\n\n /**\n * Connects the agent stream, degrading to mic-only on failure. Unlike the mic (whose failure\n * rightly disables the recorder), the agent stream is best-effort: a browser may reject it\n * (cross-sample-rate `NotSupportedError`) and that must not discard the user's recording.\n * Returns whether it was connected, so the caller only marks it attached on success.\n */\n private connectRemoteStream(audioContext: AudioContext, stream: MediaStream): boolean {\n try {\n this.connectStream(audioContext, stream);\n return true;\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] Could not mix the agent stream into the recording — continuing mic-only:', error);\n return false;\n }\n }\n\n /**\n * Creates the PCM capture node and inserts it into the graph: sources → captureNode → destination.\n * Prefers an {@link AudioWorkletNode} (off-main-thread, no deprecation); falls back to a\n * {@link ScriptProcessorNode} where worklets are unavailable. Throws when neither is supported\n * (caught by {@link Start}, which then disables the recorder).\n */\n private async createCaptureNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): Promise<void> {\n if (await this.tryCreateWorkletNode(audioContext, destination)) {\n return;\n }\n this.createScriptProcessorNode(audioContext, destination);\n }\n\n /** Attempts to build the AudioWorklet capture node; returns `false` (no throw) when unsupported. */\n private async tryCreateWorkletNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): Promise<boolean> {\n if (!audioContext.audioWorklet || typeof AudioWorkletNode === 'undefined' || typeof Blob === 'undefined') {\n return false;\n }\n try {\n const moduleUrl = URL.createObjectURL(\n new Blob([RealtimeAudioRecorder.workletProcessorSource], { type: 'application/javascript' }),\n );\n try {\n await audioContext.audioWorklet.addModule(moduleUrl);\n } finally {\n URL.revokeObjectURL(moduleUrl);\n }\n const node = new AudioWorkletNode(audioContext, 'mj-pcm-capture', { numberOfInputs: 1, numberOfOutputs: 1 });\n node.port.onmessage = (event: MessageEvent<Float32Array>) => this.captureFrame(event.data);\n node.connect(destination);\n this.workletNode = node;\n return true;\n } catch (error) {\n console.warn('[RealtimeAudioRecorder] AudioWorklet unavailable — falling back to ScriptProcessor:', error);\n return false;\n }\n }\n\n /** Builds the ScriptProcessor fallback capture node and inserts it into the graph. */\n private createScriptProcessorNode(audioContext: AudioContext, destination: MediaStreamAudioDestinationNode): void {\n if (typeof audioContext.createScriptProcessor !== 'function') {\n throw new Error('Neither AudioWorklet nor ScriptProcessor is supported');\n }\n const node = audioContext.createScriptProcessor(RealtimeAudioRecorder.scriptProcessorBufferSize, 1, 1);\n node.onaudioprocess = (event: AudioProcessingEvent) => this.captureFrame(event.inputBuffer.getChannelData(0));\n // ScriptProcessor only fires onaudioprocess while connected to the destination.\n node.connect(destination);\n this.scriptNode = node;\n }\n\n /** The active capture node (worklet or script processor), or `null` before setup. */\n private captureNode(): AudioNode | null {\n return this.workletNode ?? this.scriptNode;\n }\n\n /**\n * Absorbs one captured frame: resample to 48 kHz, count it, and hand it to the encoder (or buffer\n * it while the encoder loads).\n *\n * Past the pending-buffer cap a frame is dropped AND not counted. Keeping the count equal to the\n * audio actually handed to the encoder is what lets the runtime trust `packets × 960 ≥ captured`\n * when it trims the final shard; a few lost seconds at the start of a call whose encoder never\n * loaded is the smaller harm.\n */\n private captureFrame(frame: Float32Array): void {\n if (!this.recording || frame.length === 0) {\n return;\n }\n // Copy out of the engine's reused buffer (a resampler output is already a fresh array).\n const samples = this.resampler ? this.resampler.Process(frame) : frame.slice(0);\n if (samples.length === 0) {\n return;\n }\n if (this.encoder) {\n this.encoder.Encode(samples);\n } else if (this.pendingSamples + samples.length <= RealtimeAudioRecorder.maxPendingSamples) {\n this.pendingFrames.push(samples);\n this.pendingSamples += samples.length;\n } else {\n if (!this.pendingOverflowWarned) {\n this.pendingOverflowWarned = true;\n console.warn(`[RealtimeAudioRecorder] Opus encoder still not ready after ${RealtimeAudioRecorder.maxPendingSamples / RECORDING_SAMPLE_RATE} s of audio — dropping audio until it is.`);\n }\n return;\n }\n this.capturedSamples += samples.length;\n }\n\n /** Routes one stream's audio tracks into the capture node; returns the source, or null when track-less / no node. */\n private connectStream(audioContext: AudioContext, stream: MediaStream): MediaStreamAudioSourceNode | null {\n const node = this.captureNode();\n if (!node || stream.getAudioTracks().length === 0) {\n return null;\n }\n const source = audioContext.createMediaStreamSource(stream);\n source.connect(node);\n return source;\n }\n\n /**\n * Turns recording off after a setup failure and releases the graph. Audio already captured stays\n * queued for the encoder, so a graph failure mid-call still keeps what was recorded before it.\n */\n private disable(): void {\n this.recording = false;\n this.releaseGraph();\n }\n\n /** Releases the audio graph + capture node. Idempotent; leaves the encoder and the sample count alone. */\n private releaseGraph(): void {\n this.setupGeneration++;\n this.remoteAttached = false;\n this.pendingRemoteStream = null;\n this.micStream = null;\n this.micSource = null;\n if (this.workletNode) {\n this.workletNode.port.onmessage = null;\n this.disconnectNode(this.workletNode);\n this.workletNode = null;\n }\n if (this.scriptNode) {\n this.scriptNode.onaudioprocess = null;\n this.disconnectNode(this.scriptNode);\n this.scriptNode = null;\n }\n this.destination = null;\n this.resampler = null;\n if (this.audioContext) {\n this.closeContext(this.audioContext);\n this.audioContext = null;\n }\n }\n\n private disconnectNode(node: AudioNode): void {\n try {\n node.disconnect();\n } catch (error) {\n // Expected when the node was never connected or is already disconnected; nothing to release.\n console.debug('[RealtimeAudioRecorder] Capture node disconnect skipped:', error);\n }\n }\n\n private closeContext(audioContext: AudioContext): void {\n void audioContext.close().catch((error: unknown) => {\n // A context that is already closed rejects here; the graph is released either way.\n console.debug('[RealtimeAudioRecorder] AudioContext close skipped:', error);\n });\n }\n}\n"]}
|
|
@@ -8,8 +8,8 @@ import * as i0 from "@angular/core";
|
|
|
8
8
|
* {@link RealtimeSessionRuntime} (`@memberjunction/realtime-runtime`), which is framework-agnostic
|
|
9
9
|
* and shared with every other host, including the React Native app. This class supplies the three
|
|
10
10
|
* things that are genuinely Angular/browser: the `@Injectable` shell that lets components inject
|
|
11
|
-
* it, the browser's media host, and the
|
|
12
|
-
*
|
|
11
|
+
* it, the browser's media host, and the page-lifecycle wiring that sends the recording's terminal
|
|
12
|
+
* request when the tab is hidden or unloaded (#5294).
|
|
13
13
|
*
|
|
14
14
|
* Consumers are unaffected by that split — the injectable token, class name, and public surface
|
|
15
15
|
* are unchanged. Types that used to be declared in this file (`RealtimeCaption`,
|
|
@@ -19,7 +19,35 @@ import * as i0 from "@angular/core";
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class RealtimeSessionService extends RealtimeSessionRuntime {
|
|
21
21
|
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Sends the recording terminal (tail shard + counts, as a keepalive request) when the page is
|
|
24
|
+
* going away: on `pagehide`, and when the page becomes hidden — the last event a mobile browser
|
|
25
|
+
* reliably fires before it may discard a backgrounded tab without any unload event. Both handlers
|
|
26
|
+
* only call the runtime's synchronous {@link RealtimeSessionRuntime.SendRecordingTerminal}, which
|
|
27
|
+
* does no IndexedDB work and no encoding: there is no time for either while a page is unloading.
|
|
28
|
+
* It does nothing when no call is recording, and repeating it is safe (a sent tail is sealed, so a
|
|
29
|
+
* call that continues after the tab comes back sends its later shards at new indexes).
|
|
30
|
+
*
|
|
31
|
+
* There is deliberately no `beforeunload` prompt any more: shards already on the server plus the
|
|
32
|
+
* terminal make closing the tab safe, and a `beforeunload` listener blocks the back/forward cache.
|
|
33
|
+
*
|
|
34
|
+
* The service is a root singleton, so these listeners live exactly as long as the app and are
|
|
35
|
+
* never removed.
|
|
36
|
+
*
|
|
37
|
+
* @param page the page-lifecycle event target (`window`)
|
|
38
|
+
* @param visibility the visibility source (`document`)
|
|
39
|
+
*/
|
|
40
|
+
protected WireRecordingTerminalTriggers(page: PageHideEventTarget, visibility: VisibilityEventSource): void;
|
|
22
41
|
static ɵfac: i0.ɵɵFactoryDeclaration<RealtimeSessionService, never>;
|
|
23
42
|
static ɵprov: i0.ɵɵInjectableDeclaration<RealtimeSessionService>;
|
|
24
43
|
}
|
|
44
|
+
/** The slice of `window` the terminal wiring needs; `window` itself satisfies it. */
|
|
45
|
+
export interface PageHideEventTarget {
|
|
46
|
+
addEventListener(type: 'pagehide', listener: () => void): void;
|
|
47
|
+
}
|
|
48
|
+
/** The slice of `document` the terminal wiring needs; `document` itself satisfies it. */
|
|
49
|
+
export interface VisibilityEventSource {
|
|
50
|
+
readonly visibilityState: DocumentVisibilityState;
|
|
51
|
+
addEventListener(type: 'visibilitychange', listener: () => void): void;
|
|
52
|
+
}
|
|
25
53
|
//# sourceMappingURL=realtime-session.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-session.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/realtime-session.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;;
|
|
1
|
+
{"version":3,"file":"realtime-session.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/realtime-session.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;;AA8B1E;;;;;;;;;;;;;;;;GAgBG;AACH,qBACa,sBAAuB,SAAQ,sBAAsB;;IAQ9D;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,6BAA6B,CAAC,IAAI,EAAE,mBAAmB,EAAE,UAAU,EAAE,qBAAqB,GAAG,IAAI;yCA1BlG,sBAAsB;6CAAtB,sBAAsB;CAoClC;AAED,qFAAqF;AACrF,MAAM,WAAW,mBAAmB;IAEhC,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAClE;AAED,yFAAyF;AACzF,MAAM,WAAW,qBAAqB;IAElC,QAAQ,CAAC,eAAe,EAAE,uBAAuB,CAAC;IAElD,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAC1E"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
2
|
import { RealtimeSessionRuntime } from '@memberjunction/realtime-runtime';
|
|
3
|
-
import { LoadAssemblyAIRealtimeClient, LoadElevenLabsRealtimeClient, LoadGeminiRealtimeClient, LoadHuggingFaceRealtimeClient, LoadOpenAILiveClient, LoadOpenAIRealtimeClient, LoadxAIRealtimeClient, } from '@memberjunction/ai-realtime-client';
|
|
3
|
+
import { LoadAssemblyAIRealtimeClient, LoadElevenLabsRealtimeClient, LoadElevenRealtimeClient, LoadGeminiRealtimeClient, LoadHuggingFaceRealtimeClient, LoadOpenAILiveClient, LoadOpenAIRealtimeClient, LoadxAIRealtimeClient, } from '@memberjunction/ai-realtime-client';
|
|
4
4
|
import { BrowserRealtimeMediaHost } from './browser-realtime-media-host';
|
|
5
|
-
import { BrowserRecordingUnloadGuard } from './browser-recording-unload-guard';
|
|
6
5
|
import * as i0 from "@angular/core";
|
|
7
6
|
// Tree-shaking prevention: client drivers are resolved dynamically through the ClassFactory (by
|
|
8
7
|
// the server-reported Provider key), so these static calls are what keep their @RegisterClass side
|
|
@@ -18,6 +17,7 @@ LoadGeminiRealtimeClient();
|
|
|
18
17
|
LoadElevenLabsRealtimeClient();
|
|
19
18
|
LoadAssemblyAIRealtimeClient();
|
|
20
19
|
LoadxAIRealtimeClient();
|
|
20
|
+
LoadElevenRealtimeClient();
|
|
21
21
|
LoadHuggingFaceRealtimeClient();
|
|
22
22
|
/**
|
|
23
23
|
* Angular host for MemberJunction's realtime co-agent sessions.
|
|
@@ -27,8 +27,8 @@ LoadHuggingFaceRealtimeClient();
|
|
|
27
27
|
* {@link RealtimeSessionRuntime} (`@memberjunction/realtime-runtime`), which is framework-agnostic
|
|
28
28
|
* and shared with every other host, including the React Native app. This class supplies the three
|
|
29
29
|
* things that are genuinely Angular/browser: the `@Injectable` shell that lets components inject
|
|
30
|
-
* it, the browser's media host, and the
|
|
31
|
-
*
|
|
30
|
+
* it, the browser's media host, and the page-lifecycle wiring that sends the recording's terminal
|
|
31
|
+
* request when the tab is hidden or unloaded (#5294).
|
|
32
32
|
*
|
|
33
33
|
* Consumers are unaffected by that split — the injectable token, class name, and public surface
|
|
34
34
|
* are unchanged. Types that used to be declared in this file (`RealtimeCaption`,
|
|
@@ -39,9 +39,37 @@ LoadHuggingFaceRealtimeClient();
|
|
|
39
39
|
export class RealtimeSessionService extends RealtimeSessionRuntime {
|
|
40
40
|
constructor() {
|
|
41
41
|
super(new BrowserRealtimeMediaHost());
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
43
|
+
this.WireRecordingTerminalTriggers(window, document);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sends the recording terminal (tail shard + counts, as a keepalive request) when the page is
|
|
48
|
+
* going away: on `pagehide`, and when the page becomes hidden — the last event a mobile browser
|
|
49
|
+
* reliably fires before it may discard a backgrounded tab without any unload event. Both handlers
|
|
50
|
+
* only call the runtime's synchronous {@link RealtimeSessionRuntime.SendRecordingTerminal}, which
|
|
51
|
+
* does no IndexedDB work and no encoding: there is no time for either while a page is unloading.
|
|
52
|
+
* It does nothing when no call is recording, and repeating it is safe (a sent tail is sealed, so a
|
|
53
|
+
* call that continues after the tab comes back sends its later shards at new indexes).
|
|
54
|
+
*
|
|
55
|
+
* There is deliberately no `beforeunload` prompt any more: shards already on the server plus the
|
|
56
|
+
* terminal make closing the tab safe, and a `beforeunload` listener blocks the back/forward cache.
|
|
57
|
+
*
|
|
58
|
+
* The service is a root singleton, so these listeners live exactly as long as the app and are
|
|
59
|
+
* never removed.
|
|
60
|
+
*
|
|
61
|
+
* @param page the page-lifecycle event target (`window`)
|
|
62
|
+
* @param visibility the visibility source (`document`)
|
|
63
|
+
*/
|
|
64
|
+
WireRecordingTerminalTriggers(page, visibility) {
|
|
65
|
+
page.addEventListener('pagehide', () => this.SendRecordingTerminal({ Final: true }));
|
|
66
|
+
visibility.addEventListener('visibilitychange', () => {
|
|
67
|
+
if (visibility.visibilityState === 'hidden') {
|
|
68
|
+
// Not final: the user may come back and the call go on, so the server only stamps the
|
|
69
|
+
// counts and assembles after its grace period instead of rewriting the recording now.
|
|
70
|
+
this.SendRecordingTerminal({ Final: false });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
45
73
|
}
|
|
46
74
|
static ɵfac = function RealtimeSessionService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || RealtimeSessionService)(); };
|
|
47
75
|
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: RealtimeSessionService, factory: RealtimeSessionService.ɵfac, providedIn: 'root' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-session.service.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-session.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EACH,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,6BAA6B,EAC7B,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC
|
|
1
|
+
{"version":3,"file":"realtime-session.service.js","sourceRoot":"","sources":["../../../src/lib/services/realtime-session.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EACH,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC7B,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;;AAEzE,gGAAgG;AAChG,mGAAmG;AACnG,gDAAgD;AAChD,EAAE;AACF,+FAA+F;AAC/F,0FAA0F;AAC1F,+FAA+F;AAC/F,kBAAkB;AAClB,wBAAwB,EAAE,CAAC;AAC3B,oBAAoB,EAAE,CAAC;AACvB,wBAAwB,EAAE,CAAC;AAC3B,4BAA4B,EAAE,CAAC;AAC/B,4BAA4B,EAAE,CAAC;AAC/B,qBAAqB,EAAE,CAAC;AACxB,wBAAwB,EAAE,CAAC;AAC3B,6BAA6B,EAAE,CAAC;AAEhC;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAC9D;QACI,KAAK,CAAC,IAAI,wBAAwB,EAAE,CAAC,CAAC;QACtC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;YACnE,IAAI,CAAC,6BAA6B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACO,6BAA6B,CAAC,IAAyB,EAAE,UAAiC;QAChG,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACrF,UAAU,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;YACjD,IAAI,UAAU,CAAC,eAAe,KAAK,QAAQ,EAAE,CAAC;gBAC1C,sFAAsF;gBACtF,sFAAsF;gBACtF,IAAI,CAAC,qBAAqB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACjD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;gHAnCQ,sBAAsB;gEAAtB,sBAAsB,WAAtB,sBAAsB,mBADT,MAAM;;iFACnB,sBAAsB;cADlC,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport { RealtimeSessionRuntime } from '@memberjunction/realtime-runtime';\nimport {\n LoadAssemblyAIRealtimeClient,\n LoadElevenLabsRealtimeClient,\n LoadElevenRealtimeClient,\n LoadGeminiRealtimeClient,\n LoadHuggingFaceRealtimeClient,\n LoadOpenAILiveClient,\n LoadOpenAIRealtimeClient,\n LoadxAIRealtimeClient,\n} from '@memberjunction/ai-realtime-client';\nimport { BrowserRealtimeMediaHost } from './browser-realtime-media-host';\n\n// Tree-shaking prevention: client drivers are resolved dynamically through the ClassFactory (by\n// the server-reported Provider key), so these static calls are what keep their @RegisterClass side\n// effects from being eliminated by the bundler.\n//\n// NOTE: the interactive-channel plugins (resolved dynamically from the `MJ: AI Agent Channels`\n// registry by ClientPluginClass key) get the same treatment, but their Load calls live in\n// `conversations.module.ts` — plugins carry Angular surface COMPONENTS, and this service stays\n// component-free.\nLoadOpenAIRealtimeClient();\nLoadOpenAILiveClient();\nLoadGeminiRealtimeClient();\nLoadElevenLabsRealtimeClient();\nLoadAssemblyAIRealtimeClient();\nLoadxAIRealtimeClient();\nLoadElevenRealtimeClient();\nLoadHuggingFaceRealtimeClient();\n\n/**\n * Angular host for MemberJunction's realtime co-agent sessions.\n *\n * All orchestration — mint, driver resolution, transcripts, tool relay, delegation narration,\n * channel lifecycle, usage relay, teardown — lives in\n * {@link RealtimeSessionRuntime} (`@memberjunction/realtime-runtime`), which is framework-agnostic\n * and shared with every other host, including the React Native app. This class supplies the three\n * things that are genuinely Angular/browser: the `@Injectable` shell that lets components inject\n * it, the browser's media host, and the page-lifecycle wiring that sends the recording's terminal\n * request when the tab is hidden or unloaded (#5294).\n *\n * Consumers are unaffected by that split — the injectable token, class name, and public surface\n * are unchanged. Types that used to be declared in this file (`RealtimeCaption`,\n * `RealtimeConnectionState`, `RealtimeSessionRunOptions`, …) now come from\n * `@memberjunction/realtime-runtime`; import them from there directly, since MJ does not\n * re-export across package boundaries.\n */\n@Injectable({ providedIn: 'root' })\nexport class RealtimeSessionService extends RealtimeSessionRuntime {\n constructor() {\n super(new BrowserRealtimeMediaHost());\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n this.WireRecordingTerminalTriggers(window, document);\n }\n }\n\n /**\n * Sends the recording terminal (tail shard + counts, as a keepalive request) when the page is\n * going away: on `pagehide`, and when the page becomes hidden — the last event a mobile browser\n * reliably fires before it may discard a backgrounded tab without any unload event. Both handlers\n * only call the runtime's synchronous {@link RealtimeSessionRuntime.SendRecordingTerminal}, which\n * does no IndexedDB work and no encoding: there is no time for either while a page is unloading.\n * It does nothing when no call is recording, and repeating it is safe (a sent tail is sealed, so a\n * call that continues after the tab comes back sends its later shards at new indexes).\n *\n * There is deliberately no `beforeunload` prompt any more: shards already on the server plus the\n * terminal make closing the tab safe, and a `beforeunload` listener blocks the back/forward cache.\n *\n * The service is a root singleton, so these listeners live exactly as long as the app and are\n * never removed.\n *\n * @param page the page-lifecycle event target (`window`)\n * @param visibility the visibility source (`document`)\n */\n protected WireRecordingTerminalTriggers(page: PageHideEventTarget, visibility: VisibilityEventSource): void {\n page.addEventListener('pagehide', () => this.SendRecordingTerminal({ Final: true }));\n visibility.addEventListener('visibilitychange', () => {\n if (visibility.visibilityState === 'hidden') {\n // Not final: the user may come back and the call go on, so the server only stamps the\n // counts and assembles after its grace period instead of rewriting the recording now.\n this.SendRecordingTerminal({ Final: false });\n }\n });\n }\n}\n\n/** The slice of `window` the terminal wiring needs; `window` itself satisfies it. */\nexport interface PageHideEventTarget {\n // case-violation-ok-legacy-back-compat: mirrors the DOM EventTarget API so `window` itself satisfies this interface\n addEventListener(type: 'pagehide', listener: () => void): void;\n}\n\n/** The slice of `document` the terminal wiring needs; `document` itself satisfies it. */\nexport interface VisibilityEventSource {\n // case-violation-ok-legacy-back-compat: mirrors the DOM Document API so `document` itself satisfies this interface\n readonly visibilityState: DocumentVisibilityState;\n // case-violation-ok-legacy-back-compat: mirrors the DOM EventTarget API so `document` itself satisfies this interface\n addEventListener(type: 'visibilitychange', listener: () => void): void;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libopus-wasm-binary.d.ts","sourceRoot":"","sources":["../../../../src/lib/services/recording/libopus-wasm-binary.ts"],"names":[],"mappings":"AA4CA,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,EAAE,MA2bxB,CAAC"}
|