package com.m2pool.chat.listener;

import com.m2pool.chat.constant.ExceptionEnum;
import com.m2pool.chat.entity.StompPrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

@Component
public class IpLimitListener implements ApplicationListener<IpLimitEvent> {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @Override
    public void onApplicationEvent(IpLimitEvent event) {
        StompPrincipal principal =event.getPrincipal();
//        messagingTemplate.convertAndSendToUser(principal.getName(),
//                Destination.QUEUE + "/" + principal.getName()
//                , "ip链接数限制");

        throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.IP_LIMIT_CONNECT));


    }
}
