μλ
νμΈμ, TypeScritpμ Reactλ₯Ό μ΄μ©ν WebRTC κ°λ°μ νκ³ μμ΅λλ€.
νλ‘μ νΈ λμ€ μλμ κ°μ μ€λ₯ μ¬νμ΄ λ°μλμ΄μ λ€μ λ€μ μ°Ύμλ³Έ κ²°κ³Ό μ
λλ€.
μ νλ©΄μμ 보면 React Hook "useState", "useEffect"μ λν React function componentμ λν μ€λ₯κ° μμ΄μ κ°λ°μλ€μ μ Stackoverflowλ₯Ό ν΅ν΄μ ν΄κ²° νμμ΅λλ€.
import React, { useState, useEffect} from "react";
import RTCVideo from '../Components/RTCVideo';
const rtc = () => {
const [localStream, setLocalStream] = useState<MediaStream>();
useEffect(()=>{
navigator.mediaDevices.getUserMedia({video: true})
.then(stream=>{
setLocalStream(stream);
})
},[]);
return (
<div>
<RTCVideo
mediaStream = {localStream}
/>
</div>
);
};
export default rtc;
μ μ½λμμ μ€λ₯κ° μμ΅λλ€. const rtc = () =>
μ λν΄μ μ€λ₯κ° μμ΅λλ€. μλ¬Έμμ λλ¬Έμλ‘ μ»΄ν¬λνΈ μ΄λ¦μ νλ©΄ μ’μ κ² κ°λ€κ³ λμ μμ΅λλ€.
μμ λ΄μ©μμ λ³΄λ€ μΆμ΄ μλ¬Έμλ‘ μ»΄ν¬λνΈ μ΄λ¦μ μ¬μ©νμ§ λ§κ³ λλ¬Έμλ‘ μ»΄ν¬λνΈλ₯Ό μ§μ§ λ§κ³ λλ¬Έμμ μλ¬Έμλ₯Ό μ¬μ©νμ¬μ ν΄κ²°μ νμμ΅λλ€.
import React, { useState, useEffect} from "react";
import RTCVideo from '../Components/RTCVideo';
const RTC = () => {
const [localStream, setLocalStream] = useState<MediaStream>();
useEffect(()=>{
navigator.mediaDevices.getUserMedia({video: true})
.then(stream=>{
setLocalStream(stream);
})
},[]);
return (
<div>
<RTCVideo
mediaStream = {localStream}
/>
</div>
);
};
export default RTC;
μμ κ°μ΄ λλ¬Έμμ μλ¬Έμλ₯Ό μ΄μ©ν΄μ λ§λ€κ±°λ μ μ²λΌ λλ¬Έμλ‘ λ§λ€λ©΄ λ©λλ€!
κ·Έλ¬λ©΄ μμ κ°μ΄ ν΄κ²°νλ©΄ λ©λλ€ π€©