2024-02-21 11:47:40 +08:00
|
|
|
package com.rax.vital.config;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
2024-03-15 13:30:31 +08:00
|
|
|
import org.springframework.messaging.Message;
|
|
|
|
import org.springframework.messaging.MessageChannel;
|
|
|
|
import org.springframework.messaging.simp.config.ChannelRegistration;
|
2024-02-21 11:47:40 +08:00
|
|
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
2024-03-15 13:30:31 +08:00
|
|
|
import org.springframework.messaging.simp.stomp.StompCommand;
|
|
|
|
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
|
|
|
import org.springframework.messaging.support.ChannelInterceptor;
|
|
|
|
import org.springframework.messaging.support.MessageHeaderAccessor;
|
|
|
|
import org.springframework.security.core.Authentication;
|
2024-02-21 11:47:40 +08:00
|
|
|
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
|
|
|
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
|
|
|
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@EnableWebSocketMessageBroker
|
|
|
|
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
2024-03-15 13:30:31 +08:00
|
|
|
registry.addEndpoint("/rax/chat", "/rax/ai-medicine", "/rax/doctor-medicine", "/rax/vital-signs", "/rax/SurgeryData")
|
|
|
|
.setAllowedOrigins("*");
|
2024-02-21 11:47:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
|
|
|
registry.enableSimpleBroker("/topic");
|
|
|
|
registry.setApplicationDestinationPrefixes("/front");
|
2024-03-01 13:01:35 +08:00
|
|
|
registry.setUserDestinationPrefix("/topic/user");
|
2024-02-21 11:47:40 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 13:30:31 +08:00
|
|
|
@Override
|
|
|
|
public void configureClientInboundChannel(ChannelRegistration registration) {
|
|
|
|
registration.interceptors(new ChannelInterceptor() {
|
|
|
|
@Override
|
|
|
|
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
|
|
|
StompHeaderAccessor accessor =
|
|
|
|
MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
|
|
|
if (StompCommand.CONNECT.equals(accessor.getCommand())) {
|
|
|
|
//Authentication user = ... ; // access authentication header(s)
|
|
|
|
// accessor.setUser(user);
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-21 11:47:40 +08:00
|
|
|
}
|