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);
}
}
Aggregations