Skip to content

Commit 3260314

Browse files
authored
Merge pull request #61 from boostcamp-2020/develop
Week2 Hotfixes
2 parents b3a4ae8 + 37a3585 commit 3260314

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

β€Žsrc/backend/sockets/chat.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import Games from '@game/Games';
22

3-
export const onSendChat = (socket, { message }) => {
3+
function onSendChat({ message }) {
4+
const socket = this;
45
const roomID = Games.findRoomID(socket.id);
56
if (!roomID) return;
67

78
const { nickname } = Games.findUserInfo(socket.id);
89
socket.in(roomID).emit('send chat', { message, nickname });
9-
};
10+
}
11+
12+
export default function onChat(socket) {
13+
socket.on('send chat', onSendChat);
14+
}

β€Žsrc/backend/sockets/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import io from 'socket.io';
2-
import { onJoinPlayer } from './waitingRoom';
3-
import { onSendChat } from './chat';
2+
import onWaitingRoom from './waitingRoom';
3+
import onChat from './chat';
44

55
const socketIO = io();
66

77
socketIO.on('connection', (socket) => {
88
console.log('a user connected');
99

10-
socket.on('join player', (params) => onJoinPlayer(socket, { ...params }));
11-
socket.on('send chat', (params) => onSendChat(socket, { ...params }));
10+
onWaitingRoom(socket);
11+
onChat(socket);
1212
});
1313

1414
export default socketIO;

β€Žsrc/backend/sockets/waitingRoom.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Games from '@game/Games';
22

3-
export const onJoinPlayer = (socket, { roomID }) => {
3+
function onJoinPlayer({ roomID }) {
4+
const socket = this;
45
if (!roomID || !Games.isEnterableRoom(roomID)) return;
56

67
Games.enterUser({ socketID: socket.id, roomID });
@@ -11,4 +12,8 @@ export const onJoinPlayer = (socket, { roomID }) => {
1112
roomID,
1213
players: [],
1314
});
14-
};
15+
}
16+
17+
export default function onWaitingRoom(socket) {
18+
socket.on('join player', onJoinPlayer);
19+
}

β€Žsrc/backend/utils/generateRandom.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import nickname from './nickname.json';
2+
13
const randomStrings = new Set();
24

35
const generateRandomString = () =>
46
Math.random().toString(36).substr(2, 5).toUpperCase();
57

68
export default {
7-
nickname: () => 'μ½”λ”©ν•˜λŠ” 덕싯',
9+
nickname: () => {
10+
const { adjective: adj, noun } = nickname;
11+
const randomAdj = adj[Math.floor(Math.random() * adj.length)];
12+
const randomNoun = noun[Math.floor(Math.random() * noun.length)];
13+
return `${randomAdj} ${randomNoun}`;
14+
},
815
color: () => '#222222',
916
code: () => {
1017
let randomString = generateRandomString();

β€Žsrc/backend/utils/nickname.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"adjective": ["μ½”λ”©ν•˜λŠ”", "열정적인", "JS덕후", "μ–Όμ£½μ•„", "μΉ΄νŽ˜μΈμ€‘λ…", "νŒ¨μ…˜μ™•", "μ§‘μ—λ§Œ μžˆλŠ”", "λ°€μƒˆλŠ”", "λ°°κ³ ν”ˆ", "κ³ λ…ν•œ", "발λͺ…μ™•", "μ²­μ†Œλ₯Ό μ’‹μ•„ν•˜λŠ”", "λͺ…탐정"],
3+
"noun": ["덕싯", "캠퍼", "λ½€λ‘œλ‘œ", "도라에λͺ½", "개발자", "μ½”λ”©μ™•", "미식가", "μ‚°νƒ€ν΄λ‘œμŠ€", "집사", "ν”„λ‘ νŠΈ 개발자", "λ°±μ—”λ“œ 개발자", "iOS 개발자", "μ½”λ‚œ", "μ•„ν‹°μŠ€νŠΈ"]
4+
}

0 commit comments

Comments
Β (0)