Skip to content

Commit

Permalink
fixup! ✨(front) revamp join screen
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanVss committed Jan 21, 2025
1 parent 39cdd9b commit b114fb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/frontend/src/features/rooms/components/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export const Join = ({
[tracks]
)

const audioTrack = React.useMemo(
() =>
tracks?.filter(
(track) => track.kind === Track.Kind.Audio
)[0] as LocalVideoTrack,
[tracks]
)

const facingMode = React.useMemo(() => {
if (videoTrack) {
const { facingMode } = facingModeFromLocalTrack(videoTrack)
Expand Down Expand Up @@ -283,8 +291,10 @@ export const Join = ({
>
<SelectToggleDevice
source={Track.Source.Microphone}
onChange={(enabled) => setAudioEnabled(enabled)}
initialState={audioEnabled}
track={audioTrack}
initialDeviceId={audioDeviceId}
onChange={(enabled) => setAudioEnabled(enabled)}
onDeviceError={(error) => console.error(error)}
onActiveDeviceChange={(deviceId) =>
setAudioDeviceId(deviceId ?? '')
Expand All @@ -294,6 +304,8 @@ export const Join = ({
<SelectToggleDevice
source={Track.Source.Camera}
initialState={videoEnabled}
track={videoTrack}
initialDeviceId={videoDeviceId}
onChange={(enabled) => {
setVideoEnabled(enabled)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ import {
RiVideoOffLine,
RiVideoOnLine,
} from '@remixicon/react'
import { Track } from 'livekit-client'
import {
LocalAudioTrack,
LocalTrack,
LocalVideoTrack,
Track,
} from 'livekit-client'

import { Shortcut } from '@/features/shortcuts/types'

import { ToggleDevice } from '@/features/rooms/livekit/components/controls/ToggleDevice.tsx'
import { css } from '@/styled-system/css'
import { ButtonRecipeProps } from '@/primitives/buttonRecipe'
import { useEffect } from 'react'

export type ToggleSource = Exclude<
Track.Source,
Expand Down Expand Up @@ -66,12 +72,16 @@ const selectToggleDeviceConfig: SelectToggleDeviceConfigMap = {

type SelectToggleDeviceProps<T extends ToggleSource> =
UseTrackToggleProps<T> & {
track?: LocalAudioTrack | LocalVideoTrack | undefined
initialDeviceId?: string
onActiveDeviceChange: (deviceId: string) => void
source: SelectToggleSource
variant?: NonNullable<ButtonRecipeProps>['variant']
}

export const SelectToggleDevice = <T extends ToggleSource>({
track,
initialDeviceId,
onActiveDeviceChange,
variant = 'primaryDark',
...props
Expand All @@ -84,7 +94,19 @@ export const SelectToggleDevice = <T extends ToggleSource>({
const trackProps = useTrackToggle(props)

const { devices, activeDeviceId, setActiveMediaDevice } =
useMediaDeviceSelect({ kind: config.kind })
useMediaDeviceSelect({ kind: config.kind, track })

/**
* When providing only track outside of a room context, activeDeviceId is undefined.
* So we need to initialise it with the initialDeviceId.
* nb: I don't understand why useMediaDeviceSelect cannot infer it from track device id.
*/
useEffect(() => {
if (initialDeviceId !== undefined) {
setActiveMediaDevice(initialDeviceId)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setActiveMediaDevice])

const selectLabel = t('choose', { keyPrefix: `join.${config.kind}` })

Expand Down

0 comments on commit b114fb2

Please sign in to comment.