|  | @@ -1,60 +1,40 @@
 | 
											
												
													
														|  |  package com.ym.mec.teacher.config;
 |  |  package com.ym.mec.teacher.config;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -import com.ym.mec.teacher.handler.CustomPrincipalHandshakeHandler;
 |  | 
 | 
											
												
													
														|  | -import com.ym.mec.teacher.handler.SoundHandler;
 |  | 
 | 
											
												
													
														|  | -import com.ym.mec.teacher.interceptor.WebSocketChannelInterceptor;
 |  | 
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.teacher.handler.WebSocketHandler;
 | 
											
												
													
														|  |  import com.ym.mec.teacher.interceptor.WebSocketHandshakeInterceptor;
 |  |  import com.ym.mec.teacher.interceptor.WebSocketHandshakeInterceptor;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.context.annotation.Bean;
 | 
											
												
													
														|  |  import org.springframework.context.annotation.Configuration;
 |  |  import org.springframework.context.annotation.Configuration;
 | 
											
												
													
														|  | -import org.springframework.messaging.simp.config.ChannelRegistration;
 |  | 
 | 
											
												
													
														|  | -import org.springframework.messaging.simp.config.MessageBrokerRegistry;
 |  | 
 | 
											
												
													
														|  | -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 org.springframework.web.socket.config.annotation.EnableWebSocket;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
 | 
											
												
													
														|  | 
 |  | +import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
												
													
														|  |   * @Author Joburgess
 |  |   * @Author Joburgess
 | 
											
												
													
														|  |   * @Date 2021/6/8 0008
 |  |   * @Date 2021/6/8 0008
 | 
											
												
													
														|  |   */
 |  |   */
 | 
											
												
													
														|  |  @Configuration
 |  |  @Configuration
 | 
											
												
													
														|  | -@EnableWebSocketMessageBroker
 |  | 
 | 
											
												
													
														|  | -public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
 |  | 
 | 
											
												
													
														|  | 
 |  | +@EnableWebSocket
 | 
											
												
													
														|  | 
 |  | +public class WebSocketConfig implements WebSocketConfigurer {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  | 
 |  | +    private WebSocketHandler webSocketHandler;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  |      private WebSocketHandshakeInterceptor webSocketHandshakeInterceptor;
 |  |      private WebSocketHandshakeInterceptor webSocketHandshakeInterceptor;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  | -    public void registerStompEndpoints(StompEndpointRegistry registry) {
 |  | 
 | 
											
												
													
														|  | -        registry.addEndpoint("/soundWebSocket")
 |  | 
 | 
											
												
													
														|  | -                .addInterceptors(webSocketHandshakeInterceptor)
 |  | 
 | 
											
												
													
														|  | -                .setHandshakeHandler(new CustomPrincipalHandshakeHandler())
 |  | 
 | 
											
												
													
														|  | -                .setAllowedOrigins("*");
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
 | 
											
												
													
														|  | 
 |  | +        webSocketHandlerRegistry.addHandler(webSocketHandler, "/ws")
 | 
											
												
													
														|  | 
 |  | +                .addInterceptors(webSocketHandshakeInterceptor);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    @Override
 |  | 
 | 
											
												
													
														|  | -    public void configureMessageBroker(MessageBrokerRegistry config) {
 |  | 
 | 
											
												
													
														|  | -        // prefix for subscribe
 |  | 
 | 
											
												
													
														|  | -        config.enableSimpleBroker("/topic");
 |  | 
 | 
											
												
													
														|  | -        // prefix for send
 |  | 
 | 
											
												
													
														|  | -        config.setApplicationDestinationPrefixes("/push");
 |  | 
 | 
											
												
													
														|  | 
 |  | +    @Bean
 | 
											
												
													
														|  | 
 |  | +    public ServletServerContainerFactoryBean createWebSocketContainer() {
 | 
											
												
													
														|  | 
 |  | +        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
 | 
											
												
													
														|  | 
 |  | +        container.setMaxTextMessageBufferSize(8192*4);
 | 
											
												
													
														|  | 
 |  | +        container.setMaxBinaryMessageBufferSize(8192*4);
 | 
											
												
													
														|  | 
 |  | +        return container;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    @Override
 |  | 
 | 
											
												
													
														|  | -    public void configureClientInboundChannel(ChannelRegistration registration) {
 |  | 
 | 
											
												
													
														|  | -        /*
 |  | 
 | 
											
												
													
														|  | -         * 配置消息线程池
 |  | 
 | 
											
												
													
														|  | -         * 1、corePoolSize() 配置核心线程池, 当线程数小于此配置时, 不管线程中有无空闲的线程, 都会产生新线程处理任务
 |  | 
 | 
											
												
													
														|  | -         * 2、maxPoolSize() 配置线程池最大数, 当线程池等于此配置时, 不会产生新线程
 |  | 
 | 
											
												
													
														|  | -         * 3、keepAliveSeconds() 线程池维护线程所允许的空闲时间, 单位为秒
 |  | 
 | 
											
												
													
														|  | -         */
 |  | 
 | 
											
												
													
														|  | -        registration.taskExecutor()
 |  | 
 | 
											
												
													
														|  | -                .corePoolSize(10)
 |  | 
 | 
											
												
													
														|  | -                .maxPoolSize(20)
 |  | 
 | 
											
												
													
														|  | -                .keepAliveSeconds(60);
 |  | 
 | 
											
												
													
														|  | -        /*
 |  | 
 | 
											
												
													
														|  | -         * 添加STOMP自定义拦截器
 |  | 
 | 
											
												
													
														|  | -         * 消息拦截器, 实现ChannelInterceptor接口
 |  | 
 | 
											
												
													
														|  | -         */
 |  | 
 | 
											
												
													
														|  | -        registration.interceptors(new WebSocketChannelInterceptor());
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  |  }
 |  |  }
 |