| Index: remoting/webapp/crd/js/fallback_signal_strategy.js
|
| diff --git a/remoting/webapp/crd/js/fallback_signal_strategy.js b/remoting/webapp/crd/js/fallback_signal_strategy.js
|
| index bb58e4d45ae63da3adcf558a4581b61009ffb3bd..a8926034d160488eb7d8b06faf0677359129d74d 100644
|
| --- a/remoting/webapp/crd/js/fallback_signal_strategy.js
|
| +++ b/remoting/webapp/crd/js/fallback_signal_strategy.js
|
| @@ -19,15 +19,12 @@ var remoting = remoting || {};
|
| * function(remoting.SignalStrategy.State)
|
| * ):remoting.SignalStrategy} secondaryFactory
|
| * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
|
| - * @param {function(remoting.FallbackSignalStrategy.Progress)}
|
| - * onProgressCallback
|
| *
|
| * @implements {remoting.SignalStrategy}
|
| * @constructor
|
| */
|
| remoting.FallbackSignalStrategy = function(
|
| - primaryFactory, secondaryFactory,
|
| - onStateChangedCallback, onProgressCallback) {
|
| + primaryFactory, secondaryFactory, onStateChangedCallback) {
|
| /**
|
| * @type {remoting.SignalStrategy}
|
| * @private
|
| @@ -47,12 +44,6 @@ remoting.FallbackSignalStrategy = function(
|
| this.onStateChangedCallback_ = onStateChangedCallback;
|
|
|
| /**
|
| - * @type {function(remoting.FallbackSignalStrategy.Progress)}
|
| - * @private
|
| - */
|
| - this.onProgressCallback_ = onProgressCallback;
|
| -
|
| - /**
|
| * @type {?function(Element):void}
|
| * @private
|
| */
|
| @@ -114,6 +105,24 @@ remoting.FallbackSignalStrategy = function(
|
| * @private
|
| */
|
| this.primaryConnectTimerId_ = 0;
|
| +
|
| + /**
|
| + * @type {remoting.LogToServer}
|
| + * @private
|
| + */
|
| + this.logToServer_ = null;
|
| +
|
| + /**
|
| + * @type {Array.<{progress: remoting.FallbackSignalStrategy.Progress,
|
| + * elapsed: number}>}
|
| + */
|
| + this.connectionSetupResults_ = [];
|
| +
|
| + /**
|
| + * @type {number}
|
| + * @private
|
| + */
|
| + this.startTime_ = 0;
|
| };
|
|
|
| /**
|
| @@ -162,6 +171,7 @@ remoting.FallbackSignalStrategy.prototype.connect =
|
| this.username_ = username;
|
| this.authToken_ = authToken;
|
| this.state_ = this.State.PRIMARY_PENDING;
|
| + this.startTime_ = new Date().getTime();
|
| this.primary_.setIncomingStanzaCallback(this.onIncomingStanzaCallback_);
|
| this.primary_.connect(server, username, authToken);
|
| this.primaryConnectTimerId_ =
|
| @@ -177,6 +187,28 @@ remoting.FallbackSignalStrategy.prototype.sendMessage = function(message) {
|
| this.getConnectedSignalStrategy_().sendMessage(message);
|
| };
|
|
|
| +/**
|
| + * Send any messages accumulated during connection set-up.
|
| + *
|
| + * @param {remoting.LogToServer} logToServer The LogToServer instance for the
|
| + * connection.
|
| + */
|
| +remoting.FallbackSignalStrategy.prototype.sendConnectionSetupResults =
|
| + function(logToServer) {
|
| + this.logToServer_ = logToServer;
|
| + this.sendConnectionSetupResultsInternal_();
|
| +}
|
| +
|
| +remoting.FallbackSignalStrategy.prototype.sendConnectionSetupResultsInternal_ =
|
| + function() {
|
| + for (var i = 0; i < this.connectionSetupResults_.length; ++i) {
|
| + var result = this.connectionSetupResults_[i];
|
| + this.logToServer_.logSignalStrategyProgress(result.progress,
|
| + result.elapsed);
|
| + }
|
| + this.connectionSetupResults_ = [];
|
| +};
|
| +
|
| /** @return {remoting.SignalStrategy.State} Current state */
|
| remoting.FallbackSignalStrategy.prototype.getState = function() {
|
| return (this.externalState_ === null)
|
| @@ -230,11 +262,11 @@ remoting.FallbackSignalStrategy.prototype.onPrimaryStateChanged_ =
|
| case remoting.SignalStrategy.State.CONNECTED:
|
| if (this.state_ == this.State.PRIMARY_PENDING) {
|
| window.clearTimeout(this.primaryConnectTimerId_);
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.PRIMARY_SUCCEEDED);
|
| this.state_ = this.State.PRIMARY_SUCCEEDED;
|
| } else {
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.PRIMARY_SUCCEEDED_LATE);
|
| }
|
| break;
|
| @@ -242,11 +274,11 @@ remoting.FallbackSignalStrategy.prototype.onPrimaryStateChanged_ =
|
| case remoting.SignalStrategy.State.FAILED:
|
| if (this.state_ == this.State.PRIMARY_PENDING) {
|
| window.clearTimeout(this.primaryConnectTimerId_);
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.PRIMARY_FAILED);
|
| this.connectSecondary_();
|
| } else {
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.PRIMARY_FAILED_LATE);
|
| }
|
| return; // Don't notify the external callback
|
| @@ -267,13 +299,13 @@ remoting.FallbackSignalStrategy.prototype.onSecondaryStateChanged_ =
|
| function(state) {
|
| switch (state) {
|
| case remoting.SignalStrategy.State.CONNECTED:
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.SECONDARY_SUCCEEDED);
|
| this.state_ = this.State.SECONDARY_SUCCEEDED;
|
| break;
|
|
|
| case remoting.SignalStrategy.State.FAILED:
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.SECONDARY_FAILED);
|
| this.state_ = this.State.SECONDARY_FAILED;
|
| break;
|
| @@ -323,7 +355,22 @@ remoting.FallbackSignalStrategy.prototype.connectSecondary_ = function() {
|
| * @private
|
| */
|
| remoting.FallbackSignalStrategy.prototype.onPrimaryTimeout_ = function() {
|
| - this.onProgressCallback_(
|
| + this.updateProgress_(
|
| remoting.FallbackSignalStrategy.Progress.PRIMARY_TIMED_OUT);
|
| this.connectSecondary_();
|
| };
|
| +
|
| +/**
|
| + * @param {remoting.FallbackSignalStrategy.Progress} progress
|
| + * @private
|
| + */
|
| +remoting.FallbackSignalStrategy.prototype.updateProgress_ = function(progress) {
|
| + console.log('FallbackSignalStrategy progress: ' + progress);
|
| + this.connectionSetupResults_.push({
|
| + 'progress': progress,
|
| + 'elapsed': new Date().getTime() - this.startTime_
|
| + });
|
| + if (this.logToServer_) {
|
| + this.sendConnectionSetupResultsInternal_();
|
| + }
|
| +};
|
|
|