Skip to content

Commit

Permalink
Merge pull request #51 from jjikky/fix/objet-join
Browse files Browse the repository at this point in the history
음성통화 참여 예외처리
  • Loading branch information
jjikky authored Sep 9, 2024
2 parents 06f2368 + c789c4f commit 1d39e2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ switch (config.envMode) {
break;
case 'dev':
initProdServer();
break;
default:
initLocalServer();
break;
Expand Down
18 changes: 17 additions & 1 deletion src/common/modules/socket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const https = require('https');

// TODO : 로깅 분리 및 모니터링 달기
// TODO : 요청 분리
// TOOD : 예외처리 분리
const redisCli = require('../redis');

module.exports = socketIoLoader = (io) => {
Expand Down Expand Up @@ -54,6 +53,23 @@ module.exports = socketIoLoader = (io) => {

const usersInObjet = await redisCli.lRange(objetKey, 0, -1);

const isUserExist = usersInObjet.map((user) => JSON.parse(user)).filter((user) => user.user_id === user_id);
if (isUserExist.length > 0) {
socket.emit('error_message', {
error: { status: 400, message: '이미 음성채팅에 참가중입니다.' },
});
socket.disconnect(true);
return;
}

if (usersInObjet.length >= maximum) {
socket.emit('error_message', {
error: { status: 403, message: '음성 채팅방이 가득 찼습니다.' },
});
socket.disconnect(true);
return;
}

await redisCli.rPush(objetKey, JSON.stringify({ socket_id, nickname, user_id, profile_image }));
await redisCli.set(socketKey, objet_id);

Expand Down

0 comments on commit 1d39e2b

Please sign in to comment.