summaryrefslogtreecommitdiffstats
path: root/remoting/webapp
diff options
context:
space:
mode:
authorjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-29 20:15:43 +0000
committerjamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-29 20:15:43 +0000
commit763e692c90ec33a5fd7e1b71bcc65f8ce45428ff (patch)
treeaafb5bd95c456a4e7820137fcd2907ccdf4f3719 /remoting/webapp
parent3e16cdf83caa1ed3066ab7d9033b191480331657 (diff)
downloadchromium_src-763e692c90ec33a5fd7e1b71bcc65f8ce45428ff.zip
chromium_src-763e692c90ec33a5fd7e1b71bcc65f8ce45428ff.tar.gz
chromium_src-763e692c90ec33a5fd7e1b71bcc65f8ce45428ff.tar.bz2
Die, |that|, die!
This CL cleans up some uses of the "var that = this" paradigm that can be more elegently and efficiently expressed using the |bind| function. Specifically: var that = this; f(function(x, y, z) { that.g(x, y, z); }); Is equivalent to: f(this.g.bind(this)); The latter is shorter, doesn't need explicit JSDoc type annotation, and is more efficient (though I doubt we'll notice any speed-up). I haven't changed the code to use |bind| where the situation is significantly more complex than the snippet shown above. In theory it would be possible, but I doubt the code would be more readable as a result. BUG=None TEST=Manual Review URL: https://chromiumcodereview.appspot.com/10444041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r--remoting/webapp/client_plugin_async.js5
-rw-r--r--remoting/webapp/client_plugin_v1.js13
-rw-r--r--remoting/webapp/client_session.js90
-rw-r--r--remoting/webapp/connection_history.js5
-rw-r--r--remoting/webapp/host_controller.js5
-rw-r--r--remoting/webapp/host_list.js27
-rw-r--r--remoting/webapp/host_setup_dialog.js1
-rw-r--r--remoting/webapp/host_table_entry.js26
-rw-r--r--remoting/webapp/menu_button.js2
-rw-r--r--remoting/webapp/oauth2.js24
-rw-r--r--remoting/webapp/toolbar.js17
-rw-r--r--remoting/webapp/wcs.js26
12 files changed, 84 insertions, 157 deletions
diff --git a/remoting/webapp/client_plugin_async.js b/remoting/webapp/client_plugin_async.js
index b016e03..4d128b8 100644
--- a/remoting/webapp/client_plugin_async.js
+++ b/remoting/webapp/client_plugin_async.js
@@ -58,10 +58,7 @@ remoting.ClientPluginAsync = function(plugin) {
this.plugin.addEventListener('message', function(event) {
that.handleMessage_(event.data);
}, false);
- var showPluginForClickToPlay = function() {
- that.showPluginForClickToPlay_();
- };
- window.setTimeout(showPluginForClickToPlay, 500);
+ window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500);
};
/**
diff --git a/remoting/webapp/client_plugin_v1.js b/remoting/webapp/client_plugin_v1.js
index 9f9efce..01801e9 100644
--- a/remoting/webapp/client_plugin_v1.js
+++ b/remoting/webapp/client_plugin_v1.js
@@ -40,23 +40,18 @@ remoting.ClientPluginV1 = function(plugin) {
// Connect event handlers.
- /** @type {remoting.ClientPluginV1} */
- var that = this;
-
/** @param {string} iq The IQ stanza to send. */
- this.plugin.sendIq = function(iq) { that.onSendIq_(iq); };
+ this.plugin.sendIq = this.onSendIq_.bind(this);
/** @param {string} msg The message to log. */
- this.plugin.debugInfo = function(msg) { that.onDebugInfo_(msg); };
+ this.plugin.debugInfo = this.onDebugInfo_.bind(this);
/**
* @param {number} status The plugin status.
* @param {number} error The plugin error status, if any.
*/
- this.plugin.connectionInfoUpdate = function(status, error) {
- that.onConnectionInfoUpdate_(status, error);
- };
- this.plugin.desktopSizeUpdate = function() { that.onDesktopSizeUpdate_(); };
+ this.plugin.connectionInfoUpdate = this.onConnectionInfoUpdate_.bind(this);
+ this.plugin.desktopSizeUpdate = this.onDesktopSizeUpdate_.bind(this);
};
/**
diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js
index dfccccd..a25befa 100644
--- a/remoting/webapp/client_session.js
+++ b/remoting/webapp/client_session.js
@@ -60,30 +60,24 @@ remoting.ClientSession = function(hostJid, hostPublicKey, sharedSecret,
this.logToServer = new remoting.LogToServer();
this.onStateChange = onStateChange;
- /** @type {number?} */
+ /** @type {number?} @private */
this.notifyClientDimensionsTimer_ = null;
- /** @type {remoting.ClientSession} */
- var that = this;
- /** @type {function():void} @private */
- this.callPluginLostFocus_ = function() { that.pluginLostFocus_(); };
- /** @type {function():void} @private */
- this.callPluginGotFocus_ = function() { that.pluginGotFocus_(); };
- /** @type {function():void} @private */
- this.callEnableShrink_ = function() {
- that.setScaleToFit(true);
- that.scroll_(0, 0); // Reset bump-scroll offsets.
- };
- /** @type {function():void} @private */
- this.callDisableShrink_ = function() { that.setScaleToFit(false); };
- /** @type {function():void} @private */
- this.callToggleFullScreen_ = function() { that.toggleFullScreen_(); };
- /** @type {remoting.MenuButton} @private */
+ /** @private */
+ this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this);
+ /** @private */
+ this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this);
+ /** @private */
+ this.callEnableShrink_ = this.setScaleToFit.bind(this, true);
+ /** @private */
+ this.callDisableShrink_ = this.setScaleToFit.bind(this, false);
+ /** @private */
+ this.callToggleFullScreen_ = this.toggleFullScreen_.bind(this);
+ /** @private */
this.screenOptionsMenu_ = new remoting.MenuButton(
document.getElementById('screen-options-menu'),
- function() { that.onShowOptionsMenu_(); }
- );
- /** @type {remoting.MenuButton} @private */
+ this.onShowOptionsMenu_.bind(this));
+ /** @private */
this.sendKeysMenu_ = new remoting.MenuButton(
document.getElementById('send-keys-menu')
);
@@ -256,12 +250,9 @@ remoting.ClientSession.prototype.createPluginAndConnect =
this.plugin.element().focus();
- /** @type {remoting.ClientSession} */
- var that = this;
/** @param {boolean} result */
- this.plugin.initialize(function(result) {
- that.onPluginInitialized_(oauth2AccessToken, result);
- });
+ this.plugin.initialize(
+ this.onPluginInitialized_.bind(this, oauth2AccessToken));
this.plugin.element().addEventListener(
'focus', this.callPluginGotFocus_, false);
this.plugin.element().addEventListener(
@@ -311,24 +302,17 @@ remoting.ClientSession.prototype.onPluginInitialized_ =
this.setScaleToFit(this.plugin.hasFeature(
remoting.ClientPlugin.Feature.HIGH_QUALITY_SCALING));
- /** @type {remoting.ClientSession} */ var that = this;
/** @param {string} msg The IQ stanza to send. */
- this.plugin.onOutgoingIqHandler = function(msg) { that.sendIq_(msg); };
+ this.plugin.onOutgoingIqHandler = this.sendIq_.bind(this);
/** @param {string} msg The message to log. */
this.plugin.onDebugMessageHandler = function(msg) {
console.log('plugin: ' + msg);
};
- /**
- * @param {number} status The plugin status.
- * @param {number} error The plugin error status, if any.
- */
- this.plugin.onConnectionStatusUpdateHandler = function(status, error) {
- that.connectionStatusUpdateCallback(status, error);
- };
- this.plugin.onDesktopSizeUpdateHandler = function() {
- that.onDesktopSizeChanged_();
- };
+ this.plugin.onConnectionStatusUpdateHandler =
+ this.connectionStatusUpdateCallback.bind(this);
+ this.plugin.onDesktopSizeUpdateHandler =
+ this.onDesktopSizeChanged_.bind(this);
this.connectPluginToWcs_(oauth2AccessToken);
};
@@ -410,6 +394,10 @@ remoting.ClientSession.prototype.sendCtrlAltDel = function() {
remoting.ClientSession.prototype.setScaleToFit = function(scaleToFit) {
this.scaleToFit = scaleToFit;
this.updateDimensions();
+ // If enabling scaling, reset bump-scroll offsets.
+ if (scaleToFit) {
+ this.scroll_(0, 0);
+ }
}
/**
@@ -480,15 +468,15 @@ remoting.ClientSession.prototype.connectPluginToWcs_ =
console.error('Tried to connect without a full JID.');
}
remoting.formatIq.setJids(this.clientJid, this.hostJid);
- /** @type {remoting.ClientSession} */
- var that = this;
+ var plugin = this.plugin;
+ var forwardIq = plugin.onIncomingIq.bind(plugin);
/** @param {string} stanza The IQ stanza received. */
var onIncomingIq = function(stanza) {
console.log(remoting.formatIq.prettifyReceiveIq(stanza));
- that.plugin.onIncomingIq(stanza);
+ forwardIq(stanza);
}
remoting.wcs.setOnIq(onIncomingIq);
- that.plugin.connect(this.hostJid, this.hostPublicKey, this.clientJid,
+ this.plugin.connect(this.hostJid, this.hostPublicKey, this.clientJid,
this.sharedSecret, this.authenticationMethods,
this.authenticationTag);
};
@@ -540,13 +528,11 @@ remoting.ClientSession.prototype.onResize = function() {
// Defer notifying the host of the change until the window stops resizing, to
// avoid overloading the control channel with notifications.
- /** @type {remoting.ClientSession} */
- var that = this;
- var notifyClientDimensions = function() {
- that.plugin.notifyClientDimensions(window.innerWidth, window.innerHeight);
- }
- this.notifyClientDimensionsTimer_ =
- window.setTimeout(notifyClientDimensions, 1000);
+ this.notifyClientDimensionsTimer_ = window.setTimeout(
+ this.plugin.notifyClientDimensions.bind(this.plugin,
+ window.innerWidth,
+ window.innerHeight),
+ 1000);
// If bump-scrolling is enabled, adjust the plugin margins to fully utilize
// the new window area.
@@ -727,12 +713,8 @@ remoting.ClientSession.prototype.scroll_ = function(dx, dy) {
*/
remoting.ClientSession.prototype.enableBumpScroll_ = function(enable) {
if (enable) {
- /** @type {remoting.ClientSession} */
- var that = this;
- /** @param {Event} event */
- this.onMouseMoveRef_ = function(event) {
- that.onMouseMove_(event);
- }
+ /** @type {null|function(Event):void} */
+ this.onMouseMoveRef_ = this.onMouseMove_.bind(this);
this.plugin.element().addEventListener('mousemove', this.onMouseMoveRef_,
false);
} else {
diff --git a/remoting/webapp/connection_history.js b/remoting/webapp/connection_history.js
index cd4d5a6..da28701 100644
--- a/remoting/webapp/connection_history.js
+++ b/remoting/webapp/connection_history.js
@@ -30,14 +30,13 @@ remoting.ConnectionHistory = function() {
/** @type {remoting.ConnectionHistory} */
var that = this;
var closeButton = document.getElementById('close-connection-history');
- closeButton.addEventListener('click', function() { that.hide(); }, false);
+ closeButton.addEventListener('click', this.hide.bind(this), false);
/** @param {Event} event Event identifying which button was clicked. */
var setFilter = function(event) { that.setFilter_(event.target); };
- var clearHistory = function() { that.clearHistory_(); };
this.viewAll_.addEventListener('click', setFilter, false);
this.viewOutgoing_.addEventListener('click', setFilter, false);
this.viewIncoming_.addEventListener('click', setFilter, false);
- this.clear_.addEventListener('click', clearHistory, false);
+ this.clear_.addEventListener('click', this.clearHistory_.bind(this), false);
};
/** @enum {string} */
diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js
index 364e5c2..2236c63 100644
--- a/remoting/webapp/host_controller.js
+++ b/remoting/webapp/host_controller.js
@@ -116,7 +116,7 @@ remoting.HostController.prototype.setTooltips = function() {
remoting.HostController.prototype.start = function(hostPin, callback) {
/** @type {remoting.HostController} */
var that = this;
- var hostName = that.plugin_.getHostName();
+ var hostName = this.plugin_.getHostName();
/** @return {string} */
function generateUuid() {
@@ -242,8 +242,9 @@ remoting.HostController.prototype.stop = function(callback) {
/** @param {remoting.HostController.AsyncResult} result */
function onStopped(result) {
- if (that.localHost && that.localHost.hostId)
+ if (that.localHost && that.localHost.hostId) {
remoting.HostList.unregisterHostById(that.localHost.hostId);
+ }
callback(result);
};
this.plugin_.stopDaemon(onStopped);
diff --git a/remoting/webapp/host_list.js b/remoting/webapp/host_list.js
index a1bb9814..d997e5b 100644
--- a/remoting/webapp/host_list.js
+++ b/remoting/webapp/host_list.js
@@ -84,12 +84,10 @@ remoting.HostList.prototype.getHostForId = function(hostId) {
* @return {void} Nothing.
*/
remoting.HostList.prototype.refresh = function(onDone) {
+ /** @param {XMLHttpRequest} xhr The response from the server. */
+ var parseHostListResponse = this.parseHostListResponse_.bind(this, onDone);
/** @type {remoting.HostList} */
var that = this;
- /** @param {XMLHttpRequest} xhr The response from the server. */
- var parseHostListResponse = function(xhr) {
- that.parseHostListResponse_(xhr, onDone);
- }
/** @param {string?} token The OAuth2 token. */
var getHosts = function(token) {
if (token) {
@@ -114,12 +112,12 @@ remoting.HostList.prototype.refresh = function(onDone) {
* include a JSON-encoded list of host descriptions, which we display if we're
* able to successfully parse it.
*
- * @param {XMLHttpRequest} xhr The XHR object for the host list request.
* @param {function(boolean):void} onDone The callback passed to |refresh|.
+ * @param {XMLHttpRequest} xhr The XHR object for the host list request.
* @return {void} Nothing.
* @private
*/
-remoting.HostList.prototype.parseHostListResponse_ = function(xhr, onDone) {
+remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) {
try {
if (xhr.status == 200) {
var response =
@@ -177,19 +175,6 @@ remoting.HostList.prototype.display = function(thisHostId) {
this.errorDiv_.innerText = '';
this.hostTableEntries_ = [];
- /**
- * @type {remoting.HostList}
- */
- var that = this;
- /**
- * @param {remoting.HostTableEntry} hostTableEntry The entry being renamed.
- */
- var onRename = function(hostTableEntry) { that.renameHost(hostTableEntry); }
- /**
- * @param {remoting.HostTableEntry} hostTableEntry The entry beign deleted.
- */
- var onDelete = function(hostTableEntry) { that.deleteHost_(hostTableEntry); }
-
this.table_.hidden = (this.hosts_.length == 0);
for (var i = 0; i < this.hosts_.length; ++i) {
@@ -201,7 +186,9 @@ remoting.HostList.prototype.display = function(thisHostId) {
if (host.hostName && host.hostId && host.status && host.publicKey &&
host.hostId != thisHostId) {
var hostTableEntry = new remoting.HostTableEntry();
- hostTableEntry.create(host, onRename, onDelete);
+ hostTableEntry.create(host,
+ this.renameHost.bind(this),
+ this.deleteHost_.bind(this));
this.hostTableEntries_[i] = hostTableEntry;
this.table_.appendChild(hostTableEntry.tableRow);
}
diff --git a/remoting/webapp/host_setup_dialog.js b/remoting/webapp/host_setup_dialog.js
index 01c4947..51c713d 100644
--- a/remoting/webapp/host_setup_dialog.js
+++ b/remoting/webapp/host_setup_dialog.js
@@ -16,7 +16,6 @@ remoting.HostSetupFlow = function(sequence) {
this.sequence_ = sequence;
this.currentStep_ = 0;
this.state_ = sequence[0];
-
this.pin = '';
};
diff --git a/remoting/webapp/host_table_entry.js b/remoting/webapp/host_table_entry.js
index ed1669f..ecda62f 100644
--- a/remoting/webapp/host_table_entry.js
+++ b/remoting/webapp/host_table_entry.js
@@ -181,11 +181,11 @@ remoting.HostTableEntry.prototype.updateStatus = function(opt_forEdit) {
var clickToConnect = this.host.status == 'ONLINE' && !opt_forEdit;
if (clickToConnect) {
if (!this.onConnectReference_) {
- /** @type {remoting.HostTableEntry} */
- var that = this;
+ /** @type {string} */
+ var encodedHostId = encodeURIComponent(this.host.hostId)
this.onConnectReference_ = function() {
var hostUrl = chrome.extension.getURL('main.html') +
- '?mode=me2me&hostId=' + encodeURIComponent(that.host.hostId);
+ '?mode=me2me&hostId=' + encodedHostId;
window.location.assign(hostUrl);
};
this.tableRow.addEventListener('click', this.onConnectReference_, false);
@@ -225,14 +225,10 @@ remoting.HostTableEntry.prototype.beginRename_ = function() {
this.hostNameCell_.appendChild(editBox);
editBox.select();
- /** @type {remoting.HostTableEntry} */
- var that = this;
- this.onBlurReference_ = function() { that.commitRename_(); };
+ this.onBlurReference_ = this.commitRename_.bind(this);
editBox.addEventListener('blur', this.onBlurReference_, false);
- /** @param {Event} event The keydown event. */
- var onKeydown = function(event) { that.onKeydown_(event); }
- editBox.addEventListener('keydown', onKeydown, false);
+ editBox.addEventListener('keydown', this.onKeydown_.bind(this), false);
this.updateStatus(true);
};
@@ -262,12 +258,10 @@ remoting.HostTableEntry.prototype.commitRename_ = function() {
remoting.HostTableEntry.prototype.showDeleteConfirmation_ = function() {
var message = document.getElementById('confirm-host-delete-message');
l10n.localizeElement(message, this.host.hostName);
- /** @type {remoting.HostTableEntry} */
- var that = this;
var confirm = document.getElementById('confirm-host-delete');
var cancel = document.getElementById('cancel-host-delete');
- this.onConfirmDeleteReference_ = function() { that.confirmDelete_(); };
- this.onCancelDeleteReference_ = function() { that.cancelDelete_(); };
+ this.onConfirmDeleteReference_ = this.confirmDelete_.bind(this);
+ this.onCancelDeleteReference_ = this.cancelDelete_.bind(this);
confirm.addEventListener('click', this.onConfirmDeleteReference_, false);
cancel.addEventListener('click', this.onCancelDeleteReference_, false);
remoting.setMode(remoting.AppMode.CONFIRM_HOST_DELETE);
@@ -379,10 +373,8 @@ remoting.HostTableEntry.prototype.onKeydown_ = function(event) {
* @private
*/
remoting.HostTableEntry.prototype.registerFocusHandlers_ = function(e) {
- /** @type {remoting.HostTableEntry} */
- var that = this;
- e.addEventListener('focus', function() { that.onFocusChange_(); }, false);
- e.addEventListener('blur', function() { that.onFocusChange_(); }, false);
+ e.addEventListener('focus', this.onFocusChange_.bind(this), false);
+ e.addEventListener('blur', this.onFocusChange_.bind(this), false);
};
/**
diff --git a/remoting/webapp/menu_button.js b/remoting/webapp/menu_button.js
index 03ad39e..ce0a2ed 100644
--- a/remoting/webapp/menu_button.js
+++ b/remoting/webapp/menu_button.js
@@ -85,7 +85,7 @@ remoting.MenuButton.select = function(item, selected) {
} else {
item.classList.remove('selected');
}
-}
+};
/** @const @private */
remoting.MenuButton.BUTTON_ACTIVE_CLASS_ = 'active';
diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js
index 6f74cbe..6024afc 100644
--- a/remoting/webapp/oauth2.js
+++ b/remoting/webapp/oauth2.js
@@ -201,10 +201,12 @@ remoting.OAuth2.prototype.clearAccessToken = function() {
* Update state based on token response from the OAuth2 /token endpoint.
*
* @private
+ * @param {function(XMLHttpRequest): void} onDone Callback to invoke on
+ * completion.
* @param {XMLHttpRequest} xhr The XHR object for this request.
* @return {void} Nothing.
*/
-remoting.OAuth2.prototype.processTokenResponse_ = function(xhr) {
+remoting.OAuth2.prototype.processTokenResponse_ = function(onDone, xhr) {
if (xhr.status == 200) {
try {
// Don't use jsonParseSafe here unless you move the definition out of
@@ -232,6 +234,7 @@ remoting.OAuth2.prototype.processTokenResponse_ = function(xhr) {
console.error('Failed to get tokens. Status: ' + xhr.status +
' response: ' + xhr.responseText);
}
+ onDone(xhr);
};
/**
@@ -255,15 +258,8 @@ remoting.OAuth2.prototype.refreshAccessToken = function(onDone) {
'grant_type': 'refresh_token'
};
- /** @type {remoting.OAuth2} */
- var that = this;
- /** @param {XMLHttpRequest} xhr The XHR reply. */
- var processTokenResponse = function(xhr) {
- that.processTokenResponse_(xhr);
- onDone(xhr);
- };
remoting.xhr.post(this.OAUTH2_TOKEN_ENDPOINT_,
- processTokenResponse,
+ this.processTokenResponse_.bind(this, onDone),
parameters);
};
@@ -301,16 +297,8 @@ remoting.OAuth2.prototype.exchangeCodeForToken = function(code, onDone) {
'code': code,
'grant_type': 'authorization_code'
};
-
- /** @type {remoting.OAuth2} */
- var that = this;
- /** @param {XMLHttpRequest} xhr The XHR reply. */
- var processTokenResponse = function(xhr) {
- that.processTokenResponse_(xhr);
- onDone(xhr);
- };
remoting.xhr.post(this.OAUTH2_TOKEN_ENDPOINT_,
- processTokenResponse,
+ this.processTokenResponse_.bind(this, onDone),
parameters);
};
diff --git a/remoting/webapp/toolbar.js b/remoting/webapp/toolbar.js
index 0d1288e..31a5f70 100644
--- a/remoting/webapp/toolbar.js
+++ b/remoting/webapp/toolbar.js
@@ -43,13 +43,12 @@ remoting.Toolbar = function(toolbar) {
*/
this.stubRight_ = 0;
- /** @type {remoting.Toolbar} */
- var that = this;
-
window.addEventListener('mousemove', remoting.Toolbar.onMouseMove, false);
- window.addEventListener('resize', function() { that.center(); }, false);
+ window.addEventListener('resize', this.center.bind(this), false);
// Prevent the preview canceling if the user is interacting with the tool-bar.
+ /** @type {remoting.Toolbar} */
+ var that = this;
var stopTimer = function() {
if (that.timerId_) {
window.clearTimeout(that.timerId_);
@@ -69,12 +68,10 @@ remoting.Toolbar.prototype.preview = function() {
window.clearTimeout(this.timerId_);
this.timerId_ = null;
}
- /** @type {remoting.Toolbar} */
- var that = this;
- var endPreview = function() {
- that.toolbar_.classList.remove(remoting.Toolbar.VISIBLE_CLASS_);
- };
- this.timerId_ = window.setTimeout(endPreview, 3000);
+ var classList = this.toolbar_.classList;
+ this.timerId_ = window.setTimeout(
+ classList.remove.bind(classList, remoting.Toolbar.VISIBLE_CLASS_),
+ 3000);
};
/**
diff --git a/remoting/webapp/wcs.js b/remoting/webapp/wcs.js
index 25fbbe0..4906c82 100644
--- a/remoting/webapp/wcs.js
+++ b/remoting/webapp/wcs.js
@@ -52,26 +52,15 @@ remoting.Wcs = function(wcsIqClient, token, onReady) {
*/
this.clientFullJid_ = '';
- /** @type {remoting.Wcs} */
- var that = this;
+ var updateAccessToken = this.updateAccessToken_.bind(this);
+
/**
* A timer that polls for an updated access token.
* @type {number}
* @private
*/
this.pollForUpdatedToken_ = setInterval(
- function() {
- /** @param {string?} token */
- var updateAccessToken = function(token) {
- if (token) {
- that.updateAccessToken_(token);
- } else {
- console.error('pollForUpdatedToken: Authentication failed.');
- // No need to update the token. The hanging GET will fail anyway.
- }
- }
- remoting.oauth2.callWithToken(updateAccessToken);
- },
+ function() { remoting.oauth2.callWithToken(updateAccessToken); },
60 * 1000);
/**
@@ -82,9 +71,7 @@ remoting.Wcs = function(wcsIqClient, token, onReady) {
this.onIq_ = function(stanza) {};
// Handle messages from the WcsIqClient.
- /** @param {Array.<string>} msg An array of message strings. */
- var onMessage = function(msg) { that.onMessage_(msg); };
- this.wcsIqClient_.setOnMessage(onMessage);
+ this.wcsIqClient_.setOnMessage(this.onMessage_.bind(this));
// Start the WcsIqClient.
this.wcsIqClient_.connectChannel();
@@ -98,7 +85,10 @@ remoting.Wcs = function(wcsIqClient, token, onReady) {
* @private
*/
remoting.Wcs.prototype.updateAccessToken_ = function(tokenNew) {
- if (tokenNew != this.token_) {
+ if (!tokenNew) {
+ console.error('updateAccessToken_: Authentication failed.');
+ // No need to update the token. The hanging GET will fail anyway.
+ } else if (tokenNew != this.token_) {
this.token_ = tokenNew;
this.wcsIqClient_.updateAccessToken(this.token_);
}