-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
76 additions
and
148 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
src/main/java/toy/bookchat/bookchat/config/websocket/CustomWebSocketHandlerDecorator.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...in/java/toy/bookchat/bookchat/config/websocket/MessageAuthenticationArgumentResolver.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/toy/bookchat/bookchat/config/websocket/StompEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package toy.bookchat.bookchat.config.websocket; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.socket.messaging.SessionConnectedEvent; | ||
import org.springframework.web.socket.messaging.SessionDisconnectEvent; | ||
import org.springframework.web.socket.messaging.SessionSubscribeEvent; | ||
import toy.bookchat.bookchat.domain.participant.repository.ParticipantRepository; | ||
import toy.bookchat.bookchat.security.user.UserPrincipal; | ||
|
||
@Slf4j | ||
@Component | ||
public class StompEventListener { | ||
|
||
public static final int TOPIC_NAME_LENGTH = 7; | ||
|
||
private final ParticipantRepository participantRepository; | ||
|
||
public StompEventListener(ParticipantRepository participantRepository) { | ||
this.participantRepository = participantRepository; | ||
} | ||
|
||
@EventListener | ||
public void handleStompConnectEvent(SessionConnectedEvent event) { | ||
UsernamePasswordAuthenticationToken user = (UsernamePasswordAuthenticationToken) event.getUser(); | ||
UserPrincipal userPrincipal = (UserPrincipal) user.getPrincipal(); | ||
log.info("Stomp Connect Event :: {}", userPrincipal.getUsername()); | ||
} | ||
|
||
@EventListener | ||
public void handleStompDisconnectEvent(SessionDisconnectEvent event) { | ||
UsernamePasswordAuthenticationToken user = (UsernamePasswordAuthenticationToken) event.getUser(); | ||
UserPrincipal userPrincipal = (UserPrincipal) user.getPrincipal(); | ||
participantRepository.disconnectAllByUserId(userPrincipal.getUserId()); | ||
log.info("Stomp Disconnect Event :: {}", userPrincipal.getUsername()); | ||
} | ||
|
||
@EventListener | ||
public void handleStompSubscribeEvent(SessionSubscribeEvent event) { | ||
UsernamePasswordAuthenticationToken user = (UsernamePasswordAuthenticationToken) event.getUser(); | ||
UserPrincipal userPrincipal = (UserPrincipal) user.getPrincipal(); | ||
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage()); | ||
participantRepository.connect(userPrincipal.getUserId(), accessor.getDestination().substring(TOPIC_NAME_LENGTH)); | ||
log.info("Stomp Subscribe Event :: {}", userPrincipal.getUsername()); | ||
} | ||
|
||
@EventListener | ||
public void handleStompUnsubscribeEvent(SessionSubscribeEvent event) { | ||
UsernamePasswordAuthenticationToken user = (UsernamePasswordAuthenticationToken) event.getUser(); | ||
UserPrincipal userPrincipal = (UserPrincipal) user.getPrincipal(); | ||
String destination = StompHeaderAccessor.wrap(event.getMessage()).getDestination().substring(TOPIC_NAME_LENGTH); | ||
participantRepository.disconnect(userPrincipal.getUserId(), destination); | ||
log.info("Stomp Unsubscribe Event :: {}", userPrincipal.getUsername()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters