Skip to content

Commit

Permalink
Merge pull request #2 from Linkode2024/LINKODE-47-자료실-이슈-실시간구현
Browse files Browse the repository at this point in the history
Feat : 파일 업로드 이벤트 생성, 이슈 업로드 이벤트 생성
  • Loading branch information
jsilver01 authored Sep 23, 2024
2 parents 4d95f64 + d6e0eb4 commit 9e248dc
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let webServer;
let socketServer;
let expressApp;
let mediasoupRouter;

let io;
const roomManager = new RoomManager();

(async () => {
Expand Down Expand Up @@ -106,6 +106,25 @@ async function runExpressApp() {
next();
}
});

expressApp.post('/api/broadcast', (req, res) => {
const { studyroomId, memberId, event, data } = req.body;
console.log(`Broadcasting event: ${event} for studyroom: ${studyroomId}, member: ${memberId}`);

if (!io) {
console.error('Socket.IO not initialized');
return res.status(500).send('Internal server error: Socket.IO not initialized');
}

try {
io.to(studyroomId.toString()).emit(event, { memberId, response: data });
res.status(200).send('Broadcast successful');
} catch (error) {
console.error('Error broadcasting:', error);
res.status(500).send('Internal server error: ' + error.message);
}
});

}

async function runWebServer() {
Expand Down Expand Up @@ -144,7 +163,7 @@ async function runSocketServer() {
path: '/socket.io',
log: false,
});

io = socketServer;
socketServer.on('connection', async (socket) => {
console.log('client connected');

Expand Down Expand Up @@ -372,6 +391,20 @@ async function runSocketServer() {
callback({ error: 'Failed to resume consumer' });
}
});

socket.on('fileUploaded', (data) => {
const { memberId, response } = data;
console.log(`Member ${memberId} uploaded a file:`, response);
// UI 업데이트 또는 알림 표시 로직 추가
alert(`Member ${memberId} uploaded a new file: ${response.dataName}`);
});

socket.on('issueUploaded', (data) => {
const { memberId, response } = data;
console.log(`Member ${memberId} uploaded a issue:`, response);
// UI 업데이트 또는 알림 표시 로직 추가
alert(`Member ${memberId} uploaded a new issue: ${response.dataName}`);
});

} catch (error) {
console.error('Error in socket connection:', error);
Expand Down Expand Up @@ -492,5 +525,6 @@ module.exports = {
runExpressApp,
runWebServer,
runSocketServer,
runMediasoupWorker
runMediasoupWorker,
io
};

0 comments on commit 9e248dc

Please sign in to comment.