2022-05-04 17:09:48 +01:00
/ *
2023-05-05 11:44:35 +02:00
Copyright 2022 - 2023 New Vector Ltd
2022-05-04 17:09:48 +01:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2023-05-05 11:44:35 +02:00
import React , { useCallback , useState } from "react" ;
2022-06-06 22:42:48 +02:00
import { Item } from "@react-stately/collections" ;
2023-03-13 18:40:16 -04:00
import { Trans , useTranslation } from "react-i18next" ;
2023-05-05 11:44:35 +02:00
import { MatrixClient } from "matrix-js-sdk" ;
2022-06-06 22:42:48 +02:00
2022-01-05 16:54:13 -08:00
import { Modal } from "../Modal" ;
2021-12-06 17:34:10 -08:00
import styles from "./SettingsModal.module.css" ;
2022-01-21 15:43:03 -08:00
import { TabContainer , TabItem } from "../tabs/Tabs" ;
2022-01-05 16:54:13 -08:00
import { ReactComponent as AudioIcon } from "../icons/Audio.svg" ;
import { ReactComponent as VideoIcon } from "../icons/Video.svg" ;
import { ReactComponent as DeveloperIcon } from "../icons/Developer.svg" ;
2022-11-05 11:13:56 +01:00
import { ReactComponent as OverflowIcon } from "../icons/Overflow.svg" ;
2023-05-05 11:44:35 +02:00
import { ReactComponent as UserIcon } from "../icons/User.svg" ;
import { ReactComponent as FeedbackIcon } from "../icons/Feedback.svg" ;
2022-01-05 17:27:01 -08:00
import { SelectInput } from "../input/SelectInput" ;
2022-06-08 17:22:46 +02:00
import { useMediaHandler } from "./useMediaHandler" ;
2022-11-04 13:07:14 +01:00
import {
useSpatialAudio ,
useShowInspector ,
useOptInAnalytics ,
2023-02-13 20:36:42 -05:00
useNewGrid ,
2023-03-01 13:47:36 +01:00
useDeveloperSettingsTab ,
2022-11-04 13:07:14 +01:00
} from "./useSetting" ;
2022-02-04 16:55:57 -08:00
import { FieldRow , InputField } from "../input/Input" ;
2022-02-01 15:11:06 -08:00
import { Button } from "../button" ;
2022-04-07 14:22:36 -07:00
import { useDownloadDebugLog } from "./submit-rageshake" ;
2023-03-13 18:40:16 -04:00
import { Body , Caption } from "../typography/Typography" ;
import { AnalyticsNotice } from "../analytics/AnalyticsNotice" ;
2023-05-05 11:44:35 +02:00
import { ProfileSettingsTab } from "./ProfileSettingsTab" ;
import { FeedbackSettingsTab } from "./FeedbackSettingsTab" ;
2021-12-06 17:34:10 -08:00
2022-06-06 22:42:48 +02:00
interface Props {
2022-08-02 00:46:16 +02:00
isOpen : boolean ;
2023-05-05 11:44:35 +02:00
client : MatrixClient ;
roomId? : string ;
defaultTab? : string ;
2022-08-02 00:46:16 +02:00
onClose : ( ) = > void ;
2022-06-06 22:42:48 +02:00
}
export const SettingsModal = ( props : Props ) = > {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation ( ) ;
2021-12-06 17:34:10 -08:00
const {
audioInput ,
audioInputs ,
setAudioInput ,
videoInput ,
videoInputs ,
setVideoInput ,
2022-02-22 18:32:51 -08:00
audioOutput ,
audioOutputs ,
setAudioOutput ,
Make Element Call work in Firefox's resist fingerprinting mode
This one is gonna take some explaining:
When in resist fingerprinting mode, Firefox exhibits some funny behavior: when we ask for the the list of media devices, it gives us fake device IDs. But when the js-sdk requests a stream for any of those devices, Firefox associates the stream with the real device ID.
Now, in order to get the names of devices included in their metadata when you query the device list, you need to be holding a stream. For this reason, useMediaHandler was set up to reload the device list whenever matrix-js-sdk got a new local stream. But because of the inconsistency in device IDs, it would enter an infinite cycle telling matrix-js-sdk to request a stream for the fake device ID, but with matrix-js-sdk always responding with the real device ID.
I already wasn't happy with useMediaHandler's use of @ts-ignore comments to inspect private js-sdk fields, and in the meantime we've come up with a simpler function for requesting device names, so I decided to refactor useMediaHandler to use it instead. Importantly, it doesn't break in resist fingerprinting mode.
This created a new UX issue though: now, when on the lobby screen, useMediaHandler would request microphone access so it could get device names, followed immediately by a *second* pop-up for the lobby screen to request camera access. That's 1 pop-up too many, so I changed useMediaHandler to only request device names when a component is mounted that actually wants to show them. Currently, the settings modal is the only such component, and users normally only open it *after* granting full audio/video access, so this solution works out quite nicely.
2023-05-15 22:03:26 -04:00
useDeviceNames ,
2022-02-22 18:32:51 -08:00
} = useMediaHandler ( ) ;
Make Element Call work in Firefox's resist fingerprinting mode
This one is gonna take some explaining:
When in resist fingerprinting mode, Firefox exhibits some funny behavior: when we ask for the the list of media devices, it gives us fake device IDs. But when the js-sdk requests a stream for any of those devices, Firefox associates the stream with the real device ID.
Now, in order to get the names of devices included in their metadata when you query the device list, you need to be holding a stream. For this reason, useMediaHandler was set up to reload the device list whenever matrix-js-sdk got a new local stream. But because of the inconsistency in device IDs, it would enter an infinite cycle telling matrix-js-sdk to request a stream for the fake device ID, but with matrix-js-sdk always responding with the real device ID.
I already wasn't happy with useMediaHandler's use of @ts-ignore comments to inspect private js-sdk fields, and in the meantime we've come up with a simpler function for requesting device names, so I decided to refactor useMediaHandler to use it instead. Importantly, it doesn't break in resist fingerprinting mode.
This created a new UX issue though: now, when on the lobby screen, useMediaHandler would request microphone access so it could get device names, followed immediately by a *second* pop-up for the lobby screen to request camera access. That's 1 pop-up too many, so I changed useMediaHandler to only request device names when a component is mounted that actually wants to show them. Currently, the settings modal is the only such component, and users normally only open it *after* granting full audio/video access, so this solution works out quite nicely.
2023-05-15 22:03:26 -04:00
useDeviceNames ( ) ;
2022-06-06 22:42:48 +02:00
2022-05-31 10:43:05 -04:00
const [ spatialAudio , setSpatialAudio ] = useSpatialAudio ( ) ;
const [ showInspector , setShowInspector ] = useShowInspector ( ) ;
2022-11-04 13:07:14 +01:00
const [ optInAnalytics , setOptInAnalytics ] = useOptInAnalytics ( ) ;
2023-03-01 13:47:36 +01:00
const [ developerSettingsTab , setDeveloperSettingsTab ] =
useDeveloperSettingsTab ( ) ;
2023-02-13 20:36:42 -05:00
const [ newGrid , setNewGrid ] = useNewGrid ( ) ;
2021-12-06 17:34:10 -08:00
2022-02-04 16:55:57 -08:00
const downloadDebugLog = useDownloadDebugLog ( ) ;
2022-02-01 15:11:06 -08:00
2023-05-05 11:44:35 +02:00
const [ selectedTab , setSelectedTab ] = useState < string | undefined > ( ) ;
const onSelectedTabChanged = useCallback (
( tab ) = > {
setSelectedTab ( tab ) ;
} ,
[ setSelectedTab ]
) ;
2023-03-13 18:40:16 -04:00
const optInDescription = (
< Caption >
< Trans >
< AnalyticsNotice / >
< br / >
You may withdraw consent by unchecking this box . If you are currently in
a call , this setting will take effect at the end of the call .
< / Trans >
< / Caption >
) ;
2021-12-06 17:34:10 -08:00
return (
< Modal
2022-10-10 09:19:10 -04:00
title = { t ( "Settings" ) }
2021-12-06 17:34:10 -08:00
isDismissable
2021-12-10 10:54:18 -08:00
mobileFullScreen
2021-12-06 17:34:10 -08:00
className = { styles . settingsModal }
2022-05-31 10:43:05 -04:00
{ . . . props }
2021-12-06 17:34:10 -08:00
>
2023-05-05 11:44:35 +02:00
< TabContainer
onSelectionChange = { onSelectedTabChanged }
selectedKey = { selectedTab ? ? props . defaultTab ? ? "audio" }
className = { styles . tabContainer }
>
2021-12-06 17:34:10 -08:00
< TabItem
2023-05-05 11:44:35 +02:00
key = "audio"
2021-12-06 17:34:10 -08:00
title = {
< >
< AudioIcon width = { 16 } height = { 16 } / >
2023-03-01 13:47:36 +01:00
< span className = { styles . tabLabel } > { t ( "Audio" ) } < / span >
2021-12-06 17:34:10 -08:00
< / >
}
>
< SelectInput
2022-10-10 09:19:10 -04:00
label = { t ( "Microphone" ) }
2021-12-06 17:34:10 -08:00
selectedKey = { audioInput }
onSelectionChange = { setAudioInput }
>
2022-07-07 12:10:08 +02:00
{ audioInputs . map ( ( { deviceId , label } , index ) = > (
2022-07-07 10:31:44 +02:00
< Item key = { deviceId } >
{ ! ! label && label . trim ( ) . length > 0
? label
2022-10-10 09:19:10 -04:00
: t ( "Microphone {{n}}" , { n : index + 1 } ) }
2022-07-07 10:31:44 +02:00
< / Item >
2021-12-06 17:34:10 -08:00
) ) }
< / SelectInput >
2022-02-22 18:32:51 -08:00
{ audioOutputs . length > 0 && (
< SelectInput
2022-10-10 09:19:10 -04:00
label = { t ( "Speaker" ) }
2022-02-22 18:32:51 -08:00
selectedKey = { audioOutput }
onSelectionChange = { setAudioOutput }
>
2022-07-07 12:10:08 +02:00
{ audioOutputs . map ( ( { deviceId , label } , index ) = > (
2022-07-07 10:31:44 +02:00
< Item key = { deviceId } >
{ ! ! label && label . trim ( ) . length > 0
? label
2022-10-10 09:19:10 -04:00
: t ( "Speaker {{n}}" , { n : index + 1 } ) }
2022-07-07 10:31:44 +02:00
< / Item >
2022-02-22 18:32:51 -08:00
) ) }
< / SelectInput >
) }
2022-05-31 10:43:05 -04:00
< FieldRow >
< InputField
id = "spatialAudio"
2022-10-10 09:19:10 -04:00
label = { t ( "Spatial audio" ) }
2022-05-31 10:43:05 -04:00
type = "checkbox"
checked = { spatialAudio }
2023-03-23 13:07:34 -04:00
disabled = { setSpatialAudio === null }
2022-12-16 17:12:17 +00:00
description = {
2023-03-23 13:07:34 -04:00
setSpatialAudio === null
? t ( "This feature is only supported on Firefox." )
: t (
2022-12-16 17:12:17 +00:00
"This will make a speaker's audio seem as if it is coming from where their tile is positioned on screen. (Experimental feature: this may impact the stability of audio.)"
)
}
2022-06-11 14:28:54 +02:00
onChange = { ( event : React.ChangeEvent < HTMLInputElement > ) = >
2023-03-23 13:07:34 -04:00
setSpatialAudio ! ( event . target . checked )
2022-06-11 14:28:54 +02:00
}
2022-05-31 10:43:05 -04:00
/ >
< / FieldRow >
2021-12-06 17:34:10 -08:00
< / TabItem >
< TabItem
2023-05-05 11:44:35 +02:00
key = "video"
2021-12-06 17:34:10 -08:00
title = {
< >
< VideoIcon width = { 16 } height = { 16 } / >
2022-10-10 09:19:10 -04:00
< span > { t ( "Video" ) } < / span >
2021-12-06 17:34:10 -08:00
< / >
}
>
< SelectInput
2022-10-10 09:19:10 -04:00
label = { t ( "Camera" ) }
2021-12-06 17:34:10 -08:00
selectedKey = { videoInput }
onSelectionChange = { setVideoInput }
>
2022-07-07 12:10:08 +02:00
{ videoInputs . map ( ( { deviceId , label } , index ) = > (
2022-07-07 10:31:44 +02:00
< Item key = { deviceId } >
2022-07-07 12:10:08 +02:00
{ ! ! label && label . trim ( ) . length > 0
? label
2022-10-10 09:19:10 -04:00
: t ( "Camera {{n}}" , { n : index + 1 } ) }
2022-07-07 10:31:44 +02:00
< / Item >
2021-12-06 17:34:10 -08:00
) ) }
< / SelectInput >
< / TabItem >
< TabItem
2023-05-05 11:44:35 +02:00
key = "profile"
title = {
< >
< UserIcon width = { 16 } height = { 16 } / >
< span > { t ( "Profile" ) } < / span >
< / >
}
>
< ProfileSettingsTab client = { props . client } / >
< / TabItem >
< TabItem
key = "feedback"
title = {
< >
< FeedbackIcon width = { 16 } height = { 16 } / >
2023-05-05 19:17:59 +02:00
< span > { t ( "Feedback" ) } < / span >
2023-05-05 11:44:35 +02:00
< / >
}
>
< FeedbackSettingsTab roomId = { props . roomId } / >
< / TabItem >
< TabItem
key = "more"
2021-12-06 17:34:10 -08:00
title = {
2022-11-05 11:13:56 +01:00
< >
< OverflowIcon width = { 16 } height = { 16 } / >
2023-03-01 13:47:36 +01:00
< span > { t ( "More" ) } < / span >
2022-11-05 11:13:56 +01:00
< / >
}
>
2023-05-05 11:44:35 +02:00
< h4 > Developer < / h4 >
< p >
Version : { ( import . meta . env . VITE_APP_VERSION as string ) || "dev" }
< / p >
2023-02-13 20:36:42 -05:00
< FieldRow >
< InputField
2023-03-01 13:47:36 +01:00
id = "developerSettingsTab"
2023-02-13 20:36:42 -05:00
type = "checkbox"
2023-03-01 13:47:36 +01:00
checked = { developerSettingsTab }
label = { t ( "Developer Settings" ) }
description = { t (
"Expose developer settings in the settings window."
) }
onChange = { ( event : React.ChangeEvent < HTMLInputElement > ) = >
setDeveloperSettingsTab ( event . target . checked )
2023-02-13 20:36:42 -05:00
}
/ >
< / FieldRow >
2023-05-05 11:44:35 +02:00
< h4 > Analytics < / h4 >
< FieldRow >
< InputField
id = "optInAnalytics"
type = "checkbox"
checked = { optInAnalytics }
description = { optInDescription }
onChange = { ( event : React.ChangeEvent < HTMLInputElement > ) = >
setOptInAnalytics ( event . target . checked )
}
/ >
< / FieldRow >
2021-12-06 17:34:10 -08:00
< / TabItem >
2023-03-01 13:47:36 +01:00
{ developerSettingsTab && (
< TabItem
2023-05-05 11:44:35 +02:00
key = "developer"
2023-03-01 13:47:36 +01:00
title = {
< >
< DeveloperIcon width = { 16 } height = { 16 } / >
< span > { t ( "Developer" ) } < / span >
< / >
}
>
< FieldRow >
< Body className = { styles . fieldRowText } >
{ t ( "Version: {{version}}" , {
version : import.meta.env.VITE_APP_VERSION || "dev" ,
} ) }
< / Body >
< / FieldRow >
< FieldRow >
< InputField
id = "showInspector"
name = "inspector"
label = { t ( "Show call inspector" ) }
type = "checkbox"
checked = { showInspector }
onChange = { ( e : React.ChangeEvent < HTMLInputElement > ) = >
setShowInspector ( e . target . checked )
}
/ >
< / FieldRow >
< FieldRow >
< InputField
id = "newGrid"
label = { t ( "Use the upcoming grid system" ) }
type = "checkbox"
checked = { newGrid }
onChange = { ( e : React.ChangeEvent < HTMLInputElement > ) = >
setNewGrid ( e . target . checked )
}
/ >
< / FieldRow >
< FieldRow >
< Button onPress = { downloadDebugLog } >
{ t ( "Download debug logs" ) }
< / Button >
< / FieldRow >
< / TabItem >
) }
2021-12-06 17:34:10 -08:00
< / TabContainer >
< / Modal >
) ;
2022-05-31 10:43:05 -04:00
} ;