package com.mosty.websocket.service.impl;

import com.mosty.base.model.dto.websocket.WebSocketObject;
import com.mosty.common.base.exception.BusinessException;
import com.mosty.websocket.config.WebSocketServer;
import com.mosty.websocket.service.WebSocketService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

@Service
public class WebSocketServiceImpl implements WebSocketService {

    @Resource
    private WebSocketServer webSocketServer;

    @Override
    public void sendInfo(WebSocketObject obj) {
        try {
            WebSocketServer.sendInfo(obj);
        } catch (IOException e) {
            e.printStackTrace();
            throw new BusinessException("消息推送失败！！");
        }
    }

    @Override
    public void sendBbMessage(WebSocketObject obj) {
        try {
            webSocketServer.sendBbMessage(obj);
        } catch (IOException e) {
            e.printStackTrace();
            throw new BusinessException("向用户发送报备数据！！");
        }
    }
}
