Search in sources :

Example 1 with ConnectNotExistException

use of org.roof.im.gateway.ConnectNotExistException in project roof-im by madfroglx.

the class WebSocketResponseEndPoint method send.

@Override
public void send(String connectId, Response response) throws IOException, ConnectNotExistException {
    WebSocketSession webSocketSession = webSocketSessionConnectManager.get(connectId);
    if (webSocketSession == null) {
        throw new ConnectNotExistException();
    }
    // if (!webSocketSession.isOpen()) {
    // return;
    // }
    TextMessage textMessage = new TextMessage(JSON.toJSONString(response));
    try {
        webSocketSession.sendMessage(textMessage);
    } catch (Exception e) {
        // 消息推送异常则关闭连接
        WebSocketUtils.tryCloseWithError(webSocketSession, e, LOGGER);
        throw e;
    }
}
Also used : ConnectNotExistException(org.roof.im.gateway.ConnectNotExistException) TextMessage(org.springframework.web.socket.TextMessage) IOException(java.io.IOException) ConnectNotExistException(org.roof.im.gateway.ConnectNotExistException) WebSocketSession(org.springframework.web.socket.WebSocketSession)

Aggregations

IOException (java.io.IOException)1 ConnectNotExistException (org.roof.im.gateway.ConnectNotExistException)1 TextMessage (org.springframework.web.socket.TextMessage)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1