package com.platform.config;

import com.platform.modules.live.constants.SceneConstants;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * @Description: 采用流文本协议，STOMP客户端与任意STOMP消息代理(Broker)进行交
 * @Author: yikaihong
 * @CreateDate: 2019/1/20 16:37
 * @Version: 1.0
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    private final String[] endpoints = new String[]{"/liveWs"};

    private final String[] destinationPrefixes = new String[]{SceneConstants.LIVE_CASTER_SUB_URL};


    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint(endpoints).setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker(destinationPrefixes);
    }


}