Ticket #23216: 23216-small-heartbeat-changes.2.diff
File 23216-small-heartbeat-changes.2.diff, 3.6 KB (added by , 11 years ago) |
---|
-
wp-includes/js/heartbeat.js
40 40 isUserActive, 41 41 userActiveEvents, 42 42 winBlurTimeout, 43 frameBlurTimeout = -1; 43 frameBlurTimeout = -1, 44 hasActiveConnection = true; 44 45 45 this.autostart = true; 46 this.connectionLost = false; 46 /** 47 * If a value is specified, this function will set the internal value of the `hasActiveConnection` setting. 48 * Always returns the value of `hasActiveConnection` 49 * 50 * @param value (optional) 51 * @returns boolean 52 * @private 53 */ 54 this.hasActiveConnection = function( value ) { 55 if ( typeof value === 'boolean' ) { 56 return hasActiveConnection = value; 57 } 47 58 59 return hasActiveConnection; 60 }; 61 48 62 if ( typeof( window.heartbeatSettings ) == 'object' ) { 49 63 settings = $.extend( {}, window.heartbeatSettings ); 50 64 … … 121 135 break; 122 136 } 123 137 124 if ( trigger && ! self.connectionLost) {125 self. connectionLost = true;138 if ( trigger && self.hasActiveConnection() === true ) { 139 self.hasActiveConnection( false ); 126 140 $(document).trigger( 'heartbeat-connection-lost', [error] ); 127 141 } 128 } else if ( self. connectionLost) {142 } else if ( self.hasActiveConnection() === false ) { 129 143 errorcount = 0; 130 self. connectionLost = false;144 self.hasActiveConnection( true ); 131 145 $(document).trigger( 'heartbeat-connection-restored' ); 132 146 } 133 147 } … … 152 166 153 167 // If nothing to send (nothing is expecting a response), 154 168 // schedule the next tick and bail 155 if ( empty && ! self.connectionLost) {169 if ( empty && self.hasActiveConnection() === true ) { 156 170 connecting = false; 157 171 next(); 158 172 return; … … 179 193 return errorstate( 'empty' ); 180 194 181 195 // Clear error state 182 if ( self. connectionLost)196 if ( self.hasActiveConnection() === false ) 183 197 errorstate(); 184 198 185 199 if ( response.nonces_expired ) { … … 205 219 errorstate( textStatus || 'unknown' ); 206 220 self.error( jqXHR, textStatus, error ); 207 221 }); 208 } ;222 } 209 223 210 224 function next() { 211 225 var delta = time() - tick, t = interval; … … 332 346 333 347 // Check for user activity every 30 seconds. 334 348 window.setInterval( function(){ checkUserActive(); }, 30000 ); 349 $(document).ready( function() { 350 // Start one tick (15 sec) after DOM ready 351 running = true; 352 tick = time(); 353 next(); 354 }); 335 355 336 if ( this.autostart ) {337 $(document).ready( function() {338 // Start one tick (15 sec) after DOM ready339 running = true;340 tick = time();341 next();342 });343 }344 345 356 this.hasFocus = function() { 346 357 return hasFocus; 347 } 358 }; 348 359 349 360 /** 350 361 * Get/Set the interval … … 401 412 return tempInterval ? tempInterval / 1000 : interval / 1000; 402 413 }; 403 414 404 // Start. Has no effect if heartbeat is already running405 this.start = function() {406 if ( running )407 return false;408 409 running = true;410 connect();411 return true;412 };413 414 // Stop. If a XHR is in progress, abort it415 this.stop = function() {416 if ( self.xhr && self.xhr.readyState != 4 )417 self.xhr.abort();418 419 // Reset the error state420 errorstate();421 running = false;422 return true;423 }424 425 415 /** 426 416 * Enqueue data to send with the next XHR 427 417 * … … 447 437 return true; 448 438 } 449 439 return false; 450 } 440 }; 451 441 452 442 /** 453 443 * Check if data with a particular handle is queued … … 457 447 */ 458 448 this.isQueued = function( handle ) { 459 449 return queue[handle]; 460 } 461 } 450 }; 451 }; 462 452 463 453 $.extend( Heartbeat.prototype, { 464 454 tick: function( data, textStatus, jqXHR ) {