package com.njzscloud.common.mvc.ws.util;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.messaging.simp.SimpMessagingTemplate;

public class WsUtil {
    private static final SimpMessagingTemplate SIMP_MESSAGING_TEMPLATE;

    static {
        SIMP_MESSAGING_TEMPLATE = SpringUtil.getBean(SimpMessagingTemplate.class);
    }

    /**
     * 对单发送信息
     *
     * @param userId      用户 Id
     * @param destination 事件
     * @param message     消息内容
     */
    public static void send(long userId, String destination, Object message) {
        SIMP_MESSAGING_TEMPLATE.convertAndSendToUser(userId + "", destination, message);
    }

    /**
     * 对群发送信息
     *
     * @param destination 事件
     * @param message     消息内容
     */
    public static void send(String destination, Object message) {
        SIMP_MESSAGING_TEMPLATE.convertAndSend(destination, message);
    }
}
