OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * @fileoverview | 6 * @fileoverview |
7 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 plugin.setConnectionEventHandler(this); | 81 plugin.setConnectionEventHandler(this); |
82 | 82 |
83 /** @private */ | 83 /** @private */ |
84 this.connectedDisposables_ = new base.Disposables(); | 84 this.connectedDisposables_ = new base.Disposables(); |
85 | 85 |
86 this.defineEvents(Object.keys(remoting.ClientSession.Events)); | 86 this.defineEvents(Object.keys(remoting.ClientSession.Events)); |
87 }; | 87 }; |
88 | 88 |
89 /** @enum {string} */ | 89 /** @enum {string} */ |
90 remoting.ClientSession.Events = { | 90 remoting.ClientSession.Events = { |
91 stateChanged: 'stateChanged', // deprecated. | 91 videoChannelStateChanged: 'videoChannelStateChanged' |
92 videoChannelStateChanged: 'videoChannelStateChanged', | |
93 }; | 92 }; |
94 | 93 |
95 /** | 94 /** |
96 * @interface | 95 * @interface |
97 * [START]-------> [onConnected] ------> [onDisconnected] | 96 * [START]-------> [onConnected] ------> [onDisconnected] |
98 * | | | 97 * | |
99 * |-----> [OnConnectionFailed] |----> [onError] | 98 * |-----> [OnConnectionFailed] |
100 * | 99 * |
101 * TODO(kelvinp): Route session state changes through this interface. | |
102 */ | 100 */ |
103 remoting.ClientSession.EventHandler = function() {}; | 101 remoting.ClientSession.EventHandler = function() {}; |
104 | 102 |
105 /** | 103 /** |
106 * Called when the connection failed before it is connected. | 104 * Called when the connection failed before it is connected. |
107 * | 105 * |
108 * @param {!remoting.Error} error | 106 * @param {!remoting.Error} error |
109 */ | 107 */ |
110 remoting.ClientSession.EventHandler.prototype.onConnectionFailed = | 108 remoting.ClientSession.EventHandler.prototype.onConnectionFailed = |
111 function(error) {}; | 109 function(error) {}; |
112 | 110 |
113 /** | 111 /** |
114 * Called when a new session has been connected. The |connectionInfo| will be | 112 * Called when a new session has been connected. The |connectionInfo| will be |
115 * valid until onDisconnected() or onError() is called. | 113 * valid until onDisconnected() is called. |
116 * | 114 * |
117 * @param {!remoting.ConnectionInfo} connectionInfo | 115 * @param {!remoting.ConnectionInfo} connectionInfo |
118 */ | 116 */ |
119 remoting.ClientSession.EventHandler.prototype.onConnected = | 117 remoting.ClientSession.EventHandler.prototype.onConnected = |
120 function(connectionInfo) {}; | 118 function(connectionInfo) {}; |
121 | 119 |
122 /** | 120 /** |
123 * Called when the current session has been disconnected. | 121 * Called when the current session has been disconnected. |
122 * | |
123 * @param {!remoting.Error} reason Reason that the session is disconnected. | |
124 * Set to remoting.Error.none() if there is no error. | |
124 */ | 125 */ |
125 remoting.ClientSession.EventHandler.prototype.onDisconnected = function() {}; | 126 remoting.ClientSession.EventHandler.prototype.onDisconnected = |
126 | 127 function(reason) {}; |
127 /** | |
128 * Called when an error needs to be displayed to the user. | |
129 * @param {!remoting.Error} error | |
130 */ | |
131 remoting.ClientSession.EventHandler.prototype.onError = function(error) {}; | |
132 | 128 |
133 // Note that the positive values in both of these enums are copied directly | 129 // Note that the positive values in both of these enums are copied directly |
134 // from connection_to_host.h and must be kept in sync. Code in | 130 // from connection_to_host.h and must be kept in sync. Code in |
135 // chromoting_instance.cc converts the C++ enums into strings that must match | 131 // chromoting_instance.cc converts the C++ enums into strings that must match |
136 // the names given here. | 132 // the names given here. |
137 // The negative values represent state transitions that occur within the | 133 // The negative values represent state transitions that occur within the |
138 // web-app that have no corresponding plugin state transition. | 134 // web-app that have no corresponding plugin state transition. |
139 /** @enum {number} */ | 135 /** @enum {number} */ |
140 remoting.ClientSession.State = { | 136 remoting.ClientSession.State = { |
141 CONNECTION_CANCELED: -3, // Connection closed (gracefully) before connecting. | 137 CONNECTION_CANCELED: -3, // Connection closed (gracefully) before connecting. |
(...skipping 16 matching lines...) Expand all Loading... | |
158 * @param {string} state The state name. | 154 * @param {string} state The state name. |
159 * @return {remoting.ClientSession.State} The session state enum value. | 155 * @return {remoting.ClientSession.State} The session state enum value. |
160 */ | 156 */ |
161 remoting.ClientSession.State.fromString = function(state) { | 157 remoting.ClientSession.State.fromString = function(state) { |
162 if (!remoting.ClientSession.State.hasOwnProperty(state)) { | 158 if (!remoting.ClientSession.State.hasOwnProperty(state)) { |
163 throw "Invalid ClientSession.State: " + state; | 159 throw "Invalid ClientSession.State: " + state; |
164 } | 160 } |
165 return remoting.ClientSession.State[state]; | 161 return remoting.ClientSession.State[state]; |
166 }; | 162 }; |
167 | 163 |
168 /** | |
169 @param {remoting.ClientSession.State} current | |
170 @param {remoting.ClientSession.State} previous | |
171 @constructor | |
172 */ | |
173 remoting.ClientSession.StateEvent = function(current, previous) { | |
174 /** @type {remoting.ClientSession.State} */ | |
175 this.previous = previous | |
176 | |
177 /** @type {remoting.ClientSession.State} */ | |
178 this.current = current; | |
179 }; | |
180 | |
181 /** @enum {number} */ | 164 /** @enum {number} */ |
182 remoting.ClientSession.ConnectionError = { | 165 remoting.ClientSession.ConnectionError = { |
183 UNKNOWN: -1, | 166 UNKNOWN: -1, |
184 NONE: 0, | 167 NONE: 0, |
185 HOST_IS_OFFLINE: 1, | 168 HOST_IS_OFFLINE: 1, |
186 SESSION_REJECTED: 2, | 169 SESSION_REJECTED: 2, |
187 INCOMPATIBLE_PROTOCOL: 3, | 170 INCOMPATIBLE_PROTOCOL: 3, |
188 NETWORK_FAILURE: 4, | 171 NETWORK_FAILURE: 4, |
189 HOST_OVERLOAD: 5 | 172 HOST_OVERLOAD: 5 |
190 }; | 173 }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 /** | 261 /** |
279 * Disconnect the current session with a particular |error|. The session will | 262 * Disconnect the current session with a particular |error|. The session will |
280 * raise a |stateChanged| event in response to it. The caller should then call | 263 * raise a |stateChanged| event in response to it. The caller should then call |
281 * dispose() to remove and destroy the <embed> element. | 264 * dispose() to remove and destroy the <embed> element. |
282 * | 265 * |
283 * @param {!remoting.Error} error The reason for the disconnection. Use | 266 * @param {!remoting.Error} error The reason for the disconnection. Use |
284 * remoting.Error.none() if there is no error. | 267 * remoting.Error.none() if there is no error. |
285 * @return {void} Nothing. | 268 * @return {void} Nothing. |
286 */ | 269 */ |
287 remoting.ClientSession.prototype.disconnect = function(error) { | 270 remoting.ClientSession.prototype.disconnect = function(error) { |
271 if (this.isFinished()) { | |
272 return; | |
Jamie
2015/04/24 18:09:09
This appears in both your CLs.
| |
273 } | |
274 | |
288 this.sendIq_( | 275 this.sendIq_( |
289 '<cli:iq ' + | 276 '<cli:iq ' + |
290 'to="' + this.host_.jabberId + '" ' + | 277 'to="' + this.host_.jabberId + '" ' + |
291 'type="set" ' + | 278 'type="set" ' + |
292 'id="session-terminate" ' + | 279 'id="session-terminate" ' + |
293 'xmlns:cli="jabber:client">' + | 280 'xmlns:cli="jabber:client">' + |
294 '<jingle ' + | 281 '<jingle ' + |
295 'xmlns="urn:xmpp:jingle:1" ' + | 282 'xmlns="urn:xmpp:jingle:1" ' + |
296 'action="session-terminate" ' + | 283 'action="session-terminate" ' + |
297 'sid="' + this.sessionId_ + '">' + | 284 'sid="' + this.sessionId_ + '">' + |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 case remoting.ClientSession.State.AUTHENTICATED: | 531 case remoting.ClientSession.State.AUTHENTICATED: |
545 console.log('Connection authenticated.'); | 532 console.log('Connection authenticated.'); |
546 break; | 533 break; |
547 | 534 |
548 case remoting.ClientSession.State.INITIALIZING: | 535 case remoting.ClientSession.State.INITIALIZING: |
549 console.log('Connection initializing .'); | 536 console.log('Connection initializing .'); |
550 break; | 537 break; |
551 | 538 |
552 case remoting.ClientSession.State.CLOSED: | 539 case remoting.ClientSession.State.CLOSED: |
553 console.log('Connection closed.'); | 540 console.log('Connection closed.'); |
554 this.listener_.onDisconnected(); | 541 this.listener_.onDisconnected(remoting.Error.none()); |
555 break; | 542 break; |
556 | 543 |
557 case remoting.ClientSession.State.CONNECTION_CANCELED: | 544 case remoting.ClientSession.State.CONNECTION_CANCELED: |
558 case remoting.ClientSession.State.FAILED: | 545 case remoting.ClientSession.State.FAILED: |
559 error = this.getError(); | 546 error = this.getError(); |
560 if (!error.isNone()) { | 547 if (!error.isNone()) { |
561 console.error('Connection failed: ' + error.toString()); | 548 console.error('Connection failed: ' + error.toString()); |
562 } | 549 } |
563 this.listener_.onConnectionFailed(error); | 550 this.listener_.onConnectionFailed(error); |
564 break; | 551 break; |
565 | 552 |
566 case remoting.ClientSession.State.CONNECTION_DROPPED: | 553 case remoting.ClientSession.State.CONNECTION_DROPPED: |
567 error = this.getError(); | 554 error = this.getError(); |
568 console.error('Connection dropped: ' + error.toString()); | 555 console.error('Connection dropped: ' + error.toString()); |
569 this.listener_.onError(error); | 556 this.listener_.onDisconnected(error); |
570 break; | 557 break; |
571 | 558 |
572 default: | 559 default: |
573 console.error('Unexpected client plugin state: ' + newState); | 560 console.error('Unexpected client plugin state: ' + newState); |
574 // This should only happen if the web-app and client plugin get out of | |
575 // sync, and even then the version check should ensure compatibility. | |
576 this.listener_.onError( | |
577 new remoting.Error(remoting.Error.Tag.MISSING_PLUGIN)); | |
578 } | 561 } |
579 | |
580 this.raiseEvent(remoting.ClientSession.Events.stateChanged, | |
581 new remoting.ClientSession.StateEvent(newState, oldState) | |
582 ); | |
583 }; | 562 }; |
584 | 563 |
585 /** | 564 /** |
586 * @param {remoting.ClientSession.State} previous | 565 * @param {remoting.ClientSession.State} previous |
587 * @param {remoting.ClientSession.State} current | 566 * @param {remoting.ClientSession.State} current |
588 * @return {remoting.ClientSession.State} | 567 * @return {remoting.ClientSession.State} |
589 * @private | 568 * @private |
590 */ | 569 */ |
591 remoting.ClientSession.prototype.translateState_ = function(previous, current) { | 570 remoting.ClientSession.prototype.translateState_ = function(previous, current) { |
592 var State = remoting.ClientSession.State; | 571 var State = remoting.ClientSession.State; |
(...skipping 24 matching lines...) Expand all Loading... | |
617 * For example, if attempting a connection using a cached JID, host-offline | 596 * For example, if attempting a connection using a cached JID, host-offline |
618 * errors should not be logged because the JID will be refreshed and the | 597 * errors should not be logged because the JID will be refreshed and the |
619 * connection retried. | 598 * connection retried. |
620 * | 599 * |
621 * @param {boolean} enable True to log host-offline errors; false to suppress. | 600 * @param {boolean} enable True to log host-offline errors; false to suppress. |
622 */ | 601 */ |
623 remoting.ClientSession.prototype.logHostOfflineErrors = function(enable) { | 602 remoting.ClientSession.prototype.logHostOfflineErrors = function(enable) { |
624 this.logHostOfflineErrors_ = enable; | 603 this.logHostOfflineErrors_ = enable; |
625 }; | 604 }; |
626 | 605 |
OLD | NEW |