content: package com.alibou.whatsappclone.ws;
  
  import com.fasterxml.jackson.databind.ObjectMapper;
  import lombok.RequiredArgsConstructor;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.Ordered;
  import org.springframework.core.annotation.Order;
  import org.springframework.messaging.converter.DefaultContentTypeResolver;
  import org.springframework.messaging.converter.MappingJackson2MessageConverter;
  import org.springframework.messaging.converter.MessageConverter;
  import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
  import org.springframework.messaging.simp.config.MessageBrokerRegistry;
  import org.springframework.security.messaging.context.AuthenticationPrincipalArgumentResolver;
  import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
  import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
  import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
  
  import java.util.List;
  
  import static org.springframework.http.MediaType.APPLICATION_JSON;
  
  @Configuration
  @EnableWebSocketMessageBroker
  @Order(Ordered.HIGHEST_PRECEDENCE + 99)
  @RequiredArgsConstructor
  public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry registry) {
          registry.enableSimpleBroker("/user");
          registry.setApplicationDestinationPrefixes("/app");
          registry.setUserDestinationPrefix("/user");
      }
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry
                  .addEndpoint("/ws")
                  .setAllowedOrigins("http://localhost:4200")
                  .withSockJS();
      }
  
      @Override
      public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
          argumentResolvers.add(new AuthenticationPrincipalArgumentResolver());
      }
  
      @Override
      public boolean configureMessageConverters(List<MessageConverter> messageConverters) {
          DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
          resolver.setDefaultMimeType(APPLICATION_JSON);
          MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
          converter.setObjectMapper(new ObjectMapper());
          converter.setContentTypeResolver(resolver);
          messageConverters.add(converter);
          return false;
      }
  
  }