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 answer = await peerConnection.createAnswer();
|
||||
await peerConnection.setLocalDescription(answer);
|
||||
connection = true;
|
||||
|
||||
const offer = await peerConnection.createOffer({offerToReceiveVideo: true})
|
||||
await peerConnection.setLocalDescription(offer);
|
||||
window.electronAPI.send('offer', {type:'offer', targetId: data.targetId, offer})
|
||||
|
||||
window.electronAPI.send('requestAnswer', {type: 'answer', targetId: data.targetId, answer});
|
||||
|
||||
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 (payload) => {
|
||||
window.desktopCapturer.getSources(['display'])
|
||||
window.electronAPI.receive('displays', async (data) => {
|
||||
await window.desktopCapturer.getSources(['display'])
|
||||
});
|
||||
|
||||
|
||||
window.electronAPI.receive('answer', async (data) => {
|
||||
console.log('answer', data)
|
||||
await peerConnection.setRemoteDescription(new RTCSessionDescription(data.answer));
|
||||
console.log('connect')
|
||||
})
|
||||
|
||||
window.electronAPI.receive('webrtcSignal', async (data) => {
|
||||
try {
|
||||
console.log('webrtcSignal', data)
|
||||
if (!peerConnection) return;
|
||||
if (data.type === 'icecandidate' && data.candidate) {
|
||||
window.electronAPI.receive('icecandidate', async (data) => {
|
||||
if(connection) {
|
||||
console.log(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);
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
// desktopCapturer 사용을 위해 preload 필요
|
||||
// → 다음 단계에서 preload.js 설정
|
||||
51
main.js
51
main.js
@@ -113,9 +113,21 @@ function connectToSignaling() {
|
||||
});
|
||||
|
||||
|
||||
/*연결 요청 -> webrtc 시작 -> offer 전송*/
|
||||
socket.on('responseControl', async (data) => {
|
||||
console.log(data)
|
||||
// WebRTC 신호 수신 (ICE candidate 등)
|
||||
socket.on('icecandidate', async (data) => {
|
||||
rendererWindow.webContents.send('icecandidate', data);
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('시그널링 서버와 연결 끊김');
|
||||
if (peerConnection) {
|
||||
peerConnection.close();
|
||||
peerConnection = null;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('responseOffer', async (data) => {
|
||||
console.log('responseOffer', data);
|
||||
const result = await dialog.showMessageBox({
|
||||
type: 'question',
|
||||
title: '원격 연결 요청',
|
||||
@@ -130,31 +142,14 @@ function connectToSignaling() {
|
||||
rendererWindow.webContents.send('start-webrtc', {
|
||||
displayId: data.displayId,
|
||||
targetId: data.targetId,
|
||||
offer: data.offer,
|
||||
sources
|
||||
});
|
||||
} else {
|
||||
socket.emit('webrtcSignal', { targetId: data.targetId, data: { type: 'reject' } });
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('answer', async (data) => {
|
||||
rendererWindow.webContents.send('answer', data);
|
||||
console.log('answer', data);
|
||||
})
|
||||
|
||||
// WebRTC 신호 수신 (ICE candidate 등)
|
||||
socket.on('webrtcSignal', async (data) => {
|
||||
rendererWindow.webContents.send('webrtcSignal', data);
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('시그널링 서버와 연결 끊김');
|
||||
if (peerConnection) {
|
||||
peerConnection.close();
|
||||
peerConnection = null;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('error', (err) => {
|
||||
console.error('소켓 오류:', err);
|
||||
});
|
||||
@@ -196,6 +191,16 @@ ipcMain.on('input-event-from-renderer', (event, data) => {
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on('offer', (event, data) => {
|
||||
socket.emit('offer', data);
|
||||
ipcMain.on('requestAnswer', (event, data) => {
|
||||
socket.emit('requestAnswer', data);
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on('icecandidate', (event, data) => {
|
||||
socket.emit('icecandidate', data);
|
||||
})
|
||||
|
||||
ipcMain.on('start', (event, data) => {
|
||||
console.log('start', data);
|
||||
socket.emit('start', data);
|
||||
})
|
||||
Reference in New Issue
Block a user