package ink.wgink.module.instantmessage.startup;

import ink.wgink.interfaces.manager.IWebSocketUserSessionManager;
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
import ink.wgink.module.instantmessage.websocket.server.WebSocketServer;
import ink.wgink.properties.websocket.WebSocketProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @ClassName: WebSocketStartUp
 * @Description:
 * @Author: wanggeng
 * @Date: 2021/9/11 10:38 下午
 * @Version: 1.0
 */
@Component
public class WebSocketStartUp implements ApplicationRunner {

    @Autowired
    private WebSocketServer webSocketServer;
    @Autowired
    private WebSocketProperties webSocketProperties;
    @Autowired
    private IWebSocketUserSessionManager webSocketUserSessionManager;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        WebSocketChannelManager webSocketChannelManager = WebSocketChannelManager.getInstance();
        webSocketChannelManager.setWebSocketUserSessionManager(webSocketUserSessionManager);
        webSocketChannelManager.setWebSocketProperties(webSocketProperties);
        new Thread(webSocketServer).start();
    }

}
