Skip to content

Commit

Permalink
feat: added push to talk
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Couture committed Mar 20, 2024
1 parent 0ffb8e6 commit a27bca6
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/ui/ChatScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import './ChatScreen.css';

import { Button, Container, Stack, TextField } from '@mui/material';
import { useCallback, useState } from 'react';

import { Button, Container, Stack, TextField } from '@mui/material';

import {
STATE_ACTIVE,
STATE_OPEN,
useInworld,
} from '../contexts/InworldProvider';
import { MicrophoneModes, useSystem } from '../contexts/SystemProvider';

function ChatScreen() {
const { close, state, isRecording, sendText, startRecording, stopRecording } =
useInworld();
const { microphoneMode } = useSystem();

const [text, onChangeText] = useState('');

Expand Down Expand Up @@ -64,10 +67,24 @@ function ChatScreen() {
<Button
className="chatButton"
variant="outlined"
onClick={() => onPressRec()}
onClick={() => {
if (microphoneMode === MicrophoneModes.NORMAL) onPressRec();
}}
onMouseDown={() => {
if (microphoneMode === MicrophoneModes.PTT) onPressRec();
}}
onMouseUp={() => {
if (microphoneMode === MicrophoneModes.PTT) onPressRec();
}}
style={{ width: '125px' }}
>
{isRecording ? 'Stop Rec' : 'Start Rec'}
{microphoneMode === MicrophoneModes.NORMAL &&
isRecording &&
'Stop Rec'}
{microphoneMode === MicrophoneModes.NORMAL &&
!isRecording &&
'Start Rec'}
{microphoneMode === MicrophoneModes.PTT && 'Push to Talk'}
</Button>
<Button
className="chatButton"
Expand Down
68 changes: 65 additions & 3 deletions src/ui/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ import './MainMenu.css';

import { useCallback, useEffect, useState } from 'react';

import { Button, Paper, Stack } from '@mui/material';
import {
Button,
FormControl,
FormControlLabel,
FormLabel,
Paper,
Radio,
RadioGroup,
Stack,
} from '@mui/material';
import Container from '@mui/material/Container';

import {
STATE_ACTIVE,
STATE_OPEN,
useInworld,
} from '../contexts/InworldProvider';
import {
ROOM_ANIMATIONS,
ROOM_AVATARS,
Expand All @@ -13,16 +27,24 @@ import {
ROOM_LOBBY,
useRooms,
} from '../contexts/RoomsProvider';
import { STATE_RUNNING, useSystem } from '../contexts/SystemProvider';
import {
MicrophoneModes,
STATE_RUNNING,
useSystem,
} from '../contexts/SystemProvider';
import { log } from '../utils/log';

function MainMenu() {
const STATE_MAIN = 'state_main';
const STATE_MICROPHONE = 'state_microphone';

const MICROPHONE_NORMAL = 'normal';
const MICROPHONE_PTT = 'ptt';

const [state, setState] = useState<string>(STATE_MAIN);

const { stateSystem, setStateSystem } = useSystem();
const { state: systemState } = useInworld();
const { stateSystem, setMicrophoneMode, setStateSystem } = useSystem();
const { room, setRoom } = useRooms();

useEffect(() => {
Expand All @@ -44,6 +66,17 @@ function MainMenu() {
[room, setRoom],
);

const onChangeMic = useCallback(
(event: any) => {
console.log('onChangeMic', event.target.value);
if (!setMicrophoneMode) return;
const mode = event.target.value;
if (mode === MICROPHONE_NORMAL) setMicrophoneMode(MicrophoneModes.NORMAL);
if (mode === MICROPHONE_PTT) setMicrophoneMode(MicrophoneModes.PTT);
},
[setMicrophoneMode],
);

const onClickState = useCallback((state: string) => {
setState(state);
}, []);
Expand Down Expand Up @@ -77,6 +110,35 @@ function MainMenu() {
<Paper className="paperMicrophoneMenu">
<Stack>
<p>Microphone Modes</p>
<FormControl>
<RadioGroup
aria-labelledby="demo-radio-buttons-group-label"
defaultValue="normal"
name="radio-buttons-group"
onChange={onChangeMic}
>
<FormControlLabel
value={MICROPHONE_NORMAL}
control={<Radio />}
label="Normal"
disabled={
systemState === STATE_ACTIVE || systemState === STATE_OPEN
? true
: false
}
/>
<FormControlLabel
value={MICROPHONE_PTT}
control={<Radio />}
label="Push to Talk"
disabled={
systemState === STATE_ACTIVE || systemState === STATE_OPEN
? true
: false
}
/>
</RadioGroup>
</FormControl>
<Button onClick={() => onClickState(STATE_MAIN)}>
Main Menu
</Button>
Expand Down

0 comments on commit a27bca6

Please sign in to comment.