123
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
let peerConnection = null;
|
||||
let currentStream = null;
|
||||
|
||||
let connection = false;
|
||||
// 메인 프로세스로부터 명령 수신 (IPC)
|
||||
console.log('electronAPI:', window.electronAPI);
|
||||
console.log('desktopCapturer:', window.desktopCapturer);
|
||||
@@ -33,41 +33,38 @@ window.electronAPI.receive('start-webrtc', async (data) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await peerConnection.setRemoteDescription(new RTCSessionDescription(data.offer));
|
||||
currentStream = stream;
|
||||
stream.getTracks().forEach(track => {
|
||||
console.log('track', track, stream);
|
||||
peerConnection.addTrack(track, stream)
|
||||
});
|
||||
|
||||
const offer = await peerConnection.createOffer({offerToReceiveVideo: true})
|
||||
await peerConnection.setLocalDescription(offer);
|
||||
window.electronAPI.send('offer', {type:'offer', targetId: data.targetId, offer})
|
||||
});
|
||||
|
||||
window.electronAPI.receive('displays', async (payload) => {
|
||||
window.desktopCapturer.getSources(['display'])
|
||||
});
|
||||
const answer = await peerConnection.createAnswer();
|
||||
await peerConnection.setLocalDescription(answer);
|
||||
connection = true;
|
||||
|
||||
|
||||
window.electronAPI.receive('answer', async (data) => {
|
||||
console.log('answer', data)
|
||||
await peerConnection.setRemoteDescription(new RTCSessionDescription(data.answer));
|
||||
console.log('connect')
|
||||
})
|
||||
window.electronAPI.send('requestAnswer', {type: 'answer', targetId: data.targetId, answer});
|
||||
|
||||
window.electronAPI.receive('webrtcSignal', async (data) => {
|
||||
try {
|
||||
console.log('webrtcSignal', data)
|
||||
if (!peerConnection) return;
|
||||
if (data.type === 'icecandidate' && data.candidate) {
|
||||
await peerConnection.addIceCandidate(new RTCIceCandidate(data.candidate));
|
||||
} else if(data.type === 'answer') {
|
||||
await peerConnection.setRemoteDescription(new RTCSessionDescription(data.answer));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('ICE candidate 처리 오류:', err);
|
||||
peerConnection.onicecandidate = (event) => {
|
||||
setTimeout(() => {
|
||||
console.log('icecandidate', event);
|
||||
window.electronAPI.send('icecandidate', {type: 'icecandidate', targetId: data.targetId, server:'agent', 'candidate': event.candidate});
|
||||
}, 2000)
|
||||
}
|
||||
});
|
||||
|
||||
window.electronAPI.receive('displays', async (data) => {
|
||||
await window.desktopCapturer.getSources(['display'])
|
||||
});
|
||||
|
||||
window.electronAPI.receive('icecandidate', async (data) => {
|
||||
if(connection) {
|
||||
console.log(data.candidate)
|
||||
await peerConnection.addIceCandidate(new RTCIceCandidate(data.candidate));
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
// desktopCapturer 사용을 위해 preload 필요
|
||||
// → 다음 단계에서 preload.js 설정
|
||||
Reference in New Issue
Block a user