| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * XmppLoginHandler handles authentication handshake for XmppConnection. It | 11 * XmppLoginHandler handles authentication handshake for XmppConnection. It |
| 12 * receives incoming data using onDataReceived(), calls |sendMessageCallback| | 12 * receives incoming data using onDataReceived(), calls |sendMessageCallback| |
| 13 * to send outgoing messages and calls |onHandshakeDoneCallback| after | 13 * to send outgoing messages and calls |onHandshakeDoneCallback| after |
| 14 * authentication is finished successfully or |onErrorCallback| on error. | 14 * authentication is finished successfully or |onErrorCallback| on error. |
| 15 * | 15 * |
| 16 * See RFC3920 for description of XMPP and authentication handshake. | 16 * See RFC3920 for description of XMPP and authentication handshake. |
| 17 * | 17 * |
| 18 * @param {string} server Domain name of the server we are connecting to. | 18 * @param {string} server Domain name of the server we are connecting to. |
| 19 * @param {string} username Username. | 19 * @param {string} username Username. |
| 20 * @param {string} authToken OAuth2 token. | 20 * @param {string} authToken OAuth2 token. |
| 21 * @param {boolean} needHandshakeBeforeTls Set to true when <starttls> handshake | 21 * @param {boolean} needHandshakeBeforeTls Set to true when <starttls> handshake |
| 22 * is required before starting TLS. Otherwise TLS can be started right away. | 22 * is required before starting TLS. Otherwise TLS can be started right away. |
| 23 * @param {function(string):void} sendMessageCallback Callback to call to send | 23 * @param {function(string):void} sendMessageCallback Callback to call to send |
| 24 * a message. | 24 * a message. |
| 25 * @param {function():void} startTlsCallback Callback to call to start TLS on | 25 * @param {function():void} startTlsCallback Callback to call to start TLS on |
| 26 * the underlying socket. | 26 * the underlying socket. |
| 27 * @param {function(string, remoting.XmppStreamParser):void} | 27 * @param {function(string, remoting.XmppStreamParser):void} |
| 28 * onHandshakeDoneCallback Callback to call after authentication is | 28 * onHandshakeDoneCallback Callback to call after authentication is |
| 29 * completed successfully | 29 * completed successfully |
| 30 * @param {function(remoting.Error, string):void} onErrorCallback Callback to | 30 * @param {function(!remoting.Error, string):void} onErrorCallback Callback to |
| 31 * call on error. Can be called at any point during lifetime of connection. | 31 * call on error. Can be called at any point during lifetime of connection. |
| 32 * @constructor | 32 * @constructor |
| 33 */ | 33 */ |
| 34 remoting.XmppLoginHandler = function(server, | 34 remoting.XmppLoginHandler = function(server, |
| 35 username, | 35 username, |
| 36 authToken, | 36 authToken, |
| 37 needHandshakeBeforeTls, | 37 needHandshakeBeforeTls, |
| 38 sendMessageCallback, | 38 sendMessageCallback, |
| 39 startTlsCallback, | 39 startTlsCallback, |
| 40 onHandshakeDoneCallback, | 40 onHandshakeDoneCallback, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 this.sendMessageCallback_('<stream:stream to="' + this.server_ + | 268 this.sendMessageCallback_('<stream:stream to="' + this.server_ + |
| 269 '" version="1.0" xmlns="jabber:client" ' + | 269 '" version="1.0" xmlns="jabber:client" ' + |
| 270 'xmlns:stream="http://etherx.jabber.org/streams">' + | 270 'xmlns:stream="http://etherx.jabber.org/streams">' + |
| 271 firstMessage); | 271 firstMessage); |
| 272 this.streamParser_ = new remoting.XmppStreamParser(); | 272 this.streamParser_ = new remoting.XmppStreamParser(); |
| 273 this.streamParser_.setCallbacks(this.onStanza_.bind(this), | 273 this.streamParser_.setCallbacks(this.onStanza_.bind(this), |
| 274 this.onParserError_.bind(this)); | 274 this.onParserError_.bind(this)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * @param {remoting.Error} error | 278 * @param {!remoting.Error} error |
| 279 * @param {string} text | 279 * @param {string} text |
| 280 * @private | 280 * @private |
| 281 */ | 281 */ |
| 282 remoting.XmppLoginHandler.prototype.onError_ = function(error, text) { | 282 remoting.XmppLoginHandler.prototype.onError_ = function(error, text) { |
| 283 if (this.state_ != remoting.XmppLoginHandler.State.ERROR) { | 283 if (this.state_ != remoting.XmppLoginHandler.State.ERROR) { |
| 284 this.onErrorCallback_(error, text); | 284 this.onErrorCallback_(error, text); |
| 285 this.state_ = remoting.XmppLoginHandler.State.ERROR; | 285 this.state_ = remoting.XmppLoginHandler.State.ERROR; |
| 286 } else { | 286 } else { |
| 287 console.error(text); | 287 console.error(text); |
| 288 } | 288 } |
| 289 } | 289 } |
| OLD | NEW |