feat(all): send messages as parts
This commit is contained in:
22
dist/nodes/gateway-subdevices/All.js
vendored
22
dist/nodes/gateway-subdevices/All.js
vendored
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
const uniqid = require("uniqid");
|
||||
exports.default = (RED) => {
|
||||
class All {
|
||||
static getOnlyModelsValue(input) {
|
||||
@@ -12,28 +13,35 @@ exports.default = (RED) => {
|
||||
}
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
this.gateway = RED.nodes.getNode(props.gateway);
|
||||
this.gatewayConf = RED.nodes.getNode(props.gateway);
|
||||
this.onlyModels = All.getOnlyModelsValue(props.onlyModels || []);
|
||||
this.excludedSids = props.excludedSids;
|
||||
this.setMessageListener();
|
||||
}
|
||||
setMessageListener() {
|
||||
this.on('input', (msg) => {
|
||||
if (this.gateway) {
|
||||
if (this.gatewayConf) {
|
||||
// Filter input
|
||||
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
||||
if (!this.isDeviceValid(msg.payload)) {
|
||||
if (!this.isDeviceValid(msg.payload.sid)) {
|
||||
msg = null;
|
||||
}
|
||||
this.send(msg);
|
||||
}
|
||||
else {
|
||||
Object.keys(this.gateway.deviceList || {})
|
||||
let partsId = uniqid();
|
||||
Object.keys(this.gatewayConf.deviceList || {})
|
||||
.filter((sid) => this.isDeviceValid(sid))
|
||||
.forEach((sid) => {
|
||||
.forEach((sid, i, subSids) => {
|
||||
let curMsg = Object.assign({}, msg);
|
||||
delete curMsg._msgid;
|
||||
curMsg.parts = {
|
||||
id: partsId,
|
||||
index: i,
|
||||
count: subSids.length,
|
||||
};
|
||||
curMsg.sid = sid;
|
||||
curMsg.gateway = this.gateway;
|
||||
curMsg.gateway = this.gatewayConf;
|
||||
this.send(curMsg);
|
||||
});
|
||||
}
|
||||
@@ -44,7 +52,7 @@ exports.default = (RED) => {
|
||||
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
||||
return true;
|
||||
}
|
||||
let device = this.gateway.deviceList[sid];
|
||||
let device = this.gatewayConf.deviceList[sid];
|
||||
// Is excluded
|
||||
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user