//package com.red.circle.game.fruit.infrastructure.websocket.config;
//
//import com.red.circle.tool.core.text.StringUtils;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.MessageChannel;
//import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
//import org.springframework.messaging.support.ChannelInterceptor;
//import org.springframework.messaging.support.MessageHeaderAccessor;
//
///**
// * 通道监听器.
// *
// * @author pengliang on 2021/7/22
// */
//public class CustomizeChannelInterceptor implements ChannelInterceptor {
//
//  @Override
//  public Message<?> preSend(Message<?> message, MessageChannel channel) {
//    StompHeaderAccessor accessor = MessageHeaderAccessor
//        .getAccessor(message, StompHeaderAccessor.class);
//
//    String user = getNativeHeaders(message,"req-user");
//    if (Objects.nonNull(accessor) && StringUtils.isNotBlank(user)) {
//      accessor.setUser(() -> user);
//    }
//
//    return message;
//  }
//
//  private String getNativeHeaders(Message<?> message, String key) {
//    Map<String, Object> headers = (Map<String, Object>) message.getHeaders().get("nativeHeaders");
//    if (headers != null && headers.containsKey(key)) {
//      List<String> token = (List<String>) headers.get(key);
//      return String.valueOf(token.get(0));
//    }
//    return null;
//  }
//
//}
