Search in sources :

Example 1 with BinaryPluginWebSocketMsg

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

the class TelemetryWebsocketMsgHandler method handleWebSocketMsg.

@Override
protected void handleWebSocketMsg(PluginContext ctx, PluginWebsocketSessionRef sessionRef, PluginWebsocketMsg<?> wsMsg) {
    try {
        TelemetryPluginCmdsWrapper cmdsWrapper = null;
        if (wsMsg instanceof TextPluginWebSocketMsg) {
            TextPluginWebSocketMsg textMsg = (TextPluginWebSocketMsg) wsMsg;
            cmdsWrapper = jsonMapper.readValue(textMsg.getPayload(), TelemetryPluginCmdsWrapper.class);
        } else if (wsMsg instanceof BinaryPluginWebSocketMsg) {
            throw new IllegalStateException("Not Implemented!");
        // TODO: add support of BSON here based on
        // https://github.com/michel-kraemer/bson4jackson
        }
        if (cmdsWrapper != null) {
            if (cmdsWrapper.getAttrSubCmds() != null) {
                cmdsWrapper.getAttrSubCmds().forEach(cmd -> handleWsAttributesSubscriptionCmd(ctx, sessionRef, cmd));
            }
            if (cmdsWrapper.getTsSubCmds() != null) {
                cmdsWrapper.getTsSubCmds().forEach(cmd -> handleWsTimeseriesSubscriptionCmd(ctx, sessionRef, cmd));
            }
            if (cmdsWrapper.getHistoryCmds() != null) {
                cmdsWrapper.getHistoryCmds().forEach(cmd -> handleWsHistoryCmd(ctx, sessionRef, cmd));
            }
        }
    } catch (IOException e) {
        log.warn("Failed to decode subscription cmd: {}", e.getMessage(), e);
        SubscriptionUpdate update = new SubscriptionUpdate(UNKNOWN_SUBSCRIPTION_ID, SubscriptionErrorCode.INTERNAL_ERROR, SESSION_META_DATA_NOT_FOUND);
        sendWsMsg(ctx, sessionRef, update);
    }
}
Also used : TextPluginWebSocketMsg(org.thingsboard.server.extensions.api.plugins.ws.msg.TextPluginWebSocketMsg) BinaryPluginWebSocketMsg(org.thingsboard.server.extensions.api.plugins.ws.msg.BinaryPluginWebSocketMsg) IOException(java.io.IOException) SubscriptionUpdate(org.thingsboard.server.extensions.core.plugin.telemetry.sub.SubscriptionUpdate)

Aggregations

IOException (java.io.IOException)1 BinaryPluginWebSocketMsg (org.thingsboard.server.extensions.api.plugins.ws.msg.BinaryPluginWebSocketMsg)1 TextPluginWebSocketMsg (org.thingsboard.server.extensions.api.plugins.ws.msg.TextPluginWebSocketMsg)1 SubscriptionUpdate (org.thingsboard.server.extensions.core.plugin.telemetry.sub.SubscriptionUpdate)1