Merge pull request 'back-clement-ws' (#7) from back-clement-ws into back-lucien
Reviewed-on: #7
This commit is contained in:
commit
de63550429
4 changed files with 11 additions and 10 deletions
|
|
@ -23,7 +23,7 @@ open class WebSocketConfig : WebSocketMessageBrokerConfigurer {
|
|||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
|
||||
// Register the "/ws" endpoint, enabling SockJS fallback options
|
||||
registry.addEndpoint("/ws")
|
||||
registry.addEndpoint("/ws/matches-app")
|
||||
.setAllowedOriginPatterns("*") // Allow connections from any origin (adjust for production)
|
||||
.withSockJS()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import fr.teamflash.fencerjudgeback.services.MatchService
|
|||
import fr.teamflash.fencerjudgeback.websocket.models.MatchUpdateMessage
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping
|
||||
import org.springframework.messaging.handler.annotation.SendTo
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor
|
||||
import org.springframework.stereotype.Controller
|
||||
|
|
@ -14,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping
|
|||
import org.springframework.web.socket.messaging.SessionSubscribeEvent
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/ws")
|
||||
@RequestMapping("/ws/matches")
|
||||
class MatchWebSocketController(
|
||||
private val matchService: MatchService,
|
||||
private val messagingTemplate: SimpMessagingTemplate
|
||||
|
|
@ -22,7 +21,7 @@ class MatchWebSocketController(
|
|||
|
||||
private val messageHistory = ArrayList<MatchBean>()
|
||||
|
||||
@MessageMapping("/matches")
|
||||
@MessageMapping("/all")
|
||||
fun receiveMessage(message: MatchBean) {
|
||||
println("/ws/matches $message")
|
||||
messageHistory.add(message)
|
||||
|
|
@ -37,8 +36,7 @@ class MatchWebSocketController(
|
|||
* Client sends to: /app/match.update
|
||||
* Server broadcasts to: /topic/match.updates
|
||||
*/
|
||||
@MessageMapping("/match.update")
|
||||
@SendTo("/topic/match.updates")
|
||||
@MessageMapping("/update")
|
||||
fun handleMatchUpdate(matchUpdateMessage: MatchUpdateMessage): MatchUpdateMessage {
|
||||
// Create a MatchBean from the update message
|
||||
val matchBean = MatchBean(
|
||||
|
|
@ -73,6 +71,7 @@ class MatchWebSocketController(
|
|||
val headerAccessor = StompHeaderAccessor.wrap(event.message)
|
||||
if (CHANNEL_NAME == headerAccessor.destination) {
|
||||
messagingTemplate.convertAndSend(CHANNEL_NAME, messageHistory)
|
||||
println("Lancement...")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +93,10 @@ class MatchWebSocketController(
|
|||
broadcastMatchUpdate(match)
|
||||
}
|
||||
|
||||
@MessageMapping("/add")
|
||||
fun addMatchtoMainList(match:MatchBean) {
|
||||
matchService.addMatch(match)
|
||||
messageHistory.add(match)
|
||||
broadcastMatchUpdate(match, MatchUpdateMessage.UpdateType.NEW_MATCH)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.teamflash.fencerjudgeback.websocket.controllers
|
||||
|
||||
import fr.teamflash.fencerjudgeback.config.CHANNEL_NAME
|
||||
import fr.teamflash.fencerjudgeback.entities.PlayerBean
|
||||
import fr.teamflash.fencerjudgeback.services.PlayerService
|
||||
import fr.teamflash.fencerjudgeback.websocket.models.PlayerUpdateMessage
|
||||
|
|
@ -64,6 +63,7 @@ class PlayerWebSocketController(
|
|||
}
|
||||
}
|
||||
|
||||
@MessageMapping
|
||||
fun addPlayerToMainList(playerBean: PlayerBean) {
|
||||
playerService.addPlayer(playerBean)
|
||||
broadcastPlayerUpdate(playerBean, PlayerUpdateMessage.UpdateType.PLAYER_CREATE)
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
|
||||
|
||||
<script>
|
||||
const stompClient = Stomp.over(new SockJS('/ws'));
|
||||
const channel = "/topic/match.updates";
|
||||
const stompClient = Stomp.over(new SockJS('/ws/matches-app'));
|
||||
const channel = "/ws/topic";
|
||||
|
||||
stompClient.connect({}, function () {
|
||||
stompClient.subscribe(channel, function (message) {
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
date: document.getElementById("matchDate").value
|
||||
};
|
||||
|
||||
stompClient.send("/app/match.update", {}, JSON.stringify(match));
|
||||
stompClient.send("/ws/matches/add", {}, JSON.stringify(match));
|
||||
}
|
||||
|
||||
function displayMessage(match) {
|
||||
Loading…
Add table
Reference in a new issue