WebRTC(μ›Ή μ‹€μ‹œκ°„ 톡신)λŠ” HTML5μ—μ„œ μ§€μ›ν•˜λŠ” 기술둜, μ›Ή λΈŒλΌμš°μ € 간에 μŒμ„±, λΉ„λ””μ˜€ 및 데이터λ₯Ό μ‹€μ‹œκ°„μœΌλ‘œ 전솑할 수 있게 ν•΄μ£ΌλŠ” μ˜€ν”ˆ μ†ŒμŠ€ ν”„λ‘œμ νŠΈμž…λ‹ˆλ‹€. WebRTCλŠ” 주둜 JavaScript API둜 μ‚¬μš©λ˜λ©°, μ—¬κΈ°μ—λŠ” λ―Έλ””μ–΄ 슀트리밍, 데이터 κ΅ν™˜ 및 λ„€νŠΈμ›Œν¬ 정보 μˆ˜μ§‘μ„ μœ„ν•œ λ‹€μ–‘ν•œ APIκ°€ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜λŠ” WebRTCλ₯Ό μ‚¬μš©ν•œ κ°„λ‹¨ν•œ μ˜ˆμ œμž…λ‹ˆλ‹€.

  1. λ―Έλ””μ–΄ 슀트리밍(μŒμ„± 및 λΉ„λ””μ˜€)
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>WebRTC Example</title> </head> <body> <h1>WebRTC Media Streaming Example</h1> <video id="localVideo" autoplay muted></video> <video id="remoteVideo" autoplay></video> <script> navigator.mediaDevices.getUserMedia({ video: true, audio: true }) .then((stream) => { const localVideo = document.getElementById('localVideo'); localVideo.srcObject = stream; // Send the stream to a peer (not shown in this example) }) .catch((error) => { console.error('Error accessing media devices:', error); }); </script> </body> </html>
  1. ν”Όμ–΄ κ°„ 데이터 κ΅ν™˜
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>WebRTC Data Channel Example</title> </head> <body> <h1>WebRTC Data Channel Example</h1> <textarea id="localDataChannel"></textarea> <textarea id="remoteDataChannel"></textarea> <script> const localDataChannel = document.getElementById('localDataChannel'); const remoteDataChannel = document.getElementById('remoteDataChannel'); const peerConnection = new RTCPeerConnection(); // Create a data channel const dataChannel = peerConnection.createDataChannel('myDataChannel'); // Set up event handlers dataChannel.onopen = () => { console.log('Data channel opened'); }; dataChannel.onmessage = (event) => { remoteDataChannel.value += event.data + '\n'; }; // Offer/answer code (not shown in this example) // Set up the local data channel localDataChannel.addEventListener('input', () => { const message = localDataChannel.value; dataChannel.send(message); }); </script> </body> </html>

μ΄λŸ¬ν•œ μ˜ˆμ œλŠ” WebRTC의 κΈ°λ³Έ κ°œλ…μ„ 보여주기 μœ„ν•œ κ°„λ‹¨ν•œ 것이며, 더 λ³΅μž‘ν•œ μ‹œλ‚˜λ¦¬μ˜€μ—μ„œλŠ” SDP(Offer/Answer), ICE(Interactive Connectivity Establishment) 등이 더 많이 μ‚¬μš©λ  수 μžˆμŠ΅λ‹ˆλ‹€. μ™„μ „ν•œ WebRTC μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ€ 더 λ§Žμ€ μ½”λ“œμ™€ μ„œλ²„ μΈ‘ 둜직이 ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.