mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-05 08:27:42 +00:00
🚧 (frontend) Add start/stop audio recording menu item
Functional but not mergeable—remote participants need to be informed when recording starts, including the egress ID to prevent collisions. Quick and dirty implementation.
This commit is contained in:
@@ -35,5 +35,22 @@ export const useRecordRoom = () => {
|
||||
}
|
||||
)
|
||||
}
|
||||
return { recordRoom }
|
||||
|
||||
const stopRecordingRoom = (egressId: string) => {
|
||||
if (!data || !data?.livekit) {
|
||||
throw new Error('Room data is not available')
|
||||
}
|
||||
return fetchServerApi(
|
||||
buildServerApiUrl(data.livekit.url, '/twirp/livekit.Egress/StopEgress'),
|
||||
data.livekit.token,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
egressId,
|
||||
}),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return { recordRoom, stopRecordingRoom }
|
||||
}
|
||||
|
||||
+2
@@ -8,6 +8,7 @@ import { MenuItem, Menu as RACMenu } from 'react-aria-components'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Dispatch, SetStateAction } from 'react'
|
||||
import { DialogState } from '@/features/rooms/livekit/components/controls/Options/OptionsButton'
|
||||
import { RecordingMenuItem } from './RecordingMenuItem.tsx'
|
||||
|
||||
// @todo try refactoring it to use MenuList component
|
||||
export const OptionsMenuItems = ({
|
||||
@@ -47,6 +48,7 @@ export const OptionsMenuItems = ({
|
||||
<RiSettings3Line size={18} />
|
||||
{t('options.items.settings')}
|
||||
</MenuItem>
|
||||
<RecordingMenuItem />
|
||||
</RACMenu>
|
||||
)
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import { MenuItem } from 'react-aria-components'
|
||||
import { menuItemRecipe } from '@/primitives/menuItemRecipe.ts'
|
||||
import { RiPauseCircleLine, RiRecordCircleLine } from '@remixicon/react'
|
||||
import { useRecordRoom } from '@/features/rooms/livekit/api/recordRoom.ts'
|
||||
import { useState } from 'react'
|
||||
import { egressStore } from '@/stores/egress.tsx'
|
||||
import { useSnapshot } from 'valtio'
|
||||
|
||||
export const RecordingMenuItem = () => {
|
||||
const { recordRoom, stopRecordingRoom } = useRecordRoom()
|
||||
|
||||
const egressSnap = useSnapshot(egressStore)
|
||||
const egressId = egressSnap.egressId
|
||||
|
||||
const [isPending, setIsPending] = useState(false)
|
||||
|
||||
const handleAction = async () => {
|
||||
if (egressId) {
|
||||
setIsPending(true)
|
||||
const response = await stopRecordingRoom(egressId)
|
||||
console.log(response)
|
||||
egressStore.egressId = undefined
|
||||
setIsPending(false)
|
||||
} else {
|
||||
setIsPending(true)
|
||||
const response = await recordRoom()
|
||||
egressStore.egressId = response['egress_id'] as string
|
||||
setIsPending(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
isDisabled={isPending}
|
||||
className={menuItemRecipe({ icon: true })}
|
||||
onAction={handleAction}
|
||||
>
|
||||
{egressId ? (
|
||||
<>
|
||||
<RiPauseCircleLine size={18} />
|
||||
Stop recording room
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<RiRecordCircleLine size={18} />
|
||||
Record room
|
||||
</>
|
||||
)}
|
||||
</MenuItem>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { proxy } from 'valtio'
|
||||
|
||||
type State = {
|
||||
egressId: string | undefined
|
||||
}
|
||||
|
||||
export const egressStore = proxy<State>({
|
||||
egressId: undefined,
|
||||
})
|
||||
Reference in New Issue
Block a user