package ink.wgink.module.instantmessage.controller.route;

import ink.wgink.common.component.SecurityComponent;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.properties.websocket.WebSocketProperties;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: WebSocketDemoStaticController
 * @Description: websocket示例资源
 * @Author: wanggeng
 * @Date: 2021/9/13 11:08 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户路由接口")
@Controller
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/websocket")
public class WebSocketDemoRouteController {

    @Autowired
    private SecurityComponent securityComponent;
    @Autowired
    private WebSocketProperties webSocketProperties;

    @GetMapping("chat-demo")
    public ModelAndView chatDemo() {
        ModelAndView modelAndView = new ModelAndView("chat-demo");
        modelAndView.addObject("currentUserId", securityComponent.getCurrentUser().getUserId());
        modelAndView.addObject("webSocketUrl", String.format("%s:%s/%s", webSocketProperties.getUrl(), webSocketProperties.getPort(), webSocketProperties.getContext()));
        return modelAndView;
    }

}
