-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Room #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feat: Room #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -51,11 +51,31 @@ const getPlayRoutes = (): expressWs.Router => { | |||
| return; | ||||
| } | ||||
|
|
||||
| const player:Player = { | ||||
| const player: Player = { | ||||
| id: playerId, | ||||
| connection: ws | ||||
| } | ||||
| currentRoom.set(playerId,player); | ||||
| currentRoom.set(playerId, player); | ||||
|
|
||||
| // | ||||
| currentRoom.forEach((rplayer) => { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Đang không hiểu đoạn Nếu được thì ông thêm explanation vào đây và thêm comments nhé
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. forEach được chạy khi có player bất kì ngắt kết nối. Nhiệm vụ gửi thông báo cho các player còn lại trong room về việc người chơi này đã ngắt kết nối
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hình như nhầm đoạn Cái t không hiểu lắm là tại sao tại phải có message type là
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. backstage/src/routers/ws/playRoutes.ts Line 61 in 36abb68
|
||||
| if (rplayer.id === player.id) { | ||||
| return; | ||||
| } | ||||
| player.connection.send(JSON.stringify( | ||||
| { | ||||
| method: 'SUBSCRIBE', | ||||
| player: rplayer.id | ||||
| } | ||||
| )); | ||||
| rplayer.connection.send(JSON.stringify( | ||||
| { | ||||
| method: 'SUBSCRIBE', | ||||
| player: player.id | ||||
| } | ||||
| )); | ||||
| }); | ||||
| // | ||||
|
|
||||
| ws.on('message', (data) => { | ||||
| const message = JSON.parse(data.toString()); | ||||
|
|
@@ -64,7 +84,12 @@ const getPlayRoutes = (): expressWs.Router => { | |||
| if (rplayer.id === player.id) { | ||||
| return; | ||||
| } | ||||
| rplayer.connection.send(JSON.stringify({player: player.id, messsage: message})); | ||||
| rplayer.connection.send(JSON.stringify( | ||||
| { | ||||
| method: 'MESSAGE', | ||||
| player: player.id, message: message | ||||
| } | ||||
| )); | ||||
| }); | ||||
| }); | ||||
|
|
||||
|
|
@@ -74,6 +99,15 @@ const getPlayRoutes = (): expressWs.Router => { | |||
|
|
||||
| if (currentRoom.size) { | ||||
| roomList.set(roomId, currentRoom); | ||||
|
|
||||
| currentRoom.forEach((rplayer) => { | ||||
| rplayer.connection.send(JSON.stringify( | ||||
| { | ||||
| method: 'UNSUBSCRIBE', | ||||
| player: player.id | ||||
| } | ||||
| )); | ||||
| }); | ||||
| } else { | ||||
| roomList.delete(roomId) | ||||
| } | ||||
|
|
||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove uneccessary comment mark