Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: remoting/webapp/crd/js/xmpp_connection.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/wcs_loader.js ('k') | remoting/webapp/crd/js/xmpp_login_handler.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /**
(...skipping 21 matching lines...) Expand all
32 this.startTlsPending_ = false; 32 this.startTlsPending_ = false;
33 /** @private {Array<ArrayBuffer>} */ 33 /** @private {Array<ArrayBuffer>} */
34 this.sendQueue_ = []; 34 this.sendQueue_ = [];
35 /** @private {remoting.XmppLoginHandler} */ 35 /** @private {remoting.XmppLoginHandler} */
36 this.loginHandler_ = null; 36 this.loginHandler_ = null;
37 /** @private {remoting.XmppStreamParser} */ 37 /** @private {remoting.XmppStreamParser} */
38 this.streamParser_ = null; 38 this.streamParser_ = null;
39 /** @private */ 39 /** @private */
40 this.jid_ = ''; 40 this.jid_ = '';
41 /** @private */ 41 /** @private */
42 this.error_ = remoting.Error.NONE; 42 this.error_ = remoting.Error.none();
43 }; 43 };
44 44
45 /** 45 /**
46 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback 46 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
47 */ 47 */
48 remoting.XmppConnection.prototype.setStateChangedCallback = function( 48 remoting.XmppConnection.prototype.setStateChangedCallback = function(
49 onStateChangedCallback) { 49 onStateChangedCallback) {
50 this.onStateChangedCallback_ = onStateChangedCallback; 50 this.onStateChangedCallback_ = onStateChangedCallback;
51 }; 51 };
52 52
(...skipping 14 matching lines...) Expand all
67 /** 67 /**
68 * @param {string} server 68 * @param {string} server
69 * @param {string} username 69 * @param {string} username
70 * @param {string} authToken 70 * @param {string} authToken
71 */ 71 */
72 remoting.XmppConnection.prototype.connect = 72 remoting.XmppConnection.prototype.connect =
73 function(server, username, authToken) { 73 function(server, username, authToken) {
74 base.debug.assert(this.state_ == remoting.SignalStrategy.State.NOT_CONNECTED); 74 base.debug.assert(this.state_ == remoting.SignalStrategy.State.NOT_CONNECTED);
75 base.debug.assert(this.onStateChangedCallback_ != null); 75 base.debug.assert(this.onStateChangedCallback_ != null);
76 76
77 this.error_ = remoting.Error.NONE; 77 this.error_ = remoting.Error.none();
78 var hostnameAndPort = server.split(':', 2); 78 var hostnameAndPort = server.split(':', 2);
79 this.server_ = hostnameAndPort[0]; 79 this.server_ = hostnameAndPort[0];
80 this.port_ = 80 this.port_ =
81 (hostnameAndPort.length == 2) ? parseInt(hostnameAndPort[1], 10) : 5222; 81 (hostnameAndPort.length == 2) ? parseInt(hostnameAndPort[1], 10) : 5222;
82 82
83 // The server name is passed as to attribute in the <stream>. When connecting 83 // The server name is passed as to attribute in the <stream>. When connecting
84 // to talk.google.com it affects the certificate the server will use for TLS: 84 // to talk.google.com it affects the certificate the server will use for TLS:
85 // talk.google.com uses gmail certificate when specified server is gmail.com 85 // talk.google.com uses gmail certificate when specified server is gmail.com
86 // or googlemail.com and google.com cert otherwise. In the same time it 86 // or googlemail.com and google.com cert otherwise. In the same time it
87 // doesn't accept talk.google.com as target server. Here we use google.com 87 // doesn't accept talk.google.com as target server. Here we use google.com
(...skipping 16 matching lines...) Expand all
104 this.onHandshakeDone_.bind(this), this.onError_.bind(this)); 104 this.onHandshakeDone_.bind(this), this.onError_.bind(this));
105 this.setState_(remoting.SignalStrategy.State.CONNECTING); 105 this.setState_(remoting.SignalStrategy.State.CONNECTING);
106 106
107 if (!this.socket_) { 107 if (!this.socket_) {
108 this.socket_ = new remoting.TcpSocket(); 108 this.socket_ = new remoting.TcpSocket();
109 } 109 }
110 var that = this; 110 var that = this;
111 this.socket_.connect(this.server_, this.port_) 111 this.socket_.connect(this.server_, this.port_)
112 .then(this.onSocketConnected_.bind(this)) 112 .then(this.onSocketConnected_.bind(this))
113 .catch(function(error) { 113 .catch(function(error) {
114 that.onError_(remoting.Error.NETWORK_FAILURE, 114 that.onError_(
115 'Failed to connect to ' + that.server_ + ': ' + error); 115 new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
116 'Failed to connect to ' + that.server_ + ': ' + error);
116 }); 117 });
117 }; 118 };
118 119
119 /** @param {string} message */ 120 /** @param {string} message */
120 remoting.XmppConnection.prototype.sendMessage = function(message) { 121 remoting.XmppConnection.prototype.sendMessage = function(message) {
121 base.debug.assert(this.state_ == remoting.SignalStrategy.State.CONNECTED); 122 base.debug.assert(this.state_ == remoting.SignalStrategy.State.CONNECTED);
122 this.sendString_(message); 123 this.sendString_(message);
123 }; 124 };
124 125
125 /** 126 /**
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } else if (this.state_ == remoting.SignalStrategy.State.CONNECTED) { 186 } else if (this.state_ == remoting.SignalStrategy.State.CONNECTED) {
186 this.streamParser_.appendData(data); 187 this.streamParser_.appendData(data);
187 } 188 }
188 }; 189 };
189 190
190 /** 191 /**
191 * @param {number} errorCode 192 * @param {number} errorCode
192 * @private 193 * @private
193 */ 194 */
194 remoting.XmppConnection.prototype.onReceiveError_ = function(errorCode) { 195 remoting.XmppConnection.prototype.onReceiveError_ = function(errorCode) {
195 this.onError_(remoting.Error.NETWORK_FAILURE, 196 this.onError_(
196 'Failed to receive from XMPP socket: ' + errorCode); 197 new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
198 'Failed to receive from XMPP socket: ' + errorCode);
197 }; 199 };
198 200
199 /** 201 /**
200 * @param {string} text 202 * @param {string} text
201 * @private 203 * @private
202 */ 204 */
203 remoting.XmppConnection.prototype.sendString_ = function(text) { 205 remoting.XmppConnection.prototype.sendString_ = function(text) {
204 this.sendBuffer_(base.encodeUtf8(text)); 206 this.sendBuffer_(base.encodeUtf8(text));
205 }; 207 };
206 208
(...skipping 17 matching lines...) Expand all
224 var that = this; 226 var that = this;
225 227
226 this.sendPending_ = true; 228 this.sendPending_ = true;
227 this.socket_.send(this.sendQueue_[0]) 229 this.socket_.send(this.sendQueue_[0])
228 .then(function(/** number */ bytesSent) { 230 .then(function(/** number */ bytesSent) {
229 that.sendPending_ = false; 231 that.sendPending_ = false;
230 that.onSent_(bytesSent); 232 that.onSent_(bytesSent);
231 }) 233 })
232 .catch(function(/** number */ error) { 234 .catch(function(/** number */ error) {
233 that.sendPending_ = false; 235 that.sendPending_ = false;
234 that.onError_(remoting.Error.NETWORK_FAILURE, 236 that.onError_(
235 'TCP write failed with error ' + error); 237 new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
238 'TCP write failed with error ' + error);
236 }); 239 });
237 }; 240 };
238 241
239 /** 242 /**
240 * @param {number} bytesSent 243 * @param {number} bytesSent
241 * @private 244 * @private
242 */ 245 */
243 remoting.XmppConnection.prototype.onSent_ = function(bytesSent) { 246 remoting.XmppConnection.prototype.onSent_ = function(bytesSent) {
244 // Ignore send() result if the socket was closed. 247 // Ignore send() result if the socket was closed.
245 if (this.state_ != remoting.SignalStrategy.State.HANDSHAKE && 248 if (this.state_ != remoting.SignalStrategy.State.HANDSHAKE &&
(...skipping 26 matching lines...) Expand all
272 this.socket_.startTls() 275 this.socket_.startTls()
273 .then(function() { 276 .then(function() {
274 that.startTlsPending_ = false; 277 that.startTlsPending_ = false;
275 that.socket_.startReceiving(that.onReceive_.bind(that), 278 that.socket_.startReceiving(that.onReceive_.bind(that),
276 that.onReceiveError_.bind(that)); 279 that.onReceiveError_.bind(that));
277 280
278 that.loginHandler_.onTlsStarted(); 281 that.loginHandler_.onTlsStarted();
279 }) 282 })
280 .catch(function(/** number */ error) { 283 .catch(function(/** number */ error) {
281 that.startTlsPending_ = false; 284 that.startTlsPending_ = false;
282 that.onError_(remoting.Error.NETWORK_FAILURE, 285 that.onError_(
283 'Failed to start TLS: ' + error); 286 new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE),
287 'Failed to start TLS: ' + error);
284 }); 288 });
285 } 289 }
286 290
287 /** 291 /**
288 * @param {string} jid 292 * @param {string} jid
289 * @param {remoting.XmppStreamParser} streamParser 293 * @param {remoting.XmppStreamParser} streamParser
290 * @private 294 * @private
291 */ 295 */
292 remoting.XmppConnection.prototype.onHandshakeDone_ = 296 remoting.XmppConnection.prototype.onHandshakeDone_ =
293 function(jid, streamParser) { 297 function(jid, streamParser) {
(...skipping 12 matching lines...) Expand all
306 if (this.onIncomingStanzaCallback_) { 310 if (this.onIncomingStanzaCallback_) {
307 this.onIncomingStanzaCallback_(stanza); 311 this.onIncomingStanzaCallback_(stanza);
308 } 312 }
309 }; 313 };
310 314
311 /** 315 /**
312 * @param {string} text 316 * @param {string} text
313 * @private 317 * @private
314 */ 318 */
315 remoting.XmppConnection.prototype.onParserError_ = function(text) { 319 remoting.XmppConnection.prototype.onParserError_ = function(text) {
316 this.onError_(remoting.Error.UNEXPECTED, text); 320 this.onError_(remoting.Error.unexpected(), text);
317 } 321 }
318 322
319 /** 323 /**
320 * @param {!remoting.Error} error 324 * @param {!remoting.Error} error
321 * @param {string} text 325 * @param {string} text
322 * @private 326 * @private
323 */ 327 */
324 remoting.XmppConnection.prototype.onError_ = function(error, text) { 328 remoting.XmppConnection.prototype.onError_ = function(error, text) {
325 console.error(text); 329 console.error(text);
326 this.error_ = error; 330 this.error_ = error;
327 base.dispose(this.socket_); 331 base.dispose(this.socket_);
328 this.socket_ = null; 332 this.socket_ = null;
329 this.setState_(remoting.SignalStrategy.State.FAILED); 333 this.setState_(remoting.SignalStrategy.State.FAILED);
330 }; 334 };
331 335
332 /** 336 /**
333 * @param {remoting.SignalStrategy.State} newState 337 * @param {remoting.SignalStrategy.State} newState
334 * @private 338 * @private
335 */ 339 */
336 remoting.XmppConnection.prototype.setState_ = function(newState) { 340 remoting.XmppConnection.prototype.setState_ = function(newState) {
337 if (this.state_ != newState) { 341 if (this.state_ != newState) {
338 this.state_ = newState; 342 this.state_ = newState;
339 this.onStateChangedCallback_(this.state_); 343 this.onStateChangedCallback_(this.state_);
340 } 344 }
341 }; 345 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/wcs_loader.js ('k') | remoting/webapp/crd/js/xmpp_login_handler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698