UI: Improve WS publishing of subscription commands.

This commit is contained in:
Igor Kulikov 2018-01-03 18:37:28 +02:00
parent 627c7bd1bc
commit bd4b0d78c3
2 changed files with 32 additions and 9 deletions

View File

@ -47,8 +47,8 @@ public class WebSocketConfiguration implements WebSocketConfigurer {
@Bean @Bean
public ServletServerContainerFactoryBean createWebSocketContainer() { public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(8192); container.setMaxTextMessageBufferSize(32768);
container.setMaxBinaryMessageBufferSize(8192); container.setMaxBinaryMessageBufferSize(32768);
return container; return container;
} }

View File

@ -23,6 +23,8 @@ export default angular.module('thingsboard.api.telemetryWebsocket', [thingsboard
const RECONNECT_INTERVAL = 2000; const RECONNECT_INTERVAL = 2000;
const WS_IDLE_TIMEOUT = 90000; const WS_IDLE_TIMEOUT = 90000;
const MAX_PUBLISH_COMMANDS = 10;
/*@ngInject*/ /*@ngInject*/
function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, types, userService) { function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, types, userService) {
@ -75,19 +77,40 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty
return service; return service;
function publishCommands () { function publishCommands () {
if (isOpened && (cmdsWrapper.tsSubCmds.length > 0 || while(isOpened && hasCommands()) {
cmdsWrapper.historyCmds.length > 0 || dataStream.send(preparePublishCommands()).then(function () {
cmdsWrapper.attrSubCmds.length > 0)) {
dataStream.send(angular.copy(cmdsWrapper)).then(function () {
checkToClose(); checkToClose();
}); });
cmdsWrapper.tsSubCmds = [];
cmdsWrapper.historyCmds = [];
cmdsWrapper.attrSubCmds = [];
} }
tryOpenSocket(); tryOpenSocket();
} }
function hasCommands() {
return cmdsWrapper.tsSubCmds.length > 0 ||
cmdsWrapper.historyCmds.length > 0 ||
cmdsWrapper.attrSubCmds.length > 0;
}
function preparePublishCommands() {
var preparedWrapper = {};
var leftCount = MAX_PUBLISH_COMMANDS;
preparedWrapper.tsSubCmds = popCmds(cmdsWrapper.tsSubCmds, leftCount);
leftCount -= preparedWrapper.tsSubCmds.length;
preparedWrapper.historyCmds = popCmds(cmdsWrapper.historyCmds, leftCount);
leftCount -= preparedWrapper.historyCmds.length;
preparedWrapper.attrSubCmds = popCmds(cmdsWrapper.attrSubCmds, leftCount);
return preparedWrapper;
}
function popCmds(cmds, leftCount) {
var toPublish = Math.min(cmds.length, leftCount);
if (toPublish > 0) {
return cmds.splice(0, toPublish);
} else {
return [];
}
}
function onError (/*message*/) { function onError (/*message*/) {
isOpening = false; isOpening = false;
} }