mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3025 from node-red/comms-batch
Batch messages sent over Comms link
This commit is contained in:
commit
4f18a5f1c3
@ -158,25 +158,31 @@ function CommsConnection(ws, user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommsConnection.prototype.send = function(topic,data) {
|
CommsConnection.prototype.send = function(topic,data) {
|
||||||
var self = this;
|
|
||||||
if (topic && data) {
|
if (topic && data) {
|
||||||
this.stack.push({topic:topic,data:data});
|
this.stack.push({topic:topic,data:data});
|
||||||
}
|
}
|
||||||
|
this._queueSend();
|
||||||
|
}
|
||||||
|
CommsConnection.prototype._queueSend = function() {
|
||||||
|
var self = this;
|
||||||
if (!this._xmitTimer) {
|
if (!this._xmitTimer) {
|
||||||
this._xmitTimer = setTimeout(function() {
|
this._xmitTimer = setTimeout(function() {
|
||||||
try {
|
try {
|
||||||
self.ws.send(JSON.stringify(self.stack));
|
self.ws.send(JSON.stringify(self.stack.splice(0,50)));
|
||||||
self.lastSentTime = Date.now();
|
self.lastSentTime = Date.now();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
removeActiveConnection(self);
|
removeActiveConnection(self);
|
||||||
log.warn(log._("comms.error-send",{message:err.toString()}));
|
log.warn(log._("comms.error-send",{message:err.toString()}));
|
||||||
}
|
}
|
||||||
delete self._xmitTimer;
|
delete self._xmitTimer;
|
||||||
self.stack = [];
|
if (self.stack.length > 0) {
|
||||||
|
self._queueSend();
|
||||||
|
}
|
||||||
},50);
|
},50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CommsConnection.prototype.subscribe = function(topic) {
|
CommsConnection.prototype.subscribe = function(topic) {
|
||||||
runtimeAPI.comms.subscribe({
|
runtimeAPI.comms.subscribe({
|
||||||
user: this.user,
|
user: this.user,
|
||||||
|
Loading…
Reference in New Issue
Block a user