-
Notifications
You must be signed in to change notification settings - Fork 1
/
Subtitle.js
29 lines (27 loc) · 913 Bytes
/
Subtitle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import './Subtitle.css';
import { useParticipantProperty, useAppMessage } from '@daily-co/daily-react';
import { useState, useContext, useRef } from 'react';
import { LanguageContext } from '../../contexts/Language/LanguageContext';
export default function Subtitle({ id }) {
const [text, setText] = useState();
const [lang, setLang] = useContext(LanguageContext);
const textTimeout = useRef();
const sendAppMessage = useAppMessage({
onAppMessage: (ev) => {
if (lang.local?.subtitles === ev.data?.translation_language && ev.data?.session_id === id) {
setText(ev.data.translation);
if (textTimeout.current) {
clearTimeout(textTimeout.current);
}
textTimeout.current = setTimeout(() => {
setText('');
}, 7000);
}
},
});
return (
<div className="subtitle">
<p>{text && <span>{text}</span>}</p>
</div>
);
}