From 29153400e657bc481889a8e55892954c357eb178 Mon Sep 17 00:00:00 2001 From: bangae1 Date: Mon, 20 Oct 2025 21:15:31 +0900 Subject: [PATCH] qa --- frontend/src/remote.jsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/remote.jsx b/frontend/src/remote.jsx index 8825752..8cd6ad2 100644 --- a/frontend/src/remote.jsx +++ b/frontend/src/remote.jsx @@ -3,7 +3,6 @@ import { useState, useRef, useEffect } from 'react'; import io from 'socket.io-client'; const SIGNALING_SERVER = 'http://localhost:3001'; // 실제 서버 주소로 변경 - export default function RemoteControl() { const [employeeId, setEmployeeId] = useState('psn14020'); const [status, setStatus] = useState('disconnected'); // 'disconnected' | 'connecting' | 'connected' @@ -14,6 +13,7 @@ export default function RemoteControl() { const videoRef = useRef(null); const socketRef = useRef(null); const peerConnectionRef = useRef(null); + const EMPLOYEE_ID = "psn14020_client"; // 🔌 소켓 연결 useEffect(() => { @@ -23,6 +23,11 @@ export default function RemoteControl() { }); socketRef.current = socket; + socket.on('connect', () => { + console.log('시그널링 서버 연결됨. 직원 등록 중...'); + socket.emit('register', EMPLOYEE_ID); + }); + socket.on('availableDisplays', ({ displays }) => { setDisplays(displays); if (displays.length > 0 && !selectedDisplay) { @@ -30,11 +35,11 @@ export default function RemoteControl() { } }); - socket.on('webrtcSignal', async ({ data }) => { + socket.on('webrtcSignal', async (data) => { if (!peerConnectionRef.current) return; try { if (data.type === 'answer') { - await peerConnectionRef.current.setRemoteDescription(new RTCSessionDescription(data)); + await peerConnectionRef.current.setRemoteDescription(new RTCSessionDescription(data.answer)); setStatus('connected'); setIsControlling(true); } else if (data.type === 'icecandidate' && data.candidate) { @@ -67,6 +72,7 @@ export default function RemoteControl() { peerConnectionRef.current = pc; pc.ontrack = (event) => { + console.log(event) if (videoRef.current) { videoRef.current.srcObject = event.streams[0]; } @@ -86,12 +92,14 @@ export default function RemoteControl() { const offer = await pc.createOffer({ offerToReceiveVideo: true }); await pc.setLocalDescription(offer); + socketRef.current.emit('requestControl', { targetId: employeeId, offer: offer, displayId: selectedDisplay }); } catch (err) { + setStatus('disconnected'); console.error('연결 실패:', err); setStatus('disconnected'); }