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 * @fileoverview | 6 * @fileoverview |
7 * Session class that handles creation and teardown of a remoting session. | 7 * Session class that handles creation and teardown of a remoting session. |
8 * | 8 * |
9 * This abstracts a <embed> element and controls the plugin which does the | 9 * This abstracts a <embed> element and controls the plugin which does the |
10 * actual remoting work. There should be no UI code inside this class. It | 10 * actual remoting work. There should be no UI code inside this class. It |
11 * should be purely thought of as a controller of sorts. | 11 * should be purely thought of as a controller of sorts. |
12 */ | 12 */ |
13 | 13 |
14 'use strict'; | 14 'use strict'; |
15 | 15 |
16 var remoting = remoting || {}; | 16 var remoting = remoting || {}; |
17 | 17 |
18 (function() { | 18 (function() { |
19 /** | 19 /** |
20 * @param {string} hostJid The jid of the host to connect to. | 20 * @param {string} hostJid The jid of the host to connect to. |
21 * @param {string} hostPublicKey The base64 encoded version of the host's | 21 * @param {string} hostPublicKey The base64 encoded version of the host's |
22 * public key. | 22 * public key. |
23 * @param {string} accessCode The access code for the IT2Me connection. | 23 * @param {string} accessCode The access code for the IT2Me connection. |
24 * @param {string} email The username for the talk network. | 24 * @param {string} email The username for the talk network. |
25 * @param {function(remoting.ClientSession.State):void} onStateChange | 25 * @param {function(remoting.ClientSession.State):void} onStateChange |
26 * The callback to invoke when the session changes state. | 26 * The callback to invoke when the session changes state. This callback |
| 27 * occurs after the state changes and is passed the previous state; the |
| 28 * new state is accessible via ClientSession's |state| property. |
27 * @constructor | 29 * @constructor |
28 */ | 30 */ |
29 remoting.ClientSession = function(hostJid, hostPublicKey, accessCode, email, | 31 remoting.ClientSession = function(hostJid, hostPublicKey, accessCode, email, |
30 onStateChange) { | 32 onStateChange) { |
31 this.state = remoting.ClientSession.CREATED; | 33 this.state = remoting.ClientSession.CREATED; |
32 | 34 |
33 this.hostJid = hostJid; | 35 this.hostJid = hostJid; |
34 this.hostPublicKey = hostPublicKey; | 36 this.hostPublicKey = hostPublicKey; |
35 this.accessCode = accessCode; | 37 this.accessCode = accessCode; |
36 this.email = email; | 38 this.email = email; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 * @param {Element} container The element to add the plugin to. | 106 * @param {Element} container The element to add the plugin to. |
105 * @param {string} oauth2AccessToken A valid OAuth2 access token. | 107 * @param {string} oauth2AccessToken A valid OAuth2 access token. |
106 * @return {void} Nothing. | 108 * @return {void} Nothing. |
107 */ | 109 */ |
108 remoting.ClientSession.prototype.createPluginAndConnect = | 110 remoting.ClientSession.prototype.createPluginAndConnect = |
109 function(container, oauth2AccessToken) { | 111 function(container, oauth2AccessToken) { |
110 this.plugin = document.createElement('embed'); | 112 this.plugin = document.createElement('embed'); |
111 this.plugin.id = this.PLUGIN_ID; | 113 this.plugin.id = this.PLUGIN_ID; |
112 this.plugin.src = 'about://none'; | 114 this.plugin.src = 'about://none'; |
113 this.plugin.type = 'pepper-application/x-chromoting'; | 115 this.plugin.type = 'pepper-application/x-chromoting'; |
| 116 this.plugin.width = 0; |
| 117 this.plugin.height = 0; |
114 container.appendChild(this.plugin); | 118 container.appendChild(this.plugin); |
115 | 119 |
116 if (!this.isPluginVersionSupported_(this.plugin)) { | 120 if (!this.isPluginVersionSupported_(this.plugin)) { |
117 // TODO(ajwong): Remove from parent. | 121 // TODO(ajwong): Remove from parent. |
118 delete this.plugin; | 122 delete this.plugin; |
119 this.setState_(remoting.ClientSession.BAD_PLUGIN_VERSION); | 123 this.setState_(remoting.ClientSession.BAD_PLUGIN_VERSION); |
120 return; | 124 return; |
121 } | 125 } |
122 | 126 |
123 var that = this; | 127 var that = this; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } else if (state == this.plugin.STATUS_FAILED) { | 317 } else if (state == this.plugin.STATUS_FAILED) { |
314 this.setState_(remoting.ClientSession.State.CONNECTION_FAILED); | 318 this.setState_(remoting.ClientSession.State.CONNECTION_FAILED); |
315 } | 319 } |
316 }; | 320 }; |
317 | 321 |
318 /** | 322 /** |
319 * @param {remoting.ClientSession.State} state The new state for the session. | 323 * @param {remoting.ClientSession.State} state The new state for the session. |
320 * @return {void} Nothing. | 324 * @return {void} Nothing. |
321 */ | 325 */ |
322 remoting.ClientSession.prototype.setState_ = function(state) { | 326 remoting.ClientSession.prototype.setState_ = function(state) { |
| 327 var oldState = state; |
323 this.state = state; | 328 this.state = state; |
324 if (this.onStateChange) { | 329 if (this.onStateChange) { |
325 this.onStateChange(this.state); | 330 this.onStateChange(oldState); |
326 } | 331 } |
327 }; | 332 }; |
328 | 333 |
329 /** | 334 /** |
330 * This is a callback that gets called when the desktop size contained in the | 335 * This is a callback that gets called when the desktop size contained in the |
331 * the plugin has changed. | 336 * the plugin has changed. |
332 * | 337 * |
333 * @return {void} Nothing. | 338 * @return {void} Nothing. |
334 */ | 339 */ |
335 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { | 340 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 'video_bandwidth': this.plugin.videoBandwidth, | 402 'video_bandwidth': this.plugin.videoBandwidth, |
398 'capture_latency': this.plugin.videoCaptureLatency, | 403 'capture_latency': this.plugin.videoCaptureLatency, |
399 'encode_latency': this.plugin.videoEncodeLatency, | 404 'encode_latency': this.plugin.videoEncodeLatency, |
400 'decode_latency': this.plugin.videoDecodeLatency, | 405 'decode_latency': this.plugin.videoDecodeLatency, |
401 'render_latency': this.plugin.videoRenderLatency, | 406 'render_latency': this.plugin.videoRenderLatency, |
402 'roundtrip_latency': this.plugin.roundTripLatency | 407 'roundtrip_latency': this.plugin.roundTripLatency |
403 }; | 408 }; |
404 }; | 409 }; |
405 | 410 |
406 }()); | 411 }()); |
OLD | NEW |