File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
1
import Games from '@game/Games' ;
2
2
3
- export const onSendChat = ( socket , { message } ) => {
3
+ function onSendChat ( { message } ) {
4
+ const socket = this ;
4
5
const roomID = Games . findRoomID ( socket . id ) ;
5
6
if ( ! roomID ) return ;
6
7
7
8
const { nickname } = Games . findUserInfo ( socket . id ) ;
8
9
socket . in ( roomID ) . emit ( 'send chat' , { message, nickname } ) ;
9
- } ;
10
+ }
11
+
12
+ export default function onChat ( socket ) {
13
+ socket . on ( 'send chat' , onSendChat ) ;
14
+ }
Original file line number Diff line number Diff line change 1
1
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' ;
4
4
5
5
const socketIO = io ( ) ;
6
6
7
7
socketIO . on ( 'connection' , ( socket ) => {
8
8
console . log ( 'a user connected' ) ;
9
9
10
- socket . on ( 'join player' , ( params ) => onJoinPlayer ( socket , { ... params } ) ) ;
11
- socket . on ( 'send chat' , ( params ) => onSendChat ( socket , { ... params } ) ) ;
10
+ onWaitingRoom ( socket ) ;
11
+ onChat ( socket ) ;
12
12
} ) ;
13
13
14
14
export default socketIO ;
Original file line number Diff line number Diff line change 1
1
import Games from '@game/Games' ;
2
2
3
- export const onJoinPlayer = ( socket , { roomID } ) => {
3
+ function onJoinPlayer ( { roomID } ) {
4
+ const socket = this ;
4
5
if ( ! roomID || ! Games . isEnterableRoom ( roomID ) ) return ;
5
6
6
7
Games . enterUser ( { socketID : socket . id , roomID } ) ;
@@ -11,4 +12,8 @@ export const onJoinPlayer = (socket, { roomID }) => {
11
12
roomID,
12
13
players : [ ] ,
13
14
} ) ;
14
- } ;
15
+ }
16
+
17
+ export default function onWaitingRoom ( socket ) {
18
+ socket . on ( 'join player' , onJoinPlayer ) ;
19
+ }
You can’t perform that action at this time.
0 commit comments