Skip to content

The open alternative to Salesforce, designed for AI.

feat: add audio playback fallback for call recordings (#25592)

nitin54c089ddeba3
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingAudioPlayer.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingAudioPlayer.tsx
new file mode 100644
index 00000000000..814fc1a4f0f
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingAudioPlayer.tsx
@@ -0,0 +1,246 @@
+import { formatCallRecordingTranscriptTimestamp } from '@/page-layout/widgets/call-recording-transcript/utils/formatCallRecordingTranscriptTimestamp';
+import { styled } from '@linaria/react';
+import { plural, t } from '@lingui/core/macro';
+import { useImperativeHandle, useRef, useState, type Ref } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { CircularProgressBar } from 'twenty-ui/feedback';
+import {
+ IconHeadphones,
+ IconPlayerPause,
+ IconPlayerPlay,
+} from 'twenty-ui/icon';
+import { Button, IconButton, Slider } from 'twenty-ui/input';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+
+const StyledAudioBar = styled.div`
+ align-items: center;
+ border-bottom: 1px solid ${themeCssVariables.border.color.light};
+ box-sizing: border-box;
+ color: ${themeCssVariables.font.color.secondary};
+ display: flex;
+ gap: ${themeCssVariables.spacing[2]};
+ height: ${themeCssVariables.spacing[10]};
+ padding: 0 ${themeCssVariables.spacing[3]};
+`;
+
+const StyledTrack = styled.div`
+ flex: 1;
+ min-width: 0;
+`;
+
+const StyledLoadingTrack = styled.div`
+ background: ${themeCssVariables.background.tertiary};
+ border-radius: ${themeCssVariables.border.radius.pill};
+ height: ${themeCssVariables.spacing[4]};
+`;
+
+const StyledTime = styled.span`
+ flex-shrink: 0;
+ font-size: ${themeCssVariables.font.size.xs};
+ font-variant-numeric: tabular-nums;
+`;
+
+type CallRecordingAudioPlayerProps = {
+ ref?: Ref<HTMLAudioElement>;
+ src: string;
+ onRetry: () => Promise<void>;
+};
+
+export const CallRecordingAudioPlayer = ({
+ ref,
+ src,
+ onRetry,
+}: CallRecordingAudioPlayerProps) => {
+ const audioElementRef = useRef<HTMLAudioElement>(null);
+ const [isPlaying, setIsPlaying] = useState(false);
+ const [currentTimeSeconds, setCurrentTimeSeconds] = useState(0);
+ const [durationSeconds, setDurationSeconds] = useState(0);
+ const [isSeeking, setIsSeeking] = useState(false);
+ const [isStalled, setIsStalled] = useState(false);
+ const [isErrored, setIsErrored] = useState(false);
+ const [isRetrying, setIsRetrying] = useState(false);
+
+ useImperativeHandle<HTMLAudioElement | null, HTMLAudioElement | null>(
+ ref,
+ () => audioElementRef.current,
+ [],
+ );
+
+ const isDurationKnown =
+ Number.isFinite(durationSeconds) && durationSeconds > 0;
+ const elapsedTime = isDurationKnown
+ ? formatCallRecordingTranscriptTimestamp(currentTimeSeconds)
+ : '--:--';
+ const totalTime = isDurationKnown
+ ? formatCallRecordingTranscriptTimestamp(durationSeconds)
+ : '--:--';
+ const minutes = Math.floor(currentTimeSeconds / 60);
+ const seconds = Math.floor(currentTimeSeconds % 60);
+ const spokenMinutes = plural(minutes, {
+ one: '# minute',
+ other: '# minutes',
+ });
+ const spokenSeconds = plural(seconds, {
+ one: '# second',
+ other: '# seconds',
+ });
+
+ const handleTogglePlayback = async () => {
+ const audioElement = audioElementRef.current;
+
+ if (!isDefined(audioElement)) {
+ return;
+ }
+
+ if (!audioElement.paused) {
+ audioElement.pause();
+ return;
+ }
+
+ try {
+ await audioElement.play();
+ } catch (error) {
+ // Pausing or reloading can interrupt play without a media failure.
+ if (error instanceof DOMException && error.name === 'AbortError') {
+ return;
+ }
+ setIsErrored(true);
+ setIsStalled(false);
+ }
+ };
+
+ const handlePause = () => {
+ setIsPlaying(false);
+ setIsStalled(false);
+ };
+
+ const handleCommitSeek = (value: number) => {
+ if (isDefined(audioElementRef.current) && isDurationKnown) {
+ audioElementRef.current.currentTime = value;
+ setCurrentTimeSeconds(value);
+ }
+ setIsSeeking(false);
+ };
+
+ const handleRetry = async () => {
+ setIsRetrying(true);
+ setIsStalled(false);
+
+ try {
+ await onRetry();
+ setIsErrored(false);
+ setCurrentTimeSeconds(0);
+ setDurationSeconds(0);
+ setIsSeeking(false);
+ audioElementRef.current?.load();
+ } catch {
+ // A failed refetch surfaces through the widget's query error state.
+ } finally {
+ setIsRetrying(false);
+ }
+ };
+
+ return (
+ <StyledAudioBar>
+ <audio
+ ref={audioElementRef}
+ src={src}
+ preload="metadata"
+ onPlay={() => setIsPlaying(true)}
+ onPause={handlePause}
+ onEnded={handlePause}
+ onTimeUpdate={(event) => {
+ if (!isSeeking) {
+ setCurrentTimeSeconds(event.currentTarget.currentTime);
+ }
+ }}
+ onLoadedMetadata={(event) =>
+ setDurationSeconds(event.currentTarget.duration)
+ }
+ onDurationChange={(event) =>
+ setDurationSeconds(event.currentTarget.duration)
+ }
+ onWaiting={() => setIsStalled(true)}
+ onPlaying={() => setIsStalled(false)}
+ onCanPlay={() => setIsStalled(false)}
+ onError={() => {
+ setIsErrored(true);
+ handlePause();
+ }}
+ />
+ <IconHeadphones size={16} aria-hidden />
+ {isErrored ? (
+ <>
+ <StyledTrack role="status">{t`Playback failed`}</StyledTrack>
+ <Button
+ title={t`Retry`}
+ variant="secondary"
+ size="small"
+ disabled={isRetrying}
+ isLoading={isRetrying}
+ onClick={handleRetry}
+ />
+ </>
+ ) : (
+ <>
+ <IconButton
+ ariaLabel={isPlaying ? t`Pause` : t`Play`}
+ Icon={
+ isStalled
+ ? undefined
+ : isPlaying
+ ? IconPlayerPause
+ : IconPlayerPlay
+ }
+ size="small"
+ variant="tertiary"
+ onClick={handleTogglePlayback}
+ >
+ {isStalled && <CircularProgressBar barWidth={2} size={24} />}
+ </IconButton>
+ <StyledTrack>
+ {isDurationKnown ? (
+ <Slider
+ aria-label={t`Seek`}
+ aria-valuetext={t`${spokenMinutes} ${spokenSeconds}`}
+ max={durationSeconds}
+ step={0.1}
+ value={currentTimeSeconds}
+ onPointerDown={(event) => {
+ event.currentTarget.setPointerCapture(event.pointerId);
+ setIsSeeking(true);
+ }}
+ onChange={(event) => {
+ const value = event.currentTarget.valueAsNumber;
+ setCurrentTimeSeconds(value);
+ if (!isSeeking) {
+ handleCommitSeek(value);
+ }
+ }}
+ onPointerUp={(event) =>
+ handleCommitSeek(event.currentTarget.valueAsNumber)
+ }
+ onPointerCancel={() => {
+ setIsSeeking(false);
+ setCurrentTimeSeconds(
+ audioElementRef.current?.currentTime ?? 0,
+ );
+ }}
+ onBlur={(event) => {
+ if (isSeeking) {
+ handleCommitSeek(event.currentTarget.valueAsNumber);
+ }
+ }}
+ />
+ ) : (
+ <StyledLoadingTrack />
+ )}
+ </StyledTrack>
+ <StyledTime>
+ {elapsedTime} / {totalTime}
+ </StyledTime>
+ </>
+ )}
+ </StyledAudioBar>
+ );
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody.tsx
index ef12291e093..e94d45cf81d 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody.tsx
@@ -1,3 +1,5 @@
+import { CallRecordingAudioPlayer } from '@/page-layout/widgets/call-recording-transcript/components/CallRecordingAudioPlayer';
+import { type CallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/types/CallRecordingPlaybackMedia';
import { CallRecordingWidgetEmptyStateDisplay } from '@/page-layout/widgets/call-recording/components/CallRecordingWidgetEmptyStateDisplay';
import { CallRecordingWidgetForbiddenDisplay } from '@/page-layout/widgets/call-recording/components/CallRecordingWidgetForbiddenDisplay';
import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
@@ -25,7 +27,7 @@ const StyledRecordingLayout = styled.div`
type CallRecordingTranscriptBodyProps = {
callRecording: WidgetCallRecordingCandidate | undefined;
transcriptEntries: CallRecordingParsedTranscriptEntry[] | undefined;
- videoFileUrl: string | undefined;
+ playbackMedia: CallRecordingPlaybackMedia | undefined;
loading: boolean;
error: Error | undefined;
restriction: WidgetAccessDenialInfo | undefined;
@@ -35,14 +37,14 @@ type CallRecordingTranscriptBodyProps = {
export const CallRecordingTranscriptBody = ({
callRecording,
transcriptEntries,
- videoFileUrl,
+ playbackMedia,
loading,
error,
restriction,
refetchCallRecording,
}: CallRecordingTranscriptBodyProps) => {
const widget = useCurrentWidget();
- const [videoElement, setVideoElement] = useState<HTMLVideoElement | null>(
+ const [mediaElement, setMediaElement] = useState<HTMLMediaElement | null>(
null,
);
@@ -72,7 +74,7 @@ export const CallRecordingTranscriptBody = ({
);
}
- if (!isDefined(videoFileUrl)) {
+ if (!isDefined(playbackMedia)) {
return (
<CallRecordingTranscriptContent
callRecording={callRecording}
@@ -81,12 +83,12 @@ export const CallRecordingTranscriptBody = ({
);
}
- const playback = isDefined(videoElement)
+ const playback = isDefined(mediaElement)
? {
position: entryPlaybackPosition,
- videoElement,
+ mediaElement,
onSeek: (startSeconds: number) => {
- videoElement.currentTime = startSeconds;
+ mediaElement.currentTime = startSeconds;
},
}
: undefined;
@@ -94,16 +96,25 @@ export const CallRecordingTranscriptBody = ({
return (
<StyledRecordingLayout>
<CallRecordingTranscriptPlaybackEffect
- videoElement={videoElement}
+ mediaElement={mediaElement}
timedItems={transcriptEntries}
onPlaybackPositionChange={setEntryPlaybackPosition}
/>
- <CallRecordingVideoPlayer
- key={videoFileUrl}
- ref={setVideoElement}
- src={videoFileUrl}
- onRetry={refetchCallRecording}
- />
+ {playbackMedia.kind === 'video' ? (
+ <CallRecordingVideoPlayer
+ key={playbackMedia.url}
+ ref={setMediaElement}
+ src={playbackMedia.url}
+ onRetry={refetchCallRecording}
+ />
+ ) : (
+ <CallRecordingAudioPlayer
+ key={playbackMedia.url}
+ ref={setMediaElement}
+ src={playbackMedia.url}
+ onRetry={refetchCallRecording}
+ />
+ )}
<CallRecordingTranscriptContent
callRecording={callRecording}
transcriptEntries={transcriptEntries}
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx
index 97a1adfa7af..3e00d003e1a 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx
@@ -100,8 +100,8 @@ export const CallRecordingTranscriptEntryList = ({
activeEntryElementRef={activeEntryElementRef}
isFollowingPlayback={isFollowingPlayback}
scrollContainerElementRef={scrollContainerElementRef}
- videoElement={playback?.videoElement}
- onVideoSeeking={resumeFollowingPlayback}
+ mediaElement={playback?.mediaElement}
+ onMediaSeeking={resumeFollowingPlayback}
/>
<StyledTranscriptScrollContainer
ref={scrollContainerElementRef}
@@ -127,7 +127,7 @@ export const CallRecordingTranscriptEntryList = ({
entry={entry}
entryElementRef={isActive ? activeEntryElementRef : undefined}
playbackPhase={playbackPhase}
- videoElement={playback?.videoElement}
+ mediaElement={playback?.mediaElement}
onSelect={hasPlayback ? selectTranscriptEntry : undefined}
/>
);
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
index 4fb4c489bc9..93fc25547ba 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
@@ -77,7 +77,7 @@ const StyledText = styled.p<{ isUpcoming: boolean }>`
type CallRecordingTranscriptEntryListItemProps = {
entry: CallRecordingParsedTranscriptEntry;
playbackPhase?: CallRecordingTranscriptEntryPlaybackPhase;
- videoElement?: HTMLVideoElement;
+ mediaElement?: HTMLMediaElement;
entryElementRef?: Ref<HTMLLIElement>;
onSelect?: (entryStartSeconds: number) => void;
};
@@ -85,7 +85,7 @@ type CallRecordingTranscriptEntryListItemProps = {
export const CallRecordingTranscriptEntryListItem = ({
entry,
playbackPhase,
- videoElement,
+ mediaElement,
entryElementRef,
onSelect,
}: CallRecordingTranscriptEntryListItemProps) => {
@@ -95,7 +95,7 @@ export const CallRecordingTranscriptEntryListItem = ({
const isActive = playbackPhase === 'speaking';
const hasPlaybackControls = isDefined(playbackPhase) || isDefined(onSelect);
const hasSpokenWordHighlight =
- isActive && isDefined(videoElement) && isNonEmptyArray(entry.words);
+ isActive && isDefined(mediaElement) && isNonEmptyArray(entry.words);
const formattedStartTimestamp = isDefined(entryStartSeconds)
? formatCallRecordingTranscriptTimestamp(entryStartSeconds)
: undefined;
@@ -154,7 +154,7 @@ export const CallRecordingTranscriptEntryListItem = ({
{hasSpokenWordHighlight ? (
<CallRecordingTranscriptEntryWords
words={entry.words}
- videoElement={videoElement}
+ mediaElement={mediaElement}
/>
) : (
entry.text
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryWords.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryWords.tsx
index 607cafa1402..6d1d69a5fcd 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryWords.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryWords.tsx
@@ -16,12 +16,12 @@ const StyledWord = styled.span<{ isSpoken: boolean }>`
type CallRecordingTranscriptEntryWordsProps = {
words: CallRecordingParsedTranscriptWord[];
- videoElement: HTMLVideoElement;
+ mediaElement: HTMLMediaElement;
};
export const CallRecordingTranscriptEntryWords = ({
words,
- videoElement,
+ mediaElement,
}: CallRecordingTranscriptEntryWordsProps) => {
const [wordPlaybackPosition, setWordPlaybackPosition] = useState(
INITIAL_CALL_RECORDING_TRANSCRIPT_PLAYBACK_POSITION,
@@ -30,7 +30,7 @@ export const CallRecordingTranscriptEntryWords = ({
return (
<>
<CallRecordingTranscriptPlaybackEffect
- videoElement={videoElement}
+ mediaElement={mediaElement}
timedItems={words}
onPlaybackPositionChange={setWordPlaybackPosition}
/>
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptFollowScrollEffect.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptFollowScrollEffect.tsx
index 8393b9d28fd..38b7e250ed6 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptFollowScrollEffect.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptFollowScrollEffect.tsx
@@ -6,45 +6,45 @@ type CallRecordingTranscriptFollowScrollEffectProps = {
activeEntryElementRef: RefObject<HTMLLIElement | null>;
isFollowingPlayback: boolean;
scrollContainerElementRef: RefObject<HTMLDivElement | null>;
- videoElement?: HTMLVideoElement;
- onVideoSeeking: () => void;
+ mediaElement?: HTMLMediaElement;
+ onMediaSeeking: () => void;
};
export const CallRecordingTranscriptFollowScrollEffect = ({
activeEntryElementRef,
isFollowingPlayback,
scrollContainerElementRef,
- videoElement,
- onVideoSeeking,
+ mediaElement,
+ onMediaSeeking,
}: CallRecordingTranscriptFollowScrollEffectProps) => {
useEffect(() => {
const scrollContainerElement = scrollContainerElementRef.current;
- if (!isDefined(videoElement)) {
+ if (!isDefined(mediaElement)) {
return;
}
- videoElement.addEventListener('seeking', onVideoSeeking);
+ mediaElement.addEventListener('seeking', onMediaSeeking);
const stopWatchingFollowScroll =
isFollowingPlayback && isDefined(scrollContainerElement)
? watchCallRecordingTranscriptFollowScroll({
- videoElement,
+ videoElement: mediaElement,
scrollContainerElement,
getActiveEntryElement: () => activeEntryElementRef.current,
})
: undefined;
return () => {
- videoElement.removeEventListener('seeking', onVideoSeeking);
+ mediaElement.removeEventListener('seeking', onMediaSeeking);
stopWatchingFollowScroll?.();
};
}, [
activeEntryElementRef,
isFollowingPlayback,
- onVideoSeeking,
+ onMediaSeeking,
scrollContainerElementRef,
- videoElement,
+ mediaElement,
]);
return null;
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptPlaybackEffect.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptPlaybackEffect.tsx
index 1b4da736184..70e22a024e3 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptPlaybackEffect.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptPlaybackEffect.tsx
@@ -6,7 +6,7 @@ import { useEffect, useMemo } from 'react';
import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
type CallRecordingTranscriptPlaybackEffectProps = {
- videoElement: HTMLVideoElement | null;
+ mediaElement: HTMLMediaElement | null;
timedItems: CallRecordingTranscriptTimedItem[] | undefined;
onPlaybackPositionChange: (
playbackPosition: CallRecordingTranscriptPlaybackPosition,
@@ -14,7 +14,7 @@ type CallRecordingTranscriptPlaybackEffectProps = {
};
export const CallRecordingTranscriptPlaybackEffect = ({
- videoElement,
+ mediaElement,
timedItems,
onPlaybackPositionChange,
}: CallRecordingTranscriptPlaybackEffectProps) => {
@@ -27,16 +27,16 @@ export const CallRecordingTranscriptPlaybackEffect = ({
);
useEffect(() => {
- if (!isDefined(videoElement) || !isNonEmptyArray(timePoints)) {
+ if (!isDefined(mediaElement) || !isNonEmptyArray(timePoints)) {
return;
}
return watchCallRecordingTranscriptPlayback({
- videoElement,
+ videoElement: mediaElement,
timePoints,
onPlaybackPositionChange,
});
- }, [videoElement, timePoints, onPlaybackPositionChange]);
+ }, [mediaElement, timePoints, onPlaybackPositionChange]);
return null;
};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptWidgetContent.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptWidgetContent.tsx
index e3f8a095cb7..2780ffcb5a3 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptWidgetContent.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptWidgetContent.tsx
@@ -1,6 +1,6 @@
import { useCallRecordingWidgetData } from '@/page-layout/widgets/call-recording/hooks/useCallRecordingWidgetData';
import { useCallRecordingWidgetTarget } from '@/page-layout/widgets/call-recording/hooks/useCallRecordingWidgetTarget';
-import { getCallRecordingVideoFileUrl } from '@/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl';
+import { getCallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia';
import { CallRecordingTranscriptBody } from '@/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody';
import { WidgetHeaderCountEffect } from '@/page-layout/widgets/components/WidgetHeaderCountEffect';
import { useMemo } from 'react';
@@ -33,7 +33,7 @@ export const CallRecordingTranscriptWidgetContent = () => {
[callRecordingForDisplay?.transcript],
);
- const videoFileUrl = getCallRecordingVideoFileUrl(callRecordingForDisplay);
+ const playbackMedia = getCallRecordingPlaybackMedia(callRecordingForDisplay);
const calendarEventHeaderCount = canExposeCallRecordingData
? callRecordingsCount
@@ -50,7 +50,7 @@ export const CallRecordingTranscriptWidgetContent = () => {
<CallRecordingTranscriptBody
callRecording={callRecording}
transcriptEntries={transcriptEntries}
- videoFileUrl={videoFileUrl}
+ playbackMedia={playbackMedia}
loading={loading}
error={error}
restriction={restriction}
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/WidgetActionCallRecordingTranscript.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/WidgetActionCallRecordingTranscript.tsx
index 2ed5459948d..dfc3e4a8811 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/WidgetActionCallRecordingTranscript.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/WidgetActionCallRecordingTranscript.tsx
@@ -1,6 +1,6 @@
import { WidgetActionCallRecordingSeeAll } from '@/page-layout/widgets/call-recording/components/WidgetActionCallRecordingSeeAll';
import { useCallRecordingForWidget } from '@/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget';
-import { getCallRecordingVideoFileUrl } from '@/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl';
+import { getCallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia';
import { buildCallRecordingTranscriptPlainText } from '@/page-layout/widgets/call-recording-transcript/utils/buildCallRecordingTranscriptPlainText';
import { WidgetCardHeaderActionButton } from '@/page-layout/widgets/widget-card/components/WidgetCardHeaderActionButton';
import { t } from '@lingui/core/macro';
@@ -33,7 +33,7 @@ export const WidgetActionCallRecordingTranscript = () => {
? buildCallRecordingTranscriptPlainText(transcriptEntries)
: undefined;
- const videoFileUrl = getCallRecordingVideoFileUrl(
+ const playbackMedia = getCallRecordingPlaybackMedia(
canExposeCallRecording ? callRecording : undefined,
);
@@ -51,12 +51,16 @@ export const WidgetActionCallRecordingTranscript = () => {
}
/>
)}
- {isDefined(videoFileUrl) && (
+ {isDefined(playbackMedia) && (
<WidgetCardHeaderActionButton
Icon={IconLink}
- label={t`Copy video download link`}
+ label={
+ playbackMedia.kind === 'video'
+ ? t`Copy video download link`
+ : t`Copy audio download link`
+ }
onClick={() =>
- copyToClipboard(videoFileUrl, t`Link copied to clipboard`)
+ copyToClipboard(playbackMedia.url, t`Link copied to clipboard`)
}
/>
)}
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingAudioPlayer.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingAudioPlayer.stories.tsx
new file mode 100644
index 00000000000..7bae4055499
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingAudioPlayer.stories.tsx
@@ -0,0 +1,92 @@
+import { CallRecordingAudioPlayer } from '@/page-layout/widgets/call-recording-transcript/components/CallRecordingAudioPlayer';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fireEvent, fn, spyOn, waitFor, within } from 'storybook/test';
+import { isDefined } from 'twenty-shared/utils';
+import { CatalogDecorator, type CatalogStory } from 'twenty-ui/testing';
+import { MOCK_CALL_RECORDING_AUDIO_DATA_URI } from './mockCallRecordingAudio';
+
+const meta: Meta<typeof CallRecordingAudioPlayer> = {
+ title: 'Modules/PageLayout/Widgets/CallRecordingAudioPlayer',
+ component: CallRecordingAudioPlayer,
+ args: {
+ src: MOCK_CALL_RECORDING_AUDIO_DATA_URI,
+ onRetry: fn(async () => {}),
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof CallRecordingAudioPlayer>;
+
+export const Catalog: CatalogStory<Story, typeof CallRecordingAudioPlayer> = {
+ decorators: [CatalogDecorator],
+ parameters: {
+ catalog: {
+ dimensions: [
+ {
+ name: 'state',
+ values: ['ready', 'error'],
+ props: (state: string) => ({
+ src:
+ state === 'error'
+ ? 'data:audio/wav,not-a-recording'
+ : MOCK_CALL_RECORDING_AUDIO_DATA_URI,
+ }),
+ },
+ ],
+ },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(await canvas.findByRole('slider', { name: 'Seek' })).toBeEnabled();
+ expect(await canvas.findByText('Playback failed')).toBeVisible();
+ expect(canvas.getByRole('button', { name: /^Retry/ })).toBeEnabled();
+ },
+};
+
+export const MediaStates: Story = {
+ tags: ['!dev', '!autodocs'],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const audioElement = canvasElement.querySelector('audio');
+
+ if (!isDefined(audioElement)) {
+ throw new Error('Audio player was not rendered');
+ }
+
+ await canvas.findByRole('slider', { name: 'Seek' });
+
+ const duration = spyOn(audioElement, 'duration', 'get');
+
+ for (const unknownDuration of [Number.NaN, Number.POSITIVE_INFINITY]) {
+ duration.mockReturnValue(unknownDuration);
+ fireEvent.durationChange(audioElement);
+
+ expect(await canvas.findByText('--:-- / --:--')).toBeVisible();
+ expect(
+ canvas.queryByRole('slider', { name: 'Seek' }),
+ ).not.toBeInTheDocument();
+ }
+
+ duration.mockRestore();
+ fireEvent.durationChange(audioElement);
+
+ await canvas.findByRole('slider', { name: 'Seek' });
+
+ fireEvent.play(audioElement);
+ fireEvent.waiting(audioElement);
+
+ const pauseButton = await canvas.findByRole('button', { name: 'Pause' });
+
+ expect(pauseButton.querySelector('circle')).toBeInTheDocument();
+
+ fireEvent.pause(audioElement);
+
+ await waitFor(() => {
+ const playButton = canvas.getByRole('button', { name: 'Play' });
+
+ expect(playButton.querySelector('circle')).not.toBeInTheDocument();
+ expect(canvas.queryByText('Playback failed')).not.toBeInTheDocument();
+ });
+ },
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
index b5182716167..63465fa20c1 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/CallRecordingTranscriptBody.stories.tsx
@@ -3,7 +3,7 @@ import { type PageLayout } from '@/page-layout/types/PageLayout';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import { getCallRecordingWidgetStoryDecorator } from '@/page-layout/widgets/call-recording/testing/getCallRecordingWidgetStoryDecorator';
import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
-import { getCallRecordingVideoFileUrl } from '@/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl';
+import { getCallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia';
import { CallRecordingTranscriptBody } from '@/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptBody';
import { CALL_RECORDING_TRANSCRIPT_CURRENT_SPOKEN_WORD_DATA_ATTRIBUTE } from '@/page-layout/widgets/call-recording-transcript/constants/CallRecordingTranscriptCurrentSpokenWordDataAttribute';
import { WidgetHeaderCountEffect } from '@/page-layout/widgets/components/WidgetHeaderCountEffect';
@@ -33,6 +33,7 @@ import {
import { CallRecordingStatus } from '~/generated/graphql';
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
+import { MOCK_CALL_RECORDING_AUDIO_DATA_URI } from './mockCallRecordingAudio';
import { MOCK_CALL_RECORDING_VIDEO_DATA_URI } from './mockCallRecordingVideo';
const TRANSCRIPT_WIDGET_ID = 'transcript-widget';
@@ -247,6 +248,18 @@ const recordedCallRecording: WidgetCallRecordingCandidate = {
],
};
+const audioCallRecording: WidgetCallRecordingCandidate = {
+ ...readableCallRecording,
+ audio: [
+ {
+ fileId: 'audio-file-id',
+ label: 'recording.wav',
+ extension: 'wav',
+ url: MOCK_CALL_RECORDING_AUDIO_DATA_URI,
+ },
+ ],
+};
+
const unplayableRecordedCallRecording: WidgetCallRecordingCandidate = {
...recordedCallRecording,
video: [
@@ -261,7 +274,7 @@ const unplayableRecordedCallRecording: WidgetCallRecordingCandidate = {
type CallRecordingTranscriptBodyStoryProps = Omit<
ComponentProps<typeof CallRecordingTranscriptBody>,
- 'transcriptEntries' | 'videoFileUrl'
+ 'transcriptEntries' | 'playbackMedia'
>;
const CallRecordingTranscriptBodyStory = (
@@ -277,7 +290,7 @@ const CallRecordingTranscriptBodyStory = (
const transcriptEntries = parseCallRecordingTranscriptEntries(
callRecordingForDisplay?.transcript,
);
- const videoFileUrl = getCallRecordingVideoFileUrl(callRecordingForDisplay);
+ const playbackMedia = getCallRecordingPlaybackMedia(callRecordingForDisplay);
return (
<>
@@ -289,7 +302,7 @@ const CallRecordingTranscriptBodyStory = (
<CallRecordingTranscriptBody
{...args}
transcriptEntries={transcriptEntries}
- videoFileUrl={videoFileUrl}
+ playbackMedia={playbackMedia}
/>
</>
);
@@ -575,6 +588,200 @@ export const WithVideoInteractions: Story = {
},
};
+const AUDIO_STORY_CONFIGURATION = {
+ args: {
+ callRecording: audioCallRecording,
+ loading: false,
+ error: undefined,
+ restriction: undefined,
+ },
+ parameters: {
+ msw: {
+ handlers: [
+ graphql.query('CallRecordingIdForCalendarEvent', () =>
+ HttpResponse.json({
+ data: {
+ callRecordingIdForCalendarEvent: audioCallRecording.id,
+ },
+ }),
+ ),
+ graphql.query('FindOneCallRecording', () =>
+ HttpResponse.json({ data: { callRecording: audioCallRecording } }),
+ ),
+ ],
+ },
+ },
+} satisfies Story;
+
+export const WithAudio: Story = {
+ ...AUDIO_STORY_CONFIGURATION,
+ play: async ({ canvasElement, userEvent }) => {
+ const canvas = within(canvasElement);
+ const transcriptRegion = await canvas.findByRole('region', {
+ name: 'Transcript',
+ });
+ const audioElement = canvasElement.querySelector('audio');
+
+ if (!isDefined(audioElement)) {
+ throw new Error('Audio player was not rendered');
+ }
+
+ expect(canvasElement.querySelector('video')).not.toBeInTheDocument();
+ expect(
+ await canvas.findByRole('button', { name: 'Copy audio download link' }),
+ ).toBeVisible();
+ expect(
+ canvas.queryByRole('button', { name: 'Copy video download link' }),
+ ).not.toBeInTheDocument();
+
+ await waitFor(() => {
+ expect(audioElement.duration).toBeCloseTo(59);
+ expect(audioElement.seekable.length).toBeGreaterThan(0);
+ });
+
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Seek recording to 0:46' }),
+ );
+
+ await waitFor(() => {
+ expect(audioElement.currentTime).toBeCloseTo(46);
+ expect(
+ canvasElement.querySelector('[aria-current="true"]'),
+ ).toHaveTextContent("Perfect, let's gather final feedback and wrap up.");
+ expect(
+ canvasElement.querySelector(
+ `[${CALL_RECORDING_TRANSCRIPT_CURRENT_SPOKEN_WORD_DATA_ATTRIBUTE}]`,
+ ),
+ ).toHaveTextContent('Perfect,');
+ expect(transcriptRegion.scrollTop).toBeGreaterThan(0);
+ });
+
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Seek recording to 0:06' }),
+ );
+
+ await waitFor(() => {
+ expect(canvasElement.querySelector('audio')).toBe(audioElement);
+ expect(audioElement.currentTime).toBeCloseTo(6);
+ expect(canvas.getByRole('slider', { name: 'Seek' })).toHaveValue('6');
+ expect(
+ canvasElement.querySelector('[aria-current="true"]'),
+ ).toHaveTextContent(
+ 'The first milestone is complete and ready for review.',
+ );
+ });
+ },
+};
+
+export const AudioSeekInteractions: Story = {
+ ...AUDIO_STORY_CONFIGURATION,
+ tags: ['!dev', '!autodocs'],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const audioElement = canvasElement.querySelector('audio');
+
+ if (!isDefined(audioElement)) {
+ throw new Error('Audio player was not rendered');
+ }
+
+ const seekSlider = await canvas.findByRole('slider', { name: 'Seek' });
+
+ await waitFor(() => expect(seekSlider).toBeEnabled());
+
+ audioElement.currentTime = 6;
+ fireEvent.timeUpdate(audioElement);
+
+ // Synthetic pointer events cannot acquire a native pointer capture.
+ const setPointerCapture = spyOn(
+ seekSlider,
+ 'setPointerCapture',
+ ).mockImplementation(() => {});
+
+ fireEvent.pointerDown(seekSlider);
+ fireEvent.input(seekSlider, { target: { value: '22' } });
+ fireEvent.timeUpdate(audioElement);
+
+ expect(seekSlider).toHaveValue('22');
+ expect(audioElement.currentTime).toBeCloseTo(6);
+
+ fireEvent.pointerUp(seekSlider);
+ setPointerCapture.mockRestore();
+
+ await waitFor(() => expect(audioElement.currentTime).toBeCloseTo(22));
+
+ const { userEvent: browserUserEvent } = await import('vitest/browser');
+
+ seekSlider.focus();
+ await browserUserEvent.keyboard('{ArrowRight}');
+
+ await waitFor(() => expect(audioElement.currentTime).toBeGreaterThan(22));
+ expect(seekSlider).toHaveAttribute('aria-valuetext', expect.any(String));
+
+ await browserUserEvent.click(
+ canvas.getByRole('button', { name: 'Seek recording to 0:06' }),
+ );
+
+ await browserUserEvent.click(canvas.getByRole('button', { name: 'Play' }));
+ expect(await canvas.findByRole('button', { name: 'Pause' })).toBeVisible();
+
+ await waitFor(() => {
+ expect(audioElement.currentTime).toBeGreaterThan(6.5);
+ expect(
+ canvasElement.querySelector(
+ `[${CALL_RECORDING_TRANSCRIPT_CURRENT_SPOKEN_WORD_DATA_ATTRIBUTE}]`,
+ ),
+ ).not.toHaveTextContent(/^The$/);
+ });
+
+ await browserUserEvent.click(canvas.getByRole('button', { name: 'Pause' }));
+
+ expect(audioElement.paused).toBe(true);
+ },
+};
+
+export const AudioPlaybackError: Story = {
+ ...AUDIO_STORY_CONFIGURATION,
+ args: {
+ ...AUDIO_STORY_CONFIGURATION.args,
+ refetchCallRecording: fn(async () => {}),
+ },
+ play: async ({ args, canvasElement, userEvent }) => {
+ const canvas = within(canvasElement);
+ const audioElement = canvasElement.querySelector('audio');
+
+ if (!isDefined(audioElement)) {
+ throw new Error('Audio player was not rendered');
+ }
+
+ await waitFor(() => expect(audioElement.duration).toBeCloseTo(59));
+
+ const transcriptRegion = canvas.getByRole('region', { name: 'Transcript' });
+ const initialTranscriptTop = transcriptRegion.getBoundingClientRect().top;
+
+ fireEvent.error(audioElement);
+
+ expect(await canvas.findByText('Playback failed')).toBeVisible();
+ expect(transcriptRegion.getBoundingClientRect().top).toBe(
+ initialTranscriptTop,
+ );
+ expect(
+ canvas.queryByRole('slider', { name: 'Seek' }),
+ ).not.toBeInTheDocument();
+
+ await userEvent.click(canvas.getByRole('button', { name: /^Retry/ }));
+
+ expect(args.refetchCallRecording).toHaveBeenCalledTimes(1);
+
+ await waitFor(() => {
+ expect(canvas.queryByText('Playback failed')).not.toBeInTheDocument();
+ expect(canvas.getByRole('slider', { name: 'Seek' })).toBeEnabled();
+ expect(audioElement.readyState).toBeGreaterThanOrEqual(
+ HTMLMediaElement.HAVE_METADATA,
+ );
+ });
+ },
+};
+
export const Loading: Story = {
args: {
callRecording: undefined,
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/mockCallRecordingAudio.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/mockCallRecordingAudio.ts
new file mode 100644
index 00000000000..8107320718c
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/__stories__/mockCallRecordingAudio.ts
@@ -0,0 +1,24 @@
+const SAMPLE_RATE = 8000;
+const SAMPLE_COUNT = SAMPLE_RATE * 59;
+const headerBytes = new Uint8Array(44);
+const header = new DataView(headerBytes.buffer);
+
+headerBytes.set(new TextEncoder().encode('RIFF'), 0);
+header.setUint32(4, 36 + SAMPLE_COUNT, true);
+headerBytes.set(new TextEncoder().encode('WAVEfmt '), 8);
+header.setUint32(16, 16, true);
+header.setUint16(20, 1, true);
+header.setUint16(22, 1, true);
+header.setUint32(24, SAMPLE_RATE, true);
+header.setUint32(28, SAMPLE_RATE, true);
+header.setUint16(32, 1, true);
+header.setUint16(34, 8, true);
+headerBytes.set(new TextEncoder().encode('data'), 36);
+header.setUint32(40, SAMPLE_COUNT, true);
+
+// A generated silent WAV keeps the fixture small in source and seekable in
+// Chromium, unlike media served through the msw service worker passthrough.
+export const MOCK_CALL_RECORDING_AUDIO_DATA_URI = `data:audio/wav;base64,${btoa(
+ String.fromCharCode(...headerBytes) +
+ String.fromCharCode(128).repeat(SAMPLE_COUNT),
+)}`;
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/types/CallRecordingTranscriptPlayback.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/types/CallRecordingTranscriptPlayback.ts
index e552b5a58dd..b019ca40934 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/types/CallRecordingTranscriptPlayback.ts
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/types/CallRecordingTranscriptPlayback.ts
@@ -2,6 +2,6 @@ import { type CallRecordingTranscriptPlaybackPosition } from '@/page-layout/widg
export type CallRecordingTranscriptPlayback = {
position: CallRecordingTranscriptPlaybackPosition;
- videoElement: HTMLVideoElement;
+ mediaElement: HTMLMediaElement;
onSeek: (startSeconds: number) => void;
};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/__tests__/useCallRecordingForWidget.test.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/__tests__/useCallRecordingForWidget.test.tsx
new file mode 100644
index 00000000000..dc7b4b03108
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/__tests__/useCallRecordingForWidget.test.tsx
@@ -0,0 +1,93 @@
+import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
+import { useCallRecordingForWidget } from '@/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget';
+import { renderHook } from '@testing-library/react';
+
+let restrictedFields = new Set<string>();
+
+jest.mock('@/object-record/hooks/useFindOneRecord', () => ({
+ useFindOneRecord: jest.fn(() => ({ loading: false, refetch: jest.fn() })),
+}));
+
+jest.mock(
+ '@/page-layout/widgets/call-recording/hooks/useCallRecordingIdForWidget',
+ () => ({
+ useCallRecordingIdForWidget: () => ({
+ callRecordingId: 'call-recording-id',
+ targetKind: 'callRecording',
+ loading: false,
+ refetchCallRecordingId: jest.fn(),
+ }),
+ }),
+);
+
+jest.mock(
+ '@/page-layout/widgets/call-recording/hooks/useCallRecordingWidgetRestriction',
+ () => ({
+ useCallRecordingWidgetRestriction: () => ({
+ restriction: undefined,
+ isFieldRestricted: (fieldName: string) => restrictedFields.has(fieldName),
+ }),
+ }),
+);
+
+const getRequestedFields = () =>
+ jest.mocked(useFindOneRecord).mock.calls.at(-1)?.[0].recordGqlFields;
+
+describe('useCallRecordingForWidget', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ restrictedFields = new Set();
+ });
+
+ it.each([
+ { restricted: [], mediaFields: { video: true, audio: true } },
+ { restricted: ['video'], mediaFields: { audio: true } },
+ { restricted: ['audio'], mediaFields: { video: true } },
+ { restricted: ['video', 'audio'], mediaFields: {} },
+ ])(
+ 'omits restricted media fields: $restricted',
+ ({ restricted, mediaFields }) => {
+ restrictedFields = new Set(restricted);
+
+ renderHook(() => useCallRecordingForWidget({ kind: 'transcript' }));
+
+ expect(getRequestedFields()).toEqual({
+ id: true,
+ status: true,
+ transcript: true,
+ ...mediaFields,
+ });
+ },
+ );
+
+ it('does not request media for the summary widget', () => {
+ renderHook(() => useCallRecordingForWidget({ kind: 'summary' }));
+
+ expect(getRequestedFields()).toEqual({
+ id: true,
+ status: true,
+ summary: true,
+ });
+ });
+
+ it('keeps fields stable until media permissions change', () => {
+ const { rerender } = renderHook(() =>
+ useCallRecordingForWidget({ kind: 'transcript' }),
+ );
+ const initialFields = getRequestedFields();
+
+ rerender();
+
+ expect(getRequestedFields()).toBe(initialFields);
+
+ restrictedFields = new Set(['video']);
+ rerender();
+
+ expect(getRequestedFields()).toEqual({
+ id: true,
+ status: true,
+ transcript: true,
+ audio: true,
+ });
+ });
+});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget.ts
index 957383777dc..32e382044e2 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget.ts
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/hooks/useCallRecordingForWidget.ts
@@ -4,7 +4,7 @@ import { useCallRecordingWidgetRestriction } from '@/page-layout/widgets/call-re
import { type CallRecordingWidgetKind } from '@/page-layout/widgets/call-recording/types/CallRecordingWidgetKind';
import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
import { type WidgetAccessDenialInfo } from '@/page-layout/widgets/types/WidgetAccessDenialInfo';
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import {
CoreObjectNameSingular,
type RecordGqlOperationGqlRecordFields,
@@ -43,12 +43,22 @@ export const useCallRecordingForWidget = ({
refetchCallRecordingId,
} = useCallRecordingIdForWidget({ skip: shouldSkipQuery });
- // The transcript widget plays the video, but requesting a field the role
+ const isVideoRestricted = isFieldRestricted('video');
+ const isAudioRestricted = isFieldRestricted('audio');
+
+ // The transcript widget plays media, but requesting a field the role
// cannot read fails the whole query.
- const recordGqlFields =
- kind === 'transcript' && !isFieldRestricted('video')
- ? CALL_RECORDING_TRANSCRIPT_RECORD_FIELDS_WITH_VIDEO
- : CALL_RECORDING_RECORD_FIELDS_BY_WIDGET_KIND[kind];
+ const recordGqlFields = useMemo(
+ () =>
+ kind === 'transcript'
+ ? {
+ ...CALL_RECORDING_RECORD_FIELDS_BY_WIDGET_KIND.transcript,
+ ...(!isVideoRestricted && { video: true }),
+ ...(!isAudioRestricted && { audio: true }),
+ }
+ : CALL_RECORDING_RECORD_FIELDS_BY_WIDGET_KIND[kind],
+ [kind, isVideoRestricted, isAudioRestricted],
+ );
const {
record: callRecording,
@@ -80,10 +90,3 @@ export const useCallRecordingForWidget = ({
refetchCallRecording,
};
};
-
-// Selected between stable maps so the query hook's memoised fields do not
-// change identity on every render.
-const CALL_RECORDING_TRANSCRIPT_RECORD_FIELDS_WITH_VIDEO = {
- ...CALL_RECORDING_RECORD_FIELDS_BY_WIDGET_KIND.transcript,
- video: true,
-};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/testing/getCallRecordingWidgetStoryDecorator.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/testing/getCallRecordingWidgetStoryDecorator.tsx
index 5bd8f6d7a0c..410aa6a46e6 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/testing/getCallRecordingWidgetStoryDecorator.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/testing/getCallRecordingWidgetStoryDecorator.tsx
@@ -38,6 +38,7 @@ const CALL_RECORDING_FIELD_METADATA_IDS = {
summary: '20202020-0000-0000-0000-000000000014',
video: '20202020-0000-0000-0000-000000000015',
createdAt: '20202020-0000-0000-0000-000000000016',
+ audio: '20202020-0000-0000-0000-000000000017',
} as const;
const getFieldMetadataItemByTypeOrThrow = (
@@ -129,6 +130,12 @@ export const getCallRecordingWidgetStoryDecorator =
label: 'Video',
type: FieldMetadataType.FILES,
}),
+ createCallRecordingFieldMetadataItem({
+ id: CALL_RECORDING_FIELD_METADATA_IDS.audio,
+ name: 'audio',
+ label: 'Audio',
+ type: FieldMetadataType.FILES,
+ }),
createCallRecordingFieldMetadataItem({
id: CALL_RECORDING_FIELD_METADATA_IDS.createdAt,
name: 'createdAt',
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/CallRecordingPlaybackMedia.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/CallRecordingPlaybackMedia.ts
new file mode 100644
index 00000000000..6377dbf3ebf
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/CallRecordingPlaybackMedia.ts
@@ -0,0 +1,4 @@
+export type CallRecordingPlaybackMedia = {
+ url: string;
+ kind: 'video' | 'audio';
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate.ts
index 03fe590da86..59accba31af 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate.ts
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate.ts
@@ -8,4 +8,5 @@ export type WidgetCallRecordingCandidate = {
transcript?: unknown;
summary?: { markdown: string | null } | null;
video?: FieldFilesValue[] | null;
+ audio?: FieldFilesValue[] | null;
};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingPlaybackMedia.test.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingPlaybackMedia.test.ts
new file mode 100644
index 00000000000..abbd54fc596
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingPlaybackMedia.test.ts
@@ -0,0 +1,81 @@
+import { type FieldFilesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { getCallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia';
+
+const VIDEO_URL = 'https://files.example.com/recording.mp4';
+const AUDIO_URL = 'https://files.example.com/recording.mp3';
+
+const makeFile = (url?: string): FieldFilesValue => ({
+ fileId: 'recording-file',
+ label: 'recording',
+ extension: 'mp4',
+ url,
+});
+
+describe('getCallRecordingPlaybackMedia', () => {
+ it('returns video when only video is available', () => {
+ expect(
+ getCallRecordingPlaybackMedia({ video: [makeFile(VIDEO_URL)] }),
+ ).toEqual({ url: VIDEO_URL, kind: 'video' });
+ });
+
+ it('returns audio when only audio is available', () => {
+ expect(
+ getCallRecordingPlaybackMedia({ audio: [makeFile(AUDIO_URL)] }),
+ ).toEqual({ url: AUDIO_URL, kind: 'audio' });
+ });
+
+ it('prefers video when both are available', () => {
+ expect(
+ getCallRecordingPlaybackMedia({
+ video: [makeFile(VIDEO_URL)],
+ audio: [makeFile(AUDIO_URL)],
+ }),
+ ).toEqual({ url: VIDEO_URL, kind: 'video' });
+ });
+
+ it.each([
+ undefined,
+ {},
+ { video: null, audio: null },
+ { video: [], audio: [] },
+ ])(
+ 'returns undefined when neither media is available: %j',
+ (callRecording) => {
+ expect(getCallRecordingPlaybackMedia(callRecording)).toBeUndefined();
+ },
+ );
+
+ it.each([undefined, '', ' ', '\t\n'])(
+ 'falls back to audio when the video url is blank: %j',
+ (url) => {
+ expect(
+ getCallRecordingPlaybackMedia({
+ video: [makeFile(url)],
+ audio: [makeFile(AUDIO_URL)],
+ }),
+ ).toEqual({ url: AUDIO_URL, kind: 'audio' });
+ },
+ );
+
+ it('returns the first playable file, skipping blank urls', () => {
+ expect(
+ getCallRecordingPlaybackMedia({
+ video: [makeFile(), makeFile(' '), makeFile(VIDEO_URL)],
+ }),
+ ).toEqual({ url: VIDEO_URL, kind: 'video' });
+ expect(
+ getCallRecordingPlaybackMedia({
+ audio: [makeFile(), makeFile(' '), makeFile(AUDIO_URL)],
+ }),
+ ).toEqual({ url: AUDIO_URL, kind: 'audio' });
+ });
+
+ it('returns undefined when both files have blank urls', () => {
+ expect(
+ getCallRecordingPlaybackMedia({
+ video: [makeFile('')],
+ audio: [makeFile(' ')],
+ }),
+ ).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingVideoFileUrl.test.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingVideoFileUrl.test.ts
deleted file mode 100644
index 2adc04cbc51..00000000000
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/__tests__/getCallRecordingVideoFileUrl.test.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
-import { getCallRecordingVideoFileUrl } from '@/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl';
-
-const makeCallRecording = (
- video: WidgetCallRecordingCandidate['video'],
-): Pick<WidgetCallRecordingCandidate, 'video'> => ({
- video,
-});
-
-describe('getCallRecordingVideoFileUrl', () => {
- it('returns the first video file url with a non-empty url', () => {
- expect(
- getCallRecordingVideoFileUrl(
- makeCallRecording([
- {
- fileId: 'file-without-url',
- label: 'broken.mp4',
- extension: 'mp4',
- },
- {
- fileId: 'file-with-url',
- label: 'recording.mp4',
- extension: 'mp4',
- url: 'https://files.example.com/recording.mp4',
- },
- ]),
- ),
- ).toBe('https://files.example.com/recording.mp4');
- });
-
- it('returns undefined without a playable video file', () => {
- expect(getCallRecordingVideoFileUrl(makeCallRecording(null))).toBe(
- undefined,
- );
- expect(getCallRecordingVideoFileUrl(makeCallRecording([]))).toBe(undefined);
- });
-});
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia.ts
new file mode 100644
index 00000000000..01003d90eba
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingPlaybackMedia.ts
@@ -0,0 +1,23 @@
+import { type CallRecordingPlaybackMedia } from '@/page-layout/widgets/call-recording/types/CallRecordingPlaybackMedia';
+import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
+import { isNonEmptyString } from '@sniptt/guards';
+
+const PLAYBACK_MEDIA_PRIORITY = ['video', 'audio'] as const;
+
+export const getCallRecordingPlaybackMedia = (
+ callRecording:
+ | Pick<WidgetCallRecordingCandidate, 'video' | 'audio'>
+ | undefined,
+): CallRecordingPlaybackMedia | undefined => {
+ for (const kind of PLAYBACK_MEDIA_PRIORITY) {
+ const url = callRecording?.[kind]?.find((file) =>
+ isNonEmptyString(file.url?.trim()),
+ )?.url;
+
+ if (isNonEmptyString(url)) {
+ return { url, kind };
+ }
+ }
+
+ return undefined;
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl.ts b/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl.ts
deleted file mode 100644
index 258d61b7d4a..00000000000
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording/utils/getCallRecordingVideoFileUrl.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { type WidgetCallRecordingCandidate } from '@/page-layout/widgets/call-recording/types/WidgetCallRecordingCandidate';
-import { isNonEmptyString } from '@sniptt/guards';
-
-export const getCallRecordingVideoFileUrl = (
- callRecording: Pick<WidgetCallRecordingCandidate, 'video'> | undefined,
-): string | undefined =>
- callRecording?.video?.find((videoFile) => isNonEmptyString(videoFile.url))
- ?.url;