@@ -2496,7 +2496,7 @@ Paho.MQTT = (function (global) {
24962496} ) ( window ) ;
24972497
24982498var webduino = webduino || {
2499- version : '0.5.4 '
2499+ version : '0.6.0 '
25002500} ;
25012501
25022502if ( typeof exports !== 'undefined' ) {
@@ -4118,6 +4118,8 @@ if (typeof exports !== 'undefined') {
41184118 this . _transport = null ;
41194119 this . _pinStateEventCenter = new EventEmitter ( ) ;
41204120 this . _logger = new Logger ( 'Board' ) ;
4121+ this . _sendingInterval = 0 ;
4122+ this . _sendingRec = [ ] ;
41214123
41224124 this . _initialVersionResultHandler = onInitialVersionResult . bind ( this ) ;
41234125 this . _openHandler = onOpen . bind ( this ) ;
@@ -4233,6 +4235,16 @@ if (typeof exports !== 'undefined') {
42334235 }
42344236 } ,
42354237
4238+ sendingInterval : {
4239+ get : function ( ) {
4240+ return this . _sendingInterval ;
4241+ } ,
4242+ set : function ( interval ) {
4243+ if ( typeof interval !== 'number' ) return ;
4244+ this . _sendingInterval = interval < 0 ? 0 : interval ;
4245+ }
4246+ } ,
4247+
42364248 isReady : {
42374249 get : function ( ) {
42384250 return this . _isReady ;
@@ -4887,7 +4899,24 @@ if (typeof exports !== 'undefined') {
48874899 } ;
48884900
48894901 proto . send = function ( data ) {
4890- this . isConnected && this . _transport . send ( data ) ;
4902+ if ( ! this . isConnected ) return ;
4903+ if ( this . sendingInterval === 0 ) {
4904+ this . _transport . send ( data ) ;
4905+ return ;
4906+ }
4907+
4908+ var idx = this . _sendingRec . findIndex ( function ( val ) {
4909+ return val . value . toString ( ) === data . toString ( ) ;
4910+ } ) ;
4911+ if ( idx !== - 1 ) {
4912+ if ( Date . now ( ) - this . _sendingRec [ idx ] . timestamp < this . sendingInterval ) return ;
4913+ this . _sendingRec . splice ( idx , 1 ) ;
4914+ }
4915+ this . _sendingRec . push ( {
4916+ value : data . slice ( ) ,
4917+ timestamp : Date . now ( )
4918+ } ) ;
4919+ this . _transport . send ( data ) ;
48914920 } ;
48924921
48934922 proto . close = function ( callback ) {
0 commit comments