Skip to content
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

Fix/join room event #194

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import tw.waterballsa.gaas.application.repositories.RoomRepository
import tw.waterballsa.gaas.application.repositories.UserRepository
import tw.waterballsa.gaas.application.usecases.GetRoomUsecase
import tw.waterballsa.gaas.domain.Room
import tw.waterballsa.gaas.events.ChatData
import tw.waterballsa.gaas.events.SocketioEvent
import tw.waterballsa.gaas.events.enums.EventMessageType
import javax.servlet.http.HttpServletRequest
Expand Down Expand Up @@ -74,22 +75,13 @@ class SocketIOEventHandler(

}

socketIOServer.addEventListener(SocketIOEventName.JOIN_ROOM.eventName, SocketioEvent::class.java) {
client: SocketIOClient, socketioEvent: SocketioEvent, _ ->
socketIOServer.addEventListener(SocketIOEventName.JOIN_ROOM.eventName, ChatData::class.java) {
client: SocketIOClient, socketioEvent: ChatData, _ ->

// ECHO
logger.info(" JOIN_ROOM Received message: $socketioEvent from client: ${client.sessionId}")
val roomSize = client.getCurrentRoomSize(socketioEvent.data.target)

if(roomSize == 0){
logger.info("user: " + client.sessionId + "you are the host ")
} else{
client.joinRoom(socketioEvent.data.target)
logger.info("Client joined room: ${socketioEvent.data.target}")
logger.info("id = " + socketioEvent.data.user.id + " nickname " + socketioEvent.data.user.nickname + " targetRoom " + socketioEvent.data.target)
logger.info(" room size is : ${client.getCurrentRoomSize(socketioEvent.data.target)}")
socketIOServer.getRoomOperations(socketioEvent.data.target).sendEvent(SocketIOEventName.JOIN_ROOM.eventName, socketioEvent.data.user.id)
}
client.joinRoom(socketioEvent.target)
logger.info("Client joined room: ${socketioEvent.target}")
logger.info("id = " + socketioEvent.user.id + " nickname " + socketioEvent.user.nickname + " targetRoom " + socketioEvent.target)
logger.info(" room size is : ${client.getCurrentRoomSize(socketioEvent.target)}")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class WebSocketEventBus(

// TODO broadcast the events!
override fun broadcast(events: Collection<DomainEvent>) {

for (event in events) {
if (event is PlayerJoinedRoomEvent) {
val data = event.data
val type = event.type
socketIOServer.broadcastOperations.sendEvent(type.toString(), data)

val roomId = "ROOM_${data.roomId}"
val room = socketIOServer.getRoomOperations(roomId)
room.sendEvent(type.eventName, data)
} else if(event is PlayerLeavedRoomEvent){
val data = event.data
val type = event.type
Expand Down
4 changes: 3 additions & 1 deletion spring/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spring:
audiences:
- https://api.gaas.waterballsa.tw

frontend: http://localhost:3030

server:
port: 8087

Expand All @@ -44,5 +46,5 @@ logging:
socketio:
host: 127.0.0.1
port: 9001
active: false
active: ${SOCKET_IO_SERVER_START:false}