https://github.com/asehee/streaming-p2p.git
์ด์ ์ง์ฐ P2P ๋ฉ์ ๋คํธ์ํฌ๋ฅผ ํ์ฉํ WebRTC ๊ธฐ๋ฐ ๋ผ์ด๋ธ ์คํธ๋ฆฌ๋ฐ SDK์ ๋๋ค. ์ด SDK๋ฅผ ์ฌ์ฉํ๋ฉด ์ค์ ์๋ฒ ์์กด๋๋ฅผ ๋ฎ์ถ๋ฉด์๋ ๋ค์์ ์์ฒญ์์๊ฒ ๊ณ ํ์ง์ ์คํธ๋ฆผ์ ์ ๋ฌํ ์ ์์ต๋๋ค.
# ์ ์ฅ์ ๋ณต์
git clone https://github.com/yourusername/p2p-mesh-streaming.git
# ์์กด์ฑ ์ค์น
cd p2p-mesh-streaming
npm install
# ๊ฐ๋ฐ ์๋ฒ ์คํ
npm run dev
# ๋น๋
npm run build
import { createStreamingSDK } from 'p2p-mesh-streaming';
// SDK ์ด๊ธฐํ
const streamingSdk = createStreamingSDK({
roomId: 'unique-room-id',
config: {
signalingServer: 'wss://your-signaling-server.com'
}
});
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
streamingSdk.on('connect', () => {
console.log('์๊ทธ๋๋ง ์๋ฒ์ ์ฐ๊ฒฐ๋์์ต๋๋ค');
});
streamingSdk.on('error', (error) => {
console.error('์ค๋ฅ ๋ฐ์:', error);
});
// ์คํธ๋ฆฌ๋ฐ ์์
async function startStream() {
const stream = await streamingSdk.startStreaming({
video: {
width: { ideal: 1280 },
height: { ideal: 720 },
frameRate: { ideal: 30 }
},
audio: true
});
// ๋ก์ปฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํ์
const videoElement = document.getElementById('local-video');
videoElement.srcObject = stream;
videoElement.play();
}
// ์คํธ๋ฆฌ๋ฐ ์ค์ง
function stopStream() {
streamingSdk.stop();
}
// ์คํธ๋ฆผ ํ์ง ๋ณ๊ฒฝ
function changeQuality(quality) {
// 'low', 'medium', 'high', 'auto' ์ค ์ ํ
streamingSdk.changeStreamQuality(quality);
}
import { createStreamingSDK } from 'p2p-mesh-streaming';
// SDK ์ด๊ธฐํ (๊ฐ์ roomId ์ฌ์ฉ)
const streamingSdk = createStreamingSDK({
roomId: 'unique-room-id',
config: {
signalingServer: 'wss://your-signaling-server.com'
}
});
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
streamingSdk.on('connect', () => {
console.log('์๊ทธ๋๋ง ์๋ฒ์ ์ฐ๊ฒฐ๋์์ต๋๋ค');
});
streamingSdk.on('error', (error) => {
console.error('์ค๋ฅ ๋ฐ์:', error);
});
// ์์ฒญ ์์
async function startViewing() {
const videoElement = document.getElementById('remote-video');
await streamingSdk.startViewing(videoElement);
}
// ์์ฒญ ์ค์ง
function stopViewing() {
streamingSdk.stop();
}
// ๋คํธ์ํฌ ํต๊ณ ๊ฐ์ ธ์ค๊ธฐ
function getNetworkStats() {
const stats = streamingSdk.getNetworkStats();
console.log('๋คํธ์ํฌ ํต๊ณ:', stats);
}
์ค์ ์นด๋ฉ๋ผ์ ์๊ทธ๋๋ง ์๋ฒ ์์ด๋ ๊ฐ๋ฐ ๋ฐ ํ ์คํธ๋ฅผ ์งํํ ์ ์์ต๋๋ค:
// ํ
์คํธ ๋ชจ๋๋ก SDK ์ด๊ธฐํ
const streamingSdk = createStreamingSDK({
roomId: 'test-room',
config: {
testMode: true // ํ
์คํธ ๋ชจ๋ ํ์ฑํ
}
});