From cf3292b36ceb0dfe9eaff3bf3ecce12025b2a71c Mon Sep 17 00:00:00 2001 From: Lynchee <125778696+lynchee-owo@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:04:25 -0700 Subject: [PATCH] added push to talk (#199) --- client/web/src/App.css | 11 --- client/web/src/App.jsx | 12 ++- client/web/src/components/CallView/index.jsx | 4 +- client/web/src/components/CallView/style.css | 11 +++ .../web/src/components/Common/IconButton.js | 5 +- client/web/src/components/Common/styles.css | 5 ++ client/web/src/components/TextView/index.js | 74 ++++++++++++++----- client/web/src/components/TextView/style.css | 59 ++++++++++----- 8 files changed, 125 insertions(+), 56 deletions(-) diff --git a/client/web/src/App.css b/client/web/src/App.css index 86d2be1e9..4a186a011 100644 --- a/client/web/src/App.css +++ b/client/web/src/App.css @@ -12,17 +12,6 @@ align-items: center; } -.main-screen { - display: flex; - flex-direction: column; - align-items: center; - justify-content: space-between; - flex-grow: 1; - width: 100%; - height: 40vh; - padding: 20px; -} - .header { color: #cccccc; font-family: "Prompt", Helvetica; diff --git a/client/web/src/App.jsx b/client/web/src/App.jsx index 1cf982cff..688669032 100644 --- a/client/web/src/App.jsx +++ b/client/web/src/App.jsx @@ -89,9 +89,10 @@ const App = () => { if (message === '[end]\n') { setTextAreaValue(prevState => prevState + "\n\n"); - } else if (message.startsWith('[+]')) { + } else if (message.startsWith('[+]You said: ')) { // [+] indicates the transcription is done. stop playing audio - setTextAreaValue(prevState => prevState + `\nYou> ${message}\n`); + let msg = message.split("[+]You said: "); + setTextAreaValue(prevState => prevState + `\nYou> ${msg[1]}\n`); stopAudioPlayback(); } else if (message.startsWith('[=]')) { // [=] indicates the response is done @@ -128,7 +129,7 @@ const App = () => { // TODO: debug download video if (isConnected.current) { - if (!audioSent.current && callActive.current) { + if (!audioSent.current) { send(blob); } audioSent.current = false; @@ -342,7 +343,7 @@ const App = () => { { isConnected.current && !characterConfirmed ? (
-
) : null } @@ -376,6 +377,9 @@ const App = () => { setIsCallView={setIsCallView} useSearch={useSearch} setUseSearch={setUseSearch} + callActive={callActive} + startRecording={startRecording} + stopRecording={stopRecording} preferredLanguage={preferredLanguage} setPreferredLanguage={setPreferredLanguage} /> diff --git a/client/web/src/components/CallView/index.jsx b/client/web/src/components/CallView/index.jsx index af8e847c6..64043bf94 100644 --- a/client/web/src/components/CallView/index.jsx +++ b/client/web/src/components/CallView/index.jsx @@ -25,7 +25,7 @@ const CallView = ( {isRecording, isPlaying, audioPlayer, handleStopCall, handleC }, [isPlaying]); return ( - <> +
@@ -38,7 +38,7 @@ const CallView = ( {isRecording, isPlaying, audioPlayer, handleStopCall, handleC setIsCallView(false)} />
- +
) } diff --git a/client/web/src/components/CallView/style.css b/client/web/src/components/CallView/style.css index 814f4780a..e1572b5de 100644 --- a/client/web/src/components/CallView/style.css +++ b/client/web/src/components/CallView/style.css @@ -88,4 +88,15 @@ align-items: center; justify-content: space-between; flex-grow: 1; +} + +.call-screen { + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + flex-grow: 1; + width: 100%; + height: 30vh; + padding: 20px; } \ No newline at end of file diff --git a/client/web/src/components/Common/IconButton.js b/client/web/src/components/Common/IconButton.js index 72d62762f..831f0d7df 100644 --- a/client/web/src/components/Common/IconButton.js +++ b/client/web/src/components/Common/IconButton.js @@ -8,9 +8,10 @@ import React from 'react'; import './styles.css'; -const IconButton = ({ Icon, className, onClick, bgcolor="default"}) => { +const IconButton = ({ Icon, className, onClick, bgcolor="default", disabled=false}) => { return ( -
+
); diff --git a/client/web/src/components/Common/styles.css b/client/web/src/components/Common/styles.css index 4a5d73e73..af1d70090 100644 --- a/client/web/src/components/Common/styles.css +++ b/client/web/src/components/Common/styles.css @@ -78,3 +78,8 @@ .icon-button:hover .icon-instance-node-small { filter: brightness(2); } + +.icon-button.disabled { + opacity: 0.5; + cursor: not-allowed; +} \ No newline at end of file diff --git a/client/web/src/components/TextView/index.js b/client/web/src/components/TextView/index.js index 43713a789..018c44e84 100644 --- a/client/web/src/components/TextView/index.js +++ b/client/web/src/components/TextView/index.js @@ -5,13 +5,17 @@ * created by Lynchee on 7/16/23 */ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect, useRef, useState} from 'react'; import './style.css'; -import { TbPower, TbMicrophone } from 'react-icons/tb'; +import { TbPower, TbPhoneCall, TbMicrophone, TbPlayerStopFilled, TbKeyboard } from 'react-icons/tb'; import IconButton from '../Common/IconButton'; +import { MdVoiceChat } from 'react-icons/md'; +import Button from '../Common/Button'; -const TextView = ({ send, isPlaying, stopAudioPlayback, textAreaValue, setTextAreaValue, messageInput, setMessageInput, handleDisconnect, setIsCallView, useSearch, setUseSearch }) => { +const TextView = ({ send, isPlaying, stopAudioPlayback, textAreaValue, setTextAreaValue, messageInput, setMessageInput, handleDisconnect, setIsCallView, useSearch, setUseSearch, callActive, startRecording, stopRecording }) => { + const [keyboard, SetKeyboard] = useState(true); const chatWindowRef = useRef(null); + const talking = useRef(false); // always show the latest chat log useEffect(() => { @@ -51,8 +55,29 @@ const TextView = ({ send, isPlaying, stopAudioPlayback, textAreaValue, setTextAr setUseSearch(!useSearch); }; + const handlePushTalk = () => { + if (!talking.current) { + startRecording(); + talking.current = true; + if (isPlaying) { + stopAudioPlayback(); + } + } else { + stopRecording(); + talking.current = false; + } + } + + const handleKeyboardClick = () => { + SetKeyboard(true); + } + + const handleAudioClick = () => { + SetKeyboard(false); + } + return ( - <> +
-
- - +
+
+ + +
+ { !callActive.current && ( +
+ {keyboard ? + : + + } +
+ )}
- + + { !callActive.current && !keyboard ? + : +
) } diff --git a/client/web/src/components/TextView/style.css b/client/web/src/components/TextView/style.css index 0ac29af80..012a8c642 100644 --- a/client/web/src/components/TextView/style.css +++ b/client/web/src/components/TextView/style.css @@ -3,11 +3,26 @@ color: white; font-size: 17px; width: 100%; - height: 100%; + height: 25vh; border: none; resize: none; } +.input-container { + display: flex; + align-items: center; +} + +.text-screen { + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + flex-grow: 1; + width: 100%; + padding: 20px; +} + /* text input */ input[type="text"]{font: 15px/24px 'Muli', sans-serif; color: white; width: 100%; box-sizing: border-box; letter-spacing: 1px;} :focus{outline: none;} @@ -39,24 +54,6 @@ input[type="text"]{font: 15px/24px "Lato", Arial, sans-serif; color: white; widt .message-input:focus ~ .focus-border i:before, .message-input:focus ~ .focus-border i:after{height: 100%; transition: 0.4s;} -.send-btn { - font-family: "Prompt", Helvetica; - font-size: 1rem; - border-color: #6785d3; - color: #fff; - box-shadow: 0 0 10px 0 #6785d3 inset, 0 0 10px 4px #6785d3; - transition: all 150ms ease-in-out; - cursor: pointer; - background-color: transparent; - padding: 0.6em 2em; - border-radius: 1.5em; -} - -.send-btn:hover { - box-shadow: 0 0 40px 40px #6785d3 inset, 0 0 0 0 #6785d3; - outline: 0; -} - .options-container { display: flex; align-items: center; @@ -67,6 +64,28 @@ input[type="text"]{font: 15px/24px "Lato", Arial, sans-serif; color: white; widt } .search-checkbox { - margin-top: 5px; + margin-top: 15px; + color: white; +} + +.white { + color: white; +} + +.talk-on { + color: red; +} + +.talk-off { color: white; } + +.recording-animation { + animation: pulsate 1s infinite; +} + +@keyframes pulsate { + 0% { transform: scale(1); } + 50% { transform: scale(1.1); } + 100% { transform: scale(1); } +} \ No newline at end of file