Add spatial audio capabilities
This commit is contained in:
@@ -24,12 +24,13 @@ import { ReactComponent as DeveloperIcon } from "../icons/Developer.svg";
|
||||
import { SelectInput } from "../input/SelectInput";
|
||||
import { Item } from "@react-stately/collections";
|
||||
import { useMediaHandler } from "./useMediaHandler";
|
||||
import { useSpatialAudio, useShowInspector } from "./useSetting";
|
||||
import { FieldRow, InputField } from "../input/Input";
|
||||
import { Button } from "../button";
|
||||
import { useDownloadDebugLog } from "./submit-rageshake";
|
||||
import { Body } from "../typography/Typography";
|
||||
|
||||
export function SettingsModal({ setShowInspector, showInspector, ...rest }) {
|
||||
export const SettingsModal = (props) => {
|
||||
const {
|
||||
audioInput,
|
||||
audioInputs,
|
||||
@@ -41,6 +42,8 @@ export function SettingsModal({ setShowInspector, showInspector, ...rest }) {
|
||||
audioOutputs,
|
||||
setAudioOutput,
|
||||
} = useMediaHandler();
|
||||
const [spatialAudio, setSpatialAudio] = useSpatialAudio();
|
||||
const [showInspector, setShowInspector] = useShowInspector();
|
||||
|
||||
const downloadDebugLog = useDownloadDebugLog();
|
||||
|
||||
@@ -50,7 +53,7 @@ export function SettingsModal({ setShowInspector, showInspector, ...rest }) {
|
||||
isDismissable
|
||||
mobileFullScreen
|
||||
className={styles.settingsModal}
|
||||
{...rest}
|
||||
{...props}
|
||||
>
|
||||
<TabContainer className={styles.tabContainer}>
|
||||
<TabItem
|
||||
@@ -81,6 +84,15 @@ export function SettingsModal({ setShowInspector, showInspector, ...rest }) {
|
||||
))}
|
||||
</SelectInput>
|
||||
)}
|
||||
<FieldRow>
|
||||
<InputField
|
||||
id="spatialAudio"
|
||||
label="Spatial audio (experimental)"
|
||||
type="checkbox"
|
||||
checked={spatialAudio}
|
||||
onChange={(e) => setSpatialAudio(e.target.checked)}
|
||||
/>
|
||||
</FieldRow>
|
||||
</TabItem>
|
||||
<TabItem
|
||||
title={
|
||||
@@ -130,4 +142,4 @@ export function SettingsModal({ setShowInspector, showInspector, ...rest }) {
|
||||
</TabContainer>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
56
src/settings/useSetting.ts
Normal file
56
src/settings/useSetting.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2022 New Vector Ltd
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
import { useMemo, useState, useEffect, useCallback } from "react";
|
||||
|
||||
// Bus to notify other useSetting consumers when a setting is changed
|
||||
const settingsBus = new EventEmitter();
|
||||
|
||||
// Like useState, but reads from and persists the value to localStorage
|
||||
const useSetting = <T>(
|
||||
name: string,
|
||||
defaultValue: T
|
||||
): [T, (value: T) => void] => {
|
||||
const key = useMemo(() => `matrix-setting-${name}`, [name]);
|
||||
|
||||
const [value, setValue] = useState<T>(() => {
|
||||
const item = localStorage.getItem(key);
|
||||
return item == null ? defaultValue : JSON.parse(item);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
settingsBus.on(name, setValue);
|
||||
return () => {
|
||||
settingsBus.off(name, setValue);
|
||||
};
|
||||
}, [name, setValue]);
|
||||
|
||||
return [
|
||||
value,
|
||||
useCallback(
|
||||
(newValue: T) => {
|
||||
setValue(newValue);
|
||||
localStorage.setItem(key, JSON.stringify(newValue));
|
||||
settingsBus.emit(name, newValue);
|
||||
},
|
||||
[name, key, setValue]
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
export const useSpatialAudio = () => useSetting("spatial-audio", false);
|
||||
export const useShowInspector = () => useSetting("show-inspector", false);
|
||||
Reference in New Issue
Block a user