Combined our two post-connect functions into one, so we make less HTTP calls.

This commit is contained in:
Ian Gulliver
2014-05-27 16:32:59 -07:00
parent 6d6950624f
commit 4427af1505

View File

@@ -676,8 +676,6 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) {
return;
}
this.flushRPCQueue_();
// Handle events that were immediately available as if they came over the
// channel. Fire them before the message callbacks, so clients can use
// events like the subscribe promise fulfillment as a barrier for initial
@@ -727,28 +725,19 @@ Cosmopolite.prototype.maySendRPC_ = function() {
return true;
}
/**
* Send queued RPCs
*
* @private
*/
Cosmopolite.prototype.flushRPCQueue_ = function() {
if (!this.maySendRPC_() || !this.rpcQueue_.length) {
return;
}
this.sendRPCs_(this.rpcQueue_);
this.rpcQueue_ = [];
};
/**
* Handle tasks needed after reconnecting the channel
*
* @private
*/
Cosmopolite.prototype.onReconnect_ = function() {
if (!this.maySendRPC_()) {
return;
}
/** @type {Array.<typeRPC>} */
var rpcs = [];
var rpcs = this.rpcQueue_;
this.rpcQueue_ = [];
for (var subject in this.subscriptions_) {
/** @type {typeSubscription} */
var subscription = this.subscriptions_[subject];
@@ -856,7 +845,6 @@ Cosmopolite.prototype.onSocketOpen_ = function() {
return;
}
this.flushRPCQueue_();
this.onReconnect_();
};