| OLD | NEW |
| 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview | 7 * @fileoverview |
| 8 * A class that provides an interface to a WCS connection. | 8 * A class that provides an interface to a WCS connection. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
| 15 | 15 |
| 16 (function() { | 16 /** @type {remoting.Wcs} */ |
| 17 remoting.wcs = null; |
| 18 |
| 17 /** | 19 /** |
| 18 * @constructor | 20 * @constructor |
| 19 * | 21 * |
| 20 * @param {remoting.WcsIqClient} wcsIqClient The WCS client. | 22 * @param {remoting.WcsIqClient} wcsIqClient The WCS client. |
| 21 * @param {string} token An OAuth2 access token. | 23 * @param {string} token An OAuth2 access token. |
| 22 * @param {function(): void} onReady A function called when the WCS client has | 24 * @param {function(): void} onReady A function called when the WCS client has |
| 23 * received a full JID. | 25 * received a full JID. |
| 24 * @param {function(function(string): void): void} refreshToken A function | 26 * @param {function(function(string): void): void} refreshToken A function |
| 25 * called when this object wants to see whether an updated access token is | 27 * called when this object wants to see whether an updated access token is |
| 26 * available. The passed function will be called asynchronously with a | 28 * available. The passed function will be called asynchronously with a |
| (...skipping 21 matching lines...) Expand all Loading... |
| 48 */ | 50 */ |
| 49 this.onReady_ = onReady; | 51 this.onReady_ = onReady; |
| 50 | 52 |
| 51 /** | 53 /** |
| 52 * The full JID of the WCS client. | 54 * The full JID of the WCS client. |
| 53 * @type {string} | 55 * @type {string} |
| 54 * @private | 56 * @private |
| 55 */ | 57 */ |
| 56 this.clientFullJid_ = ''; | 58 this.clientFullJid_ = ''; |
| 57 | 59 |
| 60 /** @type {remoting.Wcs} */ |
| 58 var that = this; | 61 var that = this; |
| 59 /** | 62 /** |
| 60 * A timer that polls for an updated access token. | 63 * A timer that polls for an updated access token. |
| 61 * @type {number} | 64 * @type {number} |
| 62 * @private | 65 * @private |
| 63 */ | 66 */ |
| 64 this.pollForUpdatedToken_ = setInterval( | 67 this.pollForUpdatedToken_ = setInterval( |
| 65 function() { refreshToken(that.setToken_); }, | 68 function() { refreshToken(that.setToken_); }, |
| 66 60 * 1000); | 69 60 * 1000); |
| 67 | 70 |
| 68 /** | 71 /** |
| 69 * A function called when an IQ stanza is received. | 72 * A function called when an IQ stanza is received. |
| 70 * @type {function(string): void} | 73 * @param {string} stanza The IQ stanza. |
| 71 * @private | 74 * @private |
| 72 */ | 75 */ |
| 73 this.onIq_ = function(stanza) {}; | 76 this.onIq_ = function(stanza) {}; |
| 74 | 77 |
| 75 // Handle messages from the WcsIqClient. | 78 // Handle messages from the WcsIqClient. |
| 76 this.wcsIqClient_.setOnMessage(function(msg) { that.onMessage_(msg); }); | 79 /** @param {Array.<string>} msg An array of message strings. */ |
| 80 var onMessage = function(msg) { that.onMessage_(msg); }; |
| 81 this.wcsIqClient_.setOnMessage(onMessage); |
| 77 | 82 |
| 78 // Start the WcsIqClient. | 83 // Start the WcsIqClient. |
| 79 this.wcsIqClient_.connectChannel(); | 84 this.wcsIqClient_.connectChannel(); |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 /** | 87 /** |
| 83 * Passes an access token to the WcsIqClient, if the token has been updated. | 88 * Passes an access token to the WcsIqClient, if the token has been updated. |
| 84 * | 89 * |
| 85 * @param {string} tokenNew A (possibly updated) access token. | 90 * @param {string} tokenNew A (possibly updated) access token. |
| 86 * @return {void} Nothing. | 91 * @return {void} Nothing. |
| 87 * @private | 92 * @private |
| 88 */ | 93 */ |
| 89 remoting.Wcs.prototype.setToken_ = function(tokenNew) { | 94 remoting.Wcs.prototype.setToken_ = function(tokenNew) { |
| 90 if (tokenNew != this.token_) { | 95 if (tokenNew != this.token_) { |
| 91 this.token_ = tokenNew; | 96 this.token_ = tokenNew; |
| 92 this.wcsIqClient_.updateAccessToken(this.token_); | 97 this.wcsIqClient_.updateAccessToken(this.token_); |
| 93 } | 98 } |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 /** | 101 /** |
| 97 * Handles a message coming from the WcsIqClient. | 102 * Handles a message coming from the WcsIqClient. |
| 98 * | 103 * |
| 99 * @param {Array} msg The message. | 104 * @param {Array.<string>} msg The message. |
| 100 * @return {void} Nothing. | 105 * @return {void} Nothing. |
| 101 * @private | 106 * @private |
| 102 */ | 107 */ |
| 103 remoting.Wcs.prototype.onMessage_ = function(msg) { | 108 remoting.Wcs.prototype.onMessage_ = function(msg) { |
| 104 if (msg[0] == 'is') { | 109 if (msg[0] == 'is') { |
| 105 this.onIq_(msg[1]); | 110 this.onIq_(msg[1]); |
| 106 } else if (msg[0] == 'cfj') { | 111 } else if (msg[0] == 'cfj') { |
| 107 this.clientFullJid_ = msg[1]; | 112 this.clientFullJid_ = msg[1]; |
| 108 remoting.debug.log('Received JID: ' + this.clientFullJid_); | 113 remoting.debug.log('Received JID: ' + this.clientFullJid_); |
| 109 this.onReady_(); | 114 this.onReady_(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 133 /** | 138 /** |
| 134 * Sets the function called when an IQ stanza is received. | 139 * Sets the function called when an IQ stanza is received. |
| 135 * | 140 * |
| 136 * @param {function(string): void} onIq The function called when an IQ stanza | 141 * @param {function(string): void} onIq The function called when an IQ stanza |
| 137 * is received. | 142 * is received. |
| 138 * @return {void} Nothing. | 143 * @return {void} Nothing. |
| 139 */ | 144 */ |
| 140 remoting.Wcs.prototype.setOnIq = function(onIq) { | 145 remoting.Wcs.prototype.setOnIq = function(onIq) { |
| 141 this.onIq_ = onIq; | 146 this.onIq_ = onIq; |
| 142 }; | 147 }; |
| 143 | |
| 144 }()); | |
| OLD | NEW |