source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/api/ChatController.kt

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 841 bytes
Line 
1package mk.ukim.finki.busngobackend.api
2
3import org.springframework.messaging.handler.annotation.MessageMapping
4import org.springframework.messaging.handler.annotation.Payload
5import org.springframework.messaging.handler.annotation.SendTo
6import org.springframework.messaging.simp.SimpMessageHeaderAccessor
7import org.springframework.web.bind.annotation.RestController
8
9@RestController
10class ChatController {
11 @MessageMapping("/chat.sendMessage")
12 @SendTo("/topic/public")
13 fun sendMessage(
14 @Payload message: String,
15 ): String = message
16
17 @MessageMapping("/chat.addUser")
18 @SendTo("/topic/public")
19 fun addUser(
20 @Payload message: String,
21 headerAccessor: SimpMessageHeaderAccessor,
22 ): String {
23 headerAccessor.sessionAttributes?.put("username", message)
24 return message
25 }
26}
Note: See TracBrowser for help on using the repository browser.