I code WebSocket application with help classical Spring 5 WebSocket API, i.e. without using of SockJS and STOMP. I have a problem to get all active http-sessions. I can get one
The SimpUserRegistry
(DefaultSimpUserRegistry
) keeps track of connected websocket users.
The method getUsers()
returns all the connected users along with their sessions.
Here is a sample code:
@RestController
public class WebSocketController {
private final SimpUserRegistry simpUserRegistry;
public WebSocketController(SimpUserRegistry simpUserRegistry) {
this.simpUserRegistry = simpUserRegistry;
}
@GetMapping("/ws/users")
public List<String> connectedEquipments() {
return this.simpUserRegistry
.getUsers()
.stream()
.map(SimpUser::getName)
.collect(Collectors.toList());
}
}