WebRTC(μΉ μ€μκ° ν΅μ )λ HTML5μμ μ§μνλ κΈ°μ λ‘, μΉ λΈλΌμ°μ κ°μ μμ±, λΉλμ€ λ° λ°μ΄ν°λ₯Ό μ€μκ°μΌλ‘ μ μ‘ν μ μκ² ν΄μ£Όλ μ€ν μμ€ νλ‘μ νΈμ λλ€. WebRTCλ μ£Όλ‘ JavaScript APIλ‘ μ¬μ©λλ©°, μ¬κΈ°μλ λ―Έλμ΄ μ€νΈλ¦¬λ°, λ°μ΄ν° κ΅ν λ° λ€νΈμν¬ μ 보 μμ§μ μν λ€μν APIκ° ν¬ν¨λμ΄ μμ΅λλ€. μλλ WebRTCλ₯Ό μ¬μ©ν κ°λ¨ν μμ μ λλ€.
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>
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 μ ν리μΌμ΄μ μ λ λ§μ μ½λμ μλ² μΈ‘ λ‘μ§μ΄ νμν μ μμ΅λλ€.