1
1
package com.backgu.amaker.realtime.ws.handler
2
2
3
+ import com.backgu.amaker.realtime.server.config.ServerConfig
3
4
import com.backgu.amaker.realtime.utils.WebSocketSessionUtils
4
- import com.backgu.amaker.realtime.workspace.service.WorkspaceUserService
5
+ import com.backgu.amaker.realtime.workspace.service.WorkspaceSessionFacadeService
6
+ import com.backgu.amaker.realtime.workspace.session.WorkspaceWebSocketSession
5
7
import com.backgu.amaker.realtime.ws.constants.WebSocketConstants.Companion.USER_ID
6
8
import com.backgu.amaker.realtime.ws.constants.WebSocketConstants.Companion.WORKSPACE_ID
7
- import com.backgu.amaker.realtime.ws.session.SessionInfo
8
- import com.backgu.amaker.realtime.ws.session.storage.SessionStorage
9
9
import org.springframework.stereotype.Component
10
10
import org.springframework.web.socket.CloseStatus
11
11
import org.springframework.web.socket.WebSocketSession
12
12
import org.springframework.web.socket.handler.TextWebSocketHandler
13
13
14
14
@Component
15
15
class WebSocketSessionHandler (
16
- private val storage : SessionStorage < Long , String , SessionInfo > ,
17
- private val workspaceUserService : WorkspaceUserService ,
16
+ private val workspaceSessionFacadeService : WorkspaceSessionFacadeService ,
17
+ private val serverConfig : ServerConfig ,
18
18
) : TextWebSocketHandler() {
19
19
override fun afterConnectionEstablished (session : WebSocketSession ) {
20
20
val userId: String = WebSocketSessionUtils .extractAttribute<String >(session, USER_ID )
21
21
val workspaceId = WebSocketSessionUtils .extractAttribute<Long >(session, WORKSPACE_ID )
22
-
23
- workspaceUserService.checkUserBelongToWorkspace(userId, workspaceId)
24
-
25
- storage.addSession(workspaceId, userId, SessionInfo (userId, workspaceId, session))
22
+ workspaceSessionFacadeService.enrollUserToWorkspaceSession(
23
+ userId,
24
+ workspaceId,
25
+ WorkspaceWebSocketSession (session.id, userId, workspaceId, serverConfig.id, session),
26
+ )
26
27
}
27
28
28
29
override fun afterConnectionClosed (
@@ -32,6 +33,10 @@ class WebSocketSessionHandler(
32
33
val userId: String = WebSocketSessionUtils .extractAttribute<String >(session, USER_ID )
33
34
val workspaceId = WebSocketSessionUtils .extractAttribute<Long >(session, WORKSPACE_ID )
34
35
35
- storage.removeSession(workspaceId, userId)
36
+ workspaceSessionFacadeService.dropOutWorkspaceSession(
37
+ userId,
38
+ workspaceId,
39
+ WorkspaceWebSocketSession (session.id, userId, workspaceId, serverConfig.id, session),
40
+ )
36
41
}
37
42
}
0 commit comments