Search in sources :

Example 1 with SessionEventPluginWebSocketMsg

use of org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg in project thingsboard by thingsboard.

the class PluginWebSocketHandler method afterConnectionClosed.

@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
    super.afterConnectionClosed(session, closeStatus);
    SessionMetaData sessionMd = internalSessionMap.remove(session.getId());
    if (sessionMd != null) {
        externalSessionMap.remove(sessionMd.sessionRef.getSessionId());
        processInActorService(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onClosed()));
    }
    log.info("[{}] Session is closed", session.getId());
}
Also used : SessionEventPluginWebSocketMsg(org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg)

Example 2 with SessionEventPluginWebSocketMsg

use of org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg in project thingsboard by thingsboard.

the class PluginWebSocketHandler method afterConnectionEstablished.

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    super.afterConnectionEstablished(session);
    try {
        String internalSessionId = session.getId();
        PluginWebsocketSessionRef sessionRef = toRef(session);
        String externalSessionId = sessionRef.getSessionId();
        internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef));
        externalSessionMap.put(externalSessionId, internalSessionId);
        actorService.process(new SessionEventPluginWebSocketMsg(sessionRef, SessionEvent.onEstablished()));
        log.info("[{}][{}] Session is started", externalSessionId, session.getId());
    } catch (InvalidParameterException e) {
        log.warn("[[{}] Failed to start session", session.getId(), e);
        session.close(CloseStatus.BAD_DATA.withReason(e.getMessage()));
    } catch (Exception e) {
        log.warn("[{}] Failed to start session", session.getId(), e);
        session.close(CloseStatus.SERVER_ERROR.withReason(e.getMessage()));
    }
}
Also used : SessionEventPluginWebSocketMsg(org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg) InvalidParameterException(java.security.InvalidParameterException) PluginWebsocketSessionRef(org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef) BasicPluginWebsocketSessionRef(org.thingsboard.server.extensions.api.plugins.ws.BasicPluginWebsocketSessionRef) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException)

Example 3 with SessionEventPluginWebSocketMsg

use of org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg in project thingsboard by thingsboard.

the class PluginWebSocketHandler method handleTransportError.

@Override
public void handleTransportError(WebSocketSession session, Throwable tError) throws Exception {
    super.handleTransportError(session, tError);
    SessionMetaData sessionMd = internalSessionMap.get(session.getId());
    if (sessionMd != null) {
        processInActorService(new SessionEventPluginWebSocketMsg(sessionMd.sessionRef, SessionEvent.onError(tError)));
    } else {
        log.warn("[{}] Failed to find session", session.getId());
    }
    log.trace("[{}] Session transport error", session.getId(), tError);
}
Also used : SessionEventPluginWebSocketMsg(org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg)

Aggregations

SessionEventPluginWebSocketMsg (org.thingsboard.server.extensions.api.plugins.ws.msg.SessionEventPluginWebSocketMsg)3 IOException (java.io.IOException)1 InvalidParameterException (java.security.InvalidParameterException)1 BeanCreationNotAllowedException (org.springframework.beans.factory.BeanCreationNotAllowedException)1 BasicPluginWebsocketSessionRef (org.thingsboard.server.extensions.api.plugins.ws.BasicPluginWebsocketSessionRef)1 PluginWebsocketSessionRef (org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef)1