/** 
 | 
 * Copyright (c) 2016-2020 人人开源 All rights reserved. 
 | 
 * <p> 
 | 
 * https://www.renren.io 
 | 
 * <p> 
 | 
 * 版权所有,侵权必究! 
 | 
 */ 
 | 
  
 | 
package com.zt.modules.message.websocket.config; 
 | 
  
 | 
import javax.websocket.HandshakeResponse; 
 | 
import javax.websocket.server.HandshakeRequest; 
 | 
import javax.websocket.server.ServerEndpointConfig; 
 | 
import javax.websocket.server.ServerEndpointConfig.Configurator; 
 | 
  
 | 
import org.springframework.context.annotation.Bean; 
 | 
import org.springframework.context.annotation.Configuration; 
 | 
import org.springframework.web.socket.server.standard.ServerEndpointExporter; 
 | 
  
 | 
import com.zt.common.constant.Constant; 
 | 
import com.zt.core.context.UserContext; 
 | 
  
 | 
/** 
 | 
 * WebSocket配置 
 | 
 * 
 | 
 * @author Mark sunlightcs@gmail.com 
 | 
 */ 
 | 
@Configuration 
 | 
public class WebSocketConfig extends Configurator { 
 | 
    @Bean 
 | 
    public ServerEndpointExporter serverEndpointExporter() { 
 | 
        return new ServerEndpointExporter(); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { 
 | 
        sec.getUserProperties().put(Constant.Field.USER, UserContext.getUserId()); 
 | 
    } 
 | 
  
 | 
} 
 |