Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue auto start stt #566

Open
wants to merge 1 commit into
base: preprod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion template/src/components/ChatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {createContext, SetStateAction} from 'react';
import {ChatMessageType, Reaction} from './chat-messages/useChatMessages';
import {createHook} from 'customization-implementation';


export interface ChatBubbleProps {
isLocal: boolean;
message: string;
Expand Down Expand Up @@ -67,6 +66,7 @@ export enum messageActionType {
}

export interface RtmContextInterface {
isInitialQueueCompleted: boolean;
hasUserJoinedRTM: boolean;
rtmInitTimstamp: number;
engine: RtmEngine;
Expand Down
47 changes: 38 additions & 9 deletions template/src/components/EventsConfigure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ import {logger, LogSource} from '../logger/AppBuilderLogger';
interface Props {
children: React.ReactNode;
callActive: boolean;
sttAutoStarted: boolean;
setSttAutoStarted: React.Dispatch<React.SetStateAction<boolean>>;
}

const EventsConfigure: React.FC<Props> = ({callActive, children}) => {
const EventsConfigure: React.FC<Props> = ({
callActive,
children,
setSttAutoStarted,
sttAutoStarted,
}) => {
const isSTTAlreadyActiveRef = useRef(undefined);
// mute user audio
const hostMutedUserAudioToastHeadingTT = useString<I18nMuteType>(
hostMutedUserToastHeading,
Expand Down Expand Up @@ -257,27 +265,26 @@ const EventsConfigure: React.FC<Props> = ({callActive, children}) => {
permissionStatusRef.current = permissionStatus;
}, [permissionStatus]);

const {hasUserJoinedRTM} = useContext(ChatContext);
const {hasUserJoinedRTM, isInitialQueueCompleted} = useContext(ChatContext);
const {startSpeechToText} = useSpeechToText();
const [autoStartCompleted, setAutoStartCompleted] = useState(false);

//auto start stt
useEffect(() => {
if (
$config.ENABLE_CAPTION &&
$config.STT_AUTO_START &&
callActive &&
hasUserJoinedRTM &&
!autoStartCompleted
isInitialQueueCompleted &&
!sttAutoStarted
) {
//host will start the caption
if (isHost && roomId?.host) {
if (isHost && roomId?.host && !isSTTAlreadyActiveRef.current) {
logger.log(LogSource.Internals, 'STT', 'STT_AUTO_START triggered');
//start with default language
startSpeechToText(['en-US'])
.then(() => {
logger.log(LogSource.Internals, 'STT', 'STT_AUTO_START success');
setAutoStartCompleted(true);
setSttAutoStarted(true);
})
.catch(err => {
logger.log(
Expand All @@ -286,11 +293,28 @@ const EventsConfigure: React.FC<Props> = ({callActive, children}) => {
'STT_AUTO_START failed',
err,
);
setAutoStartCompleted(false);
setSttAutoStarted(false);
});
}

if (isHost && roomId?.host && isSTTAlreadyActiveRef.current) {
logger.log(
LogSource.Internals,
'STT',
'STT_AUTO_START triggered already by some other host success',
);
setSttAutoStarted(true);
}
}
}, [callActive, isHost, hasUserJoinedRTM, roomId, autoStartCompleted]);
}, [
callActive,
isHost,
hasUserJoinedRTM,
roomId,
sttAutoStarted,
isInitialQueueCompleted,
isSTTAlreadyActiveRef.current,
]);

useEffect(() => {
//user joined event listener
Expand Down Expand Up @@ -520,6 +544,11 @@ const EventsConfigure: React.FC<Props> = ({callActive, children}) => {

events.on(EventNames.STT_ACTIVE, data => {
const payload = JSON.parse(data?.payload);
if (payload.active) {
isSTTAlreadyActiveRef.current = true;
} else {
isSTTAlreadyActiveRef.current = false;
}
setRoomInfo(prev => {
return {
...prev,
Expand Down
3 changes: 3 additions & 0 deletions template/src/components/RTMConfigure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const RtmConfigure = (props: any) => {
}, [defaultContent]);

const [hasUserJoinedRTM, setHasUserJoinedRTM] = useState<boolean>(false);
const [isInitialQueueCompleted, setIsInitialQueueCompleted] = useState(false);
const [onlineUsersCount, setTotalOnlineUsers] = useState<number>(0);

let engine = useRef<RtmEngine>(null!);
Expand Down Expand Up @@ -181,6 +182,7 @@ const RtmConfigure = (props: any) => {
});
setHasUserJoinedRTM(true);
await runQueuedEvents();
setIsInitialQueueCompleted(true);
logger.log(
LogSource.AgoraSDK,
'Log',
Expand Down Expand Up @@ -811,6 +813,7 @@ const RtmConfigure = (props: any) => {
return (
<ChatContext.Provider
value={{
isInitialQueueCompleted,
rtmInitTimstamp,
hasUserJoinedRTM,
engine: engine.current,
Expand Down
5 changes: 5 additions & 0 deletions template/src/pages/VideoCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const VideoCall: React.FC = () => {
const [queryComplete, setQueryComplete] = useState(false);
const [waitingRoomAttendeeJoined, setWaitingRoomAttendeeJoined] =
useState(false);
const [sttAutoStarted, setSttAutoStarted] = useState(false);

const {phrase} = useParams<{phrase: string}>();

Expand Down Expand Up @@ -435,6 +436,10 @@ const VideoCall: React.FC = () => {
<CaptionProvider>
<WaitingRoomProvider>
<EventsConfigure
setSttAutoStarted={
setSttAutoStarted
}
sttAutoStarted={sttAutoStarted}
callActive={callActive}>
<ScreenshareConfigure
isRecordingActive={
Expand Down