From fefbfbf4e0fba230baef3da41dad0d7f011273a4 Mon Sep 17 00:00:00 2001 From: bcaller Date: Wed, 10 Jul 2024 20:56:16 +0900 Subject: [PATCH] Use Jitsi API to start/stop transcription --- src/components/InCall.tsx | 2 +- src/jitsi/event-handlers.ts | 27 ++++++++++++++++++--------- src/transcripts.ts | 2 ++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/components/InCall.tsx b/src/components/InCall.tsx index cdfc0f572..350fd2bc2 100644 --- a/src/components/InCall.tsx +++ b/src/components/InCall.tsx @@ -78,7 +78,7 @@ export const InCall = ({ videoConferenceJoinedHandler(transcriptManager.current), transcriptionChunkReceivedHandler(transcriptManager.current), transcribingStatusChangedHandler(transcriptManager.current), - buttonHandler, + buttonHandler(transcriptManager.current), ]; transcriptManager.current.roomName = roomName; diff --git a/src/jitsi/event-handlers.ts b/src/jitsi/event-handlers.ts index 15610c09a..5ee358485 100644 --- a/src/jitsi/event-handlers.ts +++ b/src/jitsi/event-handlers.ts @@ -558,15 +558,24 @@ export const getParticipants = ( }); }; -export const buttonHandler = { +export const buttonHandler = (transcriptManager: TranscriptManager) => ({ name: "toolbarButtonClicked", - fn: - (_jitsi: IJitsiMeetApi, _context: JitsiContext) => async (params: any) => { - switch (params.key) { - case "leo": { - alert("LEO! TODO: en/disable transcription now"); - break; + fn: (jitsi: IJitsiMeetApi, _context: JitsiContext) => async (params: any) => { + switch (params.key) { + case "leo": { + if (!transcriptManager.transcriptionEnabledAccordingToJitsiEvents) { + jitsi.executeCommand("startRecording", { + mode: "file", + transcription: true, + }); + } else { + jitsi.executeCommand("stopRecording", { + mode: "file", + transcription: true, + }); } + break; } - }, -}; + } + }, +}); diff --git a/src/transcripts.ts b/src/transcripts.ts index 7d877152c..a79f48009 100644 --- a/src/transcripts.ts +++ b/src/transcripts.ts @@ -114,6 +114,7 @@ export class TranscriptManager { data: { [key: string]: JitsiTranscriptionChunk } = {}; prompt: string = ""; transcriptionUsed: boolean = false; + transcriptionEnabledAccordingToJitsiEvents: boolean = false; constructor(public onTranscriptChange: (transcript: string) => void) {} @@ -158,6 +159,7 @@ export class TranscriptManager { } async handleTranscriptionEnabledEvent(jitsi: IJitsiMeetApi, status: boolean) { + this.transcriptionEnabledAccordingToJitsiEvents = status; if (!this.jwt) { throw new Error( "Could not process transcription enabled event due to missing JWT",