feat: add setting to automatic start recording (#21853)

* feat: disable transcription setting in cal video

* feat: add enable automatic recording feature

* chore: only when organizer joins

* chore: update name of variable

* fix: improvements

* chore: improvements

* chore: add badge

* refactor: cal video premium

* tests: add tests for cal video

* fix: use isOrganizer

* Simplify type to remove 'as SessionUser' from new code

---------

Co-authored-by: Benny Joo <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-15 16:54:23 +01:00
1 parent 8ee7b12c2b
commit 10bf982028
19 files changed
+857 -197

No files matched your search

@@ -0,0 +1,492 @@
import type { DailyCall } from "@daily-co/daily-js";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { BUTTONS } from "../button-states";
import { createCalVideoCallbacks } from "../cal-video-premium-features";
vi.mock("@calcom/lib/constants", () => ({
TRANSCRIPTION_STARTED_ICON: "/transcription-started-icon.svg",
RECORDING_IN_PROGRESS_ICON: "/recording-in-progress-icon.svg",
TRANSCRIPTION_STOPPED_ICON: "/transcription-stopped-icon.svg",
RECORDING_DEFAULT_ICON: "/recording-default-icon.svg",
}));
const mockDaily: DailyCall = {
startRecording: vi.fn(),
stopRecording: vi.fn(),
startTranscription: vi.fn(),
stopTranscription: vi.fn(),
updateCustomTrayButtons: vi.fn(),
} as unknown as DailyCall;
const createMockRecording = (isRecording = false) => ({
isRecording,
});
const createMockTranscription = (isTranscribing = false) => ({
isTranscribing,
});
describe("CalVideoPremiumFeatures - End-to-End Callback Tests", () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe("onMeetingJoined", () => {
it("should start transcription automatically when enabled and not already transcribing", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(false), // not transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onMeetingJoined();
expect(mockDaily.startTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).not.toHaveBeenCalled();
});
it("should start recording automatically when enabled and not already recording", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false), // not recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: true,
});
callbacks.onMeetingJoined();
expect(mockDaily.startRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).toHaveBeenCalledWith({
videoBitrate: 2000,
});
expect(mockDaily.startTranscription).not.toHaveBeenCalled();
});
it("should start both transcription and recording when both are enabled", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false),
transcription: createMockTranscription(false),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: true,
});
callbacks.onMeetingJoined();
expect(mockDaily.startTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).toHaveBeenCalledTimes(1);
});
it("should not start transcription when already transcribing", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(true), // already transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onMeetingJoined();
expect(mockDaily.startTranscription).not.toHaveBeenCalled();
});
it("should not start recording when already recording", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(true), // already recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: true,
});
callbacks.onMeetingJoined();
expect(mockDaily.startRecording).not.toHaveBeenCalled();
});
});
describe("onCustomButtonClick - Recording Button", () => {
it("should start recording when click occurs on Recording button and recording is stopped", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false), // not recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.onCustomButtonClick({ button_id: "recording" });
expect(mockDaily.startRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).toHaveBeenCalledWith({
videoBitrate: 2000,
});
expect(mockDaily.stopRecording).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_START,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
it("should stop recording when click occurs on Recording button and recording is started", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(true), // currently recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.onCustomButtonClick({ button_id: "recording" });
expect(mockDaily.stopRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_STOP,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
});
describe("onCustomButtonClick - Transcription Button", () => {
it("should start transcription when click occurs on Transcription button and transcription is stopped", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(false), // not transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.onCustomButtonClick({ button_id: "transcription" });
expect(mockDaily.startTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.stopTranscription).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_START,
});
});
it("should stop transcription when click occurs on Transcription button and transcription is started", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(true), // currently transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.onCustomButtonClick({ button_id: "transcription" });
expect(mockDaily.stopTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.startTranscription).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_STOP,
});
});
});
describe("onRecordingStarted", () => {
it("should update custom tray buttons to show stop recording button", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onRecordingStarted();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.STOP_RECORDING,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
});
describe("onRecordingStopped", () => {
it("should update custom tray buttons to show start recording button", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onRecordingStopped();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
});
describe("onTranscriptionStarted", () => {
it("should update custom tray buttons to show stop transcription button", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onTranscriptionStarted();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
});
});
describe("onTranscriptionStopped", () => {
it("should update custom tray buttons to show start transcription button", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.onTranscriptionStopped();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.START_TRANSCRIPTION,
});
});
});
describe("toggleRecording", () => {
it("should start recording when not currently recording", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false), // not recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.toggleRecording();
expect(mockDaily.startRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).toHaveBeenCalledWith({
videoBitrate: 2000,
});
expect(mockDaily.stopRecording).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_START,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
it("should stop recording when currently recording", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(true), // currently recording
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.toggleRecording();
expect(mockDaily.stopRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_STOP,
transcription: BUTTONS.START_TRANSCRIPTION, // current state included
});
});
});
describe("toggleTranscription", () => {
it("should start transcription when not currently transcribing", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(false), // not transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.toggleTranscription();
expect(mockDaily.startTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.stopTranscription).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_START,
});
});
it("should stop transcription when currently transcribing", async () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(true), // currently transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
await callbacks.toggleTranscription();
expect(mockDaily.stopTranscription).toHaveBeenCalledTimes(1);
expect(mockDaily.startTranscription).not.toHaveBeenCalled();
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.START_RECORDING, // current state included
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_STOP,
});
});
});
describe("updateCustomTrayButtons", () => {
it("should update both recording and transcription buttons when both are shown", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false),
transcription: createMockTranscription(false),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.updateCustomTrayButtons({
recording: BUTTONS.STOP_RECORDING,
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.STOP_RECORDING,
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
});
it("should update only recording button when transcription button is not shown", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false),
transcription: createMockTranscription(false),
showRecordingButton: true,
showTranscriptionButton: false,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.updateCustomTrayButtons({
recording: BUTTONS.STOP_RECORDING,
});
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.STOP_RECORDING,
});
});
it("should update only transcription button when recording button is not shown", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(false),
transcription: createMockTranscription(false),
showRecordingButton: false,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.updateCustomTrayButtons({
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
});
it("should use current state when no override is provided", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(true), // currently recording
transcription: createMockTranscription(false), // not transcribing
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.updateCustomTrayButtons({});
expect(mockDaily.updateCustomTrayButtons).toHaveBeenCalledWith({
recording: BUTTONS.STOP_RECORDING, // because isRecording is true
transcription: BUTTONS.START_TRANSCRIPTION, // because isTranscribing is false
});
});
});
describe("startRecording", () => {
it("should call daily.startRecording with correct parameters", () => {
const callbacks = createCalVideoCallbacks({
daily: mockDaily,
recording: createMockRecording(),
transcription: createMockTranscription(),
showRecordingButton: true,
showTranscriptionButton: true,
enableAutomaticTranscription: false,
enableAutomaticRecordingForOrganizer: false,
});
callbacks.startRecording();
expect(mockDaily.startRecording).toHaveBeenCalledTimes(1);
expect(mockDaily.startRecording).toHaveBeenCalledWith({
videoBitrate: 2000,
});
});
});
});
+57
View File
@@ -0,0 +1,57 @@
import {
TRANSCRIPTION_STARTED_ICON,
RECORDING_IN_PROGRESS_ICON,
TRANSCRIPTION_STOPPED_ICON,
RECORDING_DEFAULT_ICON,
} from "@calcom/lib/constants";
export const BUTTONS = {
STOP_TRANSCRIPTION: {
label: "Stop",
tooltip: "Stop transcription",
iconPath: TRANSCRIPTION_STARTED_ICON,
iconPathDarkMode: TRANSCRIPTION_STARTED_ICON,
},
START_TRANSCRIPTION: {
label: "Cal.ai",
tooltip: "Transcription powered by AI",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
WAIT_FOR_TRANSCRIPTION_TO_START: {
label: "Starting..",
tooltip: "Please wait while we start transcription",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
WAIT_FOR_TRANSCRIPTION_TO_STOP: {
label: "Stopping..",
tooltip: "Please wait while we stop transcription",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
START_RECORDING: {
label: "Record",
tooltip: "Start recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
WAIT_FOR_RECORDING_TO_START: {
label: "Starting..",
tooltip: "Please wait while we start recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
WAIT_FOR_RECORDING_TO_STOP: {
label: "Stopping..",
tooltip: "Please wait while we stop recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
STOP_RECORDING: {
label: "Stop",
tooltip: "Stop recording",
iconPath: RECORDING_IN_PROGRESS_ICON,
iconPathDarkMode: RECORDING_IN_PROGRESS_ICON,
},
};
@@ -1,65 +1,9 @@
import type { DailyCall } from "@daily-co/daily-js";
import { useTranscription, useRecording } from "@daily-co/daily-react";
import { useDaily, useDailyEvent } from "@daily-co/daily-react";
import React, { Fragment, useCallback, useRef, useState, useLayoutEffect, useEffect } from "react";
import {
TRANSCRIPTION_STARTED_ICON,
RECORDING_IN_PROGRESS_ICON,
TRANSCRIPTION_STOPPED_ICON,
RECORDING_DEFAULT_ICON,
} from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
const BUTTONS = {
STOP_TRANSCRIPTION: {
label: "Stop",
tooltip: "Stop transcription",
iconPath: TRANSCRIPTION_STARTED_ICON,
iconPathDarkMode: TRANSCRIPTION_STARTED_ICON,
},
START_TRANSCRIPTION: {
label: "Cal.ai",
tooltip: "Transcription powered by AI",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
WAIT_FOR_TRANSCRIPTION_TO_START: {
label: "Starting..",
tooltip: "Please wait while we start transcription",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
WAIT_FOR_TRANSCRIPTION_TO_STOP: {
label: "Stopping..",
tooltip: "Please wait while we stop transcription",
iconPath: TRANSCRIPTION_STOPPED_ICON,
iconPathDarkMode: TRANSCRIPTION_STOPPED_ICON,
},
START_RECORDING: {
label: "Record",
tooltip: "Start recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
WAIT_FOR_RECORDING_TO_START: {
label: "Starting..",
tooltip: "Please wait while we start recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
WAIT_FOR_RECORDING_TO_STOP: {
label: "Stopping..",
tooltip: "Please wait while we stop recording",
iconPath: RECORDING_DEFAULT_ICON,
iconPathDarkMode: RECORDING_DEFAULT_ICON,
},
STOP_RECORDING: {
label: "Stop",
tooltip: "Stop recording",
iconPath: RECORDING_IN_PROGRESS_ICON,
iconPathDarkMode: RECORDING_IN_PROGRESS_ICON,
},
};
import { BUTTONS } from "./button-states";
export type DailyCustomTrayButtonVisualState = "default" | "sidebar-open" | "active";
@@ -70,46 +14,180 @@ export interface DailyCustomTrayButton {
tooltip: string;
visualState?: DailyCustomTrayButtonVisualState;
}
export const CalAiTranscribe = ({
type RecordingState = {
isRecording: boolean;
};
type TranscriptionState = {
isTranscribing: boolean;
};
type CalVideoCallbacksParams = {
daily: DailyCall | null;
recording: RecordingState | null;
transcription: TranscriptionState | null;
showRecordingButton: boolean;
showTranscriptionButton: boolean;
enableAutomaticTranscription: boolean;
enableAutomaticRecordingForOrganizer: boolean;
};
export const createCalVideoCallbacks = (params: CalVideoCallbacksParams) => {
const {
daily,
recording,
transcription,
showRecordingButton,
showTranscriptionButton,
enableAutomaticTranscription,
enableAutomaticRecordingForOrganizer,
} = params;
const startRecording = () => {
daily?.startRecording({
// 480p
videoBitrate: 2000,
});
};
const updateCustomTrayButtons = ({
recording: overrideRecording,
transcription: overrideTranscription,
}: {
recording?: DailyCustomTrayButton;
transcription?: DailyCustomTrayButton;
}) => {
const currentRecordingState = recording?.isRecording ? BUTTONS.STOP_RECORDING : BUTTONS.START_RECORDING;
const currentTranscriptionState = transcription?.isTranscribing
? BUTTONS.STOP_TRANSCRIPTION
: BUTTONS.START_TRANSCRIPTION;
daily?.updateCustomTrayButtons({
...(showRecordingButton
? {
recording: overrideRecording ?? currentRecordingState,
}
: {}),
...(showTranscriptionButton
? {
transcription: overrideTranscription ?? currentTranscriptionState,
}
: {}),
});
};
const onMeetingJoined = () => {
if (enableAutomaticTranscription && !transcription?.isTranscribing) {
daily?.startTranscription();
}
if (enableAutomaticRecordingForOrganizer && !recording?.isRecording) {
startRecording();
}
};
const onRecordingStarted = () => {
updateCustomTrayButtons({
recording: BUTTONS.STOP_RECORDING,
});
};
const onRecordingStopped = () => {
updateCustomTrayButtons({
recording: BUTTONS.START_RECORDING,
});
};
const onTranscriptionStarted = () => {
updateCustomTrayButtons({
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
};
const onTranscriptionStopped = () => {
updateCustomTrayButtons({
transcription: BUTTONS.START_TRANSCRIPTION,
});
};
const toggleRecording = async () => {
if (recording?.isRecording) {
updateCustomTrayButtons({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_STOP,
});
daily?.stopRecording();
} else {
updateCustomTrayButtons({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_START,
});
startRecording();
}
};
const toggleTranscription = async () => {
if (transcription?.isTranscribing) {
updateCustomTrayButtons({
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_STOP,
});
daily?.stopTranscription();
} else {
updateCustomTrayButtons({
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_START,
});
daily?.startTranscription();
}
};
const onCustomButtonClick = async (ev: { button_id: string }) => {
if (ev?.button_id === "recording") {
toggleRecording();
} else if (ev?.button_id === "transcription") {
toggleTranscription();
}
};
return {
onMeetingJoined,
onRecordingStarted,
onRecordingStopped,
onTranscriptionStarted,
onTranscriptionStopped,
onCustomButtonClick,
toggleRecording,
toggleTranscription,
updateCustomTrayButtons,
startRecording,
};
};
export const CalVideoPremiumFeatures = ({
showRecordingButton,
enableAutomaticTranscription,
enableAutomaticRecordingForOrganizer,
showTranscriptionButton,
}: {
showRecordingButton: boolean;
enableAutomaticTranscription: boolean;
enableAutomaticRecordingForOrganizer: boolean;
showTranscriptionButton: boolean;
}) => {
const daily = useDaily();
const { t } = useLocale();
const [transcript, setTranscript] = useState("");
const [transcriptHeight, setTranscriptHeight] = useState(0);
const transcriptRef = useRef<HTMLDivElement | null>(null);
const transcription = useTranscription();
const recording = useRecording();
const updateCustomTrayButtons = ({
const callbacks = createCalVideoCallbacks({
daily,
recording,
transcription,
}: {
recording: DailyCustomTrayButton;
transcription: DailyCustomTrayButton;
}) => {
daily?.updateCustomTrayButtons({
...(showRecordingButton
? {
recording,
}
: {}),
...(showTranscriptionButton
? {
transcription,
}
: {}),
});
};
showRecordingButton,
showTranscriptionButton,
enableAutomaticTranscription,
enableAutomaticRecordingForOrganizer,
});
useDailyEvent(
"app-message",
@@ -119,94 +197,12 @@ export const CalAiTranscribe = ({
}, [])
);
useDailyEvent("joined-meeting", (ev) => {
if (enableAutomaticTranscription) {
daily?.startTranscription();
updateCustomTrayButtons({
recording: BUTTONS.START_RECORDING,
transcription: transcription?.isTranscribing
? BUTTONS.STOP_TRANSCRIPTION
: BUTTONS.START_TRANSCRIPTION,
});
}
});
useDailyEvent("transcription-started", (ev) => {
updateCustomTrayButtons({
recording: recording?.isRecording ? BUTTONS.STOP_RECORDING : BUTTONS.START_RECORDING,
transcription: BUTTONS.STOP_TRANSCRIPTION,
});
});
useDailyEvent("recording-started", (ev) => {
updateCustomTrayButtons({
recording: BUTTONS.STOP_RECORDING,
transcription: transcription?.isTranscribing ? BUTTONS.STOP_TRANSCRIPTION : BUTTONS.START_TRANSCRIPTION,
});
});
useDailyEvent("transcription-stopped", (ev) => {
updateCustomTrayButtons({
recording: recording?.isRecording ? BUTTONS.STOP_RECORDING : BUTTONS.START_RECORDING,
transcription: BUTTONS.START_TRANSCRIPTION,
});
});
useDailyEvent("recording-stopped", (ev) => {
updateCustomTrayButtons({
recording: BUTTONS.START_RECORDING,
transcription: transcription?.isTranscribing ? BUTTONS.STOP_TRANSCRIPTION : BUTTONS.START_TRANSCRIPTION,
});
});
const toggleRecording = async () => {
if (recording?.isRecording) {
updateCustomTrayButtons({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_STOP,
transcription: transcription?.isTranscribing
? BUTTONS.STOP_TRANSCRIPTION
: BUTTONS.START_TRANSCRIPTION,
});
await daily?.stopRecording();
} else {
updateCustomTrayButtons({
recording: BUTTONS.WAIT_FOR_RECORDING_TO_START,
transcription: transcription?.isTranscribing
? BUTTONS.STOP_TRANSCRIPTION
: BUTTONS.START_TRANSCRIPTION,
});
await daily?.startRecording({
// 480p
videoBitrate: 2000,
});
}
};
const toggleTranscription = async () => {
if (transcription?.isTranscribing) {
updateCustomTrayButtons({
recording: recording?.isRecording ? BUTTONS.STOP_RECORDING : BUTTONS.START_RECORDING,
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_STOP,
});
daily?.stopTranscription();
} else {
updateCustomTrayButtons({
recording: recording?.isRecording ? BUTTONS.STOP_RECORDING : BUTTONS.START_RECORDING,
transcription: BUTTONS.WAIT_FOR_TRANSCRIPTION_TO_START,
});
daily?.startTranscription();
}
};
useDailyEvent("custom-button-click", async (ev) => {
if (ev?.button_id === "recording") {
toggleRecording();
} else if (ev?.button_id === "transcription") {
toggleTranscription();
}
});
useDailyEvent("joined-meeting", callbacks.onMeetingJoined);
useDailyEvent("transcription-started", callbacks.onTranscriptionStarted);
useDailyEvent("recording-started", callbacks.onRecordingStarted);
useDailyEvent("transcription-stopped", callbacks.onTranscriptionStopped);
useDailyEvent("recording-stopped", callbacks.onRecordingStopped);
useDailyEvent("custom-button-click", callbacks.onCustomButtonClick);
useLayoutEffect(() => {
const observer = new ResizeObserver((entries) => {
@@ -21,7 +21,7 @@ import { Icon } from "@calcom/ui/components/icon";
import type { getServerSideProps } from "@lib/video/[uid]/getServerSideProps";
import { CalAiTranscribe } from "~/videos/ai/ai-transcribe";
import { CalVideoPremiumFeatures } from "../cal-video-premium-features";
export type PageProps = inferSSRProps<typeof getServerSideProps>;
@@ -37,6 +37,7 @@ export default function JoinCall(props: PageProps) {
overrideName,
showRecordingButton,
enableAutomaticTranscription,
enableAutomaticRecordingForOrganizer,
showTranscriptionButton,
rediectAttendeeToOnExit,
} = props;
@@ -116,8 +117,9 @@ export default function JoinCall(props: PageProps) {
<div
className="mx-auto hidden sm:block"
style={{ zIndex: 2, left: "30%", position: "absolute", bottom: 100, width: "auto" }}>
<CalAiTranscribe
<CalVideoPremiumFeatures
showRecordingButton={showRecordingButton}
enableAutomaticRecordingForOrganizer={enableAutomaticRecordingForOrganizer}
enableAutomaticTranscription={enableAutomaticTranscription}
showTranscriptionButton={showTranscriptionButton}
/>