mirror of
https://git.hmsn.ink/rtc-remote/server.git
synced 2026-03-20 00:12:17 +09:00
asdf
This commit is contained in:
34
server.js
34
server.js
@@ -14,6 +14,7 @@ const io = socketIo(server, {
|
|||||||
|
|
||||||
// 직원 ID ↔ socket.id 매핑
|
// 직원 ID ↔ socket.id 매핑
|
||||||
const employeeSockets = new Map(); // { employeeId: socketId }
|
const employeeSockets = new Map(); // { employeeId: socketId }
|
||||||
|
const employeeDisplays = new Map(); // { employeeId: displays[] }
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log('새 클라이언트 연결됨:', socket.id);
|
console.log('새 클라이언트 연결됨:', socket.id);
|
||||||
@@ -29,19 +30,31 @@ io.on('connection', (socket) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 관리자가 특정 직원에게 연결 요청
|
// 2. 관리자가 연결 요청
|
||||||
socket.on('requestControl', ({ targetId, offer }) => {
|
socket.on('requestControl', ({ targetId, offer, displayId }) => {
|
||||||
const targetSocketId = employeeSockets.get(targetId);
|
const targetSocketId = employeeSockets.get(targetId);
|
||||||
if (targetSocketId) {
|
if (targetSocketId) {
|
||||||
io.to(targetSocketId).emit('controlRequest', {
|
io.to(targetSocketId).emit('controlRequest', {
|
||||||
from: socket.id,
|
from: socket.id,
|
||||||
offer
|
offer,
|
||||||
|
displayId // 선택된 디스플레이 ID 전달
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
console.log(`직원 ${targetId}가 오프라인입니다.`);
|
||||||
socket.emit('error', `직원 ${targetId}가 오프라인입니다.`);
|
socket.emit('error', `직원 ${targetId}가 오프라인입니다.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2.5. 관리자가 디스플레이 목록 요청
|
||||||
|
socket.on('requestDisplays', (employeeId) => {
|
||||||
|
const displays = employeeDisplays.get(employeeId);
|
||||||
|
if (displays) {
|
||||||
|
socket.emit('availableDisplays', { displays });
|
||||||
|
} else {
|
||||||
|
socket.emit('error', `직원 ${employeeId}의 디스플레이 정보가 없습니다.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 3. WebRTC 시그널링 (SDP, ICE)
|
// 3. WebRTC 시그널링 (SDP, ICE)
|
||||||
socket.on('webrtcSignal', ({ targetId, data }) => {
|
socket.on('webrtcSignal', ({ targetId, data }) => {
|
||||||
const targetSocketId = employeeSockets.get(targetId);
|
const targetSocketId = employeeSockets.get(targetId);
|
||||||
@@ -50,6 +63,14 @@ io.on('connection', (socket) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 4. 입력 이벤트 전달 (관리자 → 직원)
|
||||||
|
socket.on('inputEvent', ({ targetId, ...data }) => {
|
||||||
|
const targetSocketId = employeeSockets.get(targetId);
|
||||||
|
if (targetSocketId) {
|
||||||
|
io.to(targetSocketId).emit('inputEvent', data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 연결 종료 시 정리
|
// 연결 종료 시 정리
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
if (socket.employeeId) {
|
if (socket.employeeId) {
|
||||||
@@ -58,6 +79,13 @@ io.on('connection', (socket) => {
|
|||||||
console.log(`직원 오프라인: ${socket.employeeId}`);
|
console.log(`직원 오프라인: ${socket.employeeId}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('availableDisplays', ({ displays }) => {
|
||||||
|
if (socket.employeeId && displays) {
|
||||||
|
employeeDisplays.set(socket.employeeId, displays);
|
||||||
|
console.log(`디스플레이 목록 저장됨: ${socket.employeeId}`, displays);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
|
|||||||
Reference in New Issue
Block a user