//package com.red.circle.game.fruit.infrastructure.websocket.config;//package com.sugartime.app.websocket.config;
//
//import com.red.circle.game.fruit.infrastructure.websocket.message.MessageSender;
//import com.red.circle.game.fruit.infrastructure.websocket.message.ResultMessage;
//import com.red.circle.game.fruit.infrastructure.websocket.message.SocketMessageBody;
//import com.red.circle.game.fruit.infrastructure.websocket.message.SocketMessageType;
//import java.util.Map;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.web.socket.CloseStatus;
//import org.springframework.web.socket.WebSocketHandler;
//import org.springframework.web.socket.WebSocketSession;
//import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
//import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
//
///**
// * 服务端和客户端在进行握手挥手时会被执行.
// *
// * @author pengliang on 2021/7/29
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class WebSocketDecoratorFactory implements WebSocketHandlerDecoratorFactory {
//
//  private final MessageSender messageSender;
//
//  @Override
//  public WebSocketHandler decorate(WebSocketHandler handler) {
//    return new WebSocketHandlerDecorator(handler) {
//      @Override
//      public void afterConnectionEstablished(WebSocketSession session) throws Exception {
//        super.afterConnectionEstablished(session);
//      }
//
//      @Override
//      public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)
//          throws Exception {
//        Map<String, Object> stringObjectMap = session.getAttributes();
//        messageSender.send(SocketMessageBody.builder()
//            .msgId("CLOSE_".concat(session.getId()))
//            .content(getResultMessage(session, closeStatus, stringObjectMap))
//            .destination(String.valueOf(stringObjectMap.get(SocketConstant.DESTINATION)))
//            .build());
//        super.afterConnectionClosed(session, closeStatus);
//      }
//
//      private String getResultMessage(WebSocketSession session, CloseStatus closeStatus,
//          Map<String, Object> stringObjectMap) {
//        return  ResultMessage.builder()
//            .type(SocketMessageType.CONNECT_CLOSE)
//            .message("[" + session.getId() + "]Socket connect close " + closeStatus)
//            .body(stringObjectMap.get(SocketConstant.USER_ID))
//            .build()
//            .toJson();
//      }
//    };
//  }
//}
