// main.js const { app, BrowserWindow, Tray, Menu, nativeImage, ipcMain } = require('electron'); const path = require('path'); const io = require('socket.io-client'); const os = require('os'); // 고유 직원 ID (실제로는 설정 파일, 환경변수, 또는 도메인 계정 연동 권장) const EMPLOYEE_ID = "psn14020"; // 시그널링 서버 주소 const SIGNALING_SERVER = 'http://localhost:3001'; // 실제 서버로 변경 let tray = null; let mainWindow = null; let socket = null; let peerConnection = null; // 자동 시작 설정 (부팅 시 실행) app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true }); // 백그라운드 창 (화면 공유용, 눈에 보이지 않음) function createHiddenWindow() { mainWindow = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, contextIsolation: true, preload: path.join(__dirname, 'preload.js') } }); } // 트레이 아이콘 (선택 사항, 고령 사용자 친화적) function createTray() { const iconPath = path.join(__dirname, 'resources', 'icon.png'); const icon = nativeImage.createFromPath(iconPath); tray = new Tray(icon || undefined); const contextMenu = Menu.buildFromTemplate([ { label: `직원 ID: ${EMPLOYEE_ID}`, enabled: false }, { label: '종료', click: () => app.quit() } ]); tray.setToolTip('원격 지원 에이전트 실행 중'); tray.setContextMenu(contextMenu); } // WebRTC 연결 준비 function setupWebRTC() { // 실제 구현 시 RTCPeerConnection 생성, 스트림 처리 등 포함 // 여기선 간략히 placeholder console.log('WebRTC 준비됨'); } // 시그널링 연결 function connectToSignaling() { socket = io(SIGNALING_SERVER, { reconnection: true, reconnectionAttempts: Infinity, reconnectionDelay: 2000 }); socket.on('connect', () => { console.log('시그널링 서버 연결됨. 직원 등록 중...'); socket.emit('register', EMPLOYEE_ID); }); socket.on('controlRequest', async ({ from, offer }) => { // 🔔 사용자에게 알림 (간단한 확인 창) const { dialog } = require('electron'); const result = await dialog.showMessageBox({ type: 'question', title: '원격 연결 요청', message: `관리자로부터 원격 제어 요청이 왔습니다.\n허용하시겠습니까?`, buttons: ['허용', '거부'], defaultId: 1, cancelId: 1 }); if (result.response === 0) { // 허용 → WebRTC 연결 시작 socket.emit('webrtcSignal', { targetId: EMPLOYEE_ID, data: { type: 'answer', sdp: '...' } // 실제 SDP 생성 필요 }); setupWebRTC(); } else { socket.emit('webrtcSignal', { targetId: EMPLOYEE_ID, data: { type: 'reject' } }); } }); socket.on('webrtcSignal', ({ data }) => { // ICE candidate, answer 등 처리 console.log('WebRTC 신호 수신:', data); }); socket.on('disconnect', () => { console.log('시그널링 서버와 연결 끊김'); }); socket.on('error', (err) => { console.error('소켓 오류:', err); }); } // 앱 준비 완료 app.whenReady().then(() => { createHiddenWindow(); createTray(); connectToSignaling(); app.on('activate', () => { // macOS에서 dock 클릭 시 동작 (필요 시 창 표시) }); }); // 모든 창 닫힘 (Windows/Linux) app.on('window-all-closed', () => { // 앱 종료하지 않고 백그라운드 유지 });