| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
| 6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
| 7 | 7 |
| 8 (function() { | 8 (function() { |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 /** @private */ | 23 /** @private */ |
| 24 this.parentActivity_ = parentActivity; | 24 this.parentActivity_ = parentActivity; |
| 25 /** @private {remoting.DesktopConnectedView} */ | 25 /** @private {remoting.DesktopConnectedView} */ |
| 26 this.connectedView_ = null; | 26 this.connectedView_ = null; |
| 27 /** @private */ | 27 /** @private */ |
| 28 this.sessionFactory_ = new remoting.ClientSessionFactory( | 28 this.sessionFactory_ = new remoting.ClientSessionFactory( |
| 29 document.querySelector('#client-container .client-plugin-container'), | 29 document.querySelector('#client-container .client-plugin-container'), |
| 30 remoting.app_capabilities()); | 30 remoting.app_capabilities()); |
| 31 /** @private {remoting.ClientSession} */ | 31 /** @private {remoting.ClientSession} */ |
| 32 this.session_ = null; | 32 this.session_ = null; |
| 33 /** @private {remoting.ConnectingDialog} */ |
| 34 this.connectingDialog_ = |
| 35 new remoting.ConnectingDialog(parentActivity.stop.bind(parentActivity)); |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 /** | 38 /** |
| 36 * Initiates a connection. | 39 * Initiates a connection. |
| 37 * | 40 * |
| 38 * @param {remoting.Host} host the Host to connect to. | 41 * @param {remoting.Host} host the Host to connect to. |
| 39 * @param {remoting.CredentialsProvider} credentialsProvider | 42 * @param {remoting.CredentialsProvider} credentialsProvider |
| 40 * @param {boolean=} opt_suppressOfflineError | 43 * @param {boolean=} opt_suppressOfflineError |
| 41 * @return {void} Nothing. | 44 * @return {void} Nothing. |
| 42 */ | 45 */ |
| 43 remoting.DesktopRemotingActivity.prototype.start = | 46 remoting.DesktopRemotingActivity.prototype.start = |
| 44 function(host, credentialsProvider, opt_suppressOfflineError) { | 47 function(host, credentialsProvider, opt_suppressOfflineError) { |
| 45 var that = this; | 48 var that = this; |
| 46 this.sessionFactory_.createSession(this).then( | 49 this.sessionFactory_.createSession(this).then( |
| 47 function(/** remoting.ClientSession */ session) { | 50 function(/** remoting.ClientSession */ session) { |
| 48 that.session_ = session; | 51 that.session_ = session; |
| 49 session.logHostOfflineErrors(!opt_suppressOfflineError); | 52 session.logHostOfflineErrors(!opt_suppressOfflineError); |
| 50 session.connect(host, credentialsProvider); | 53 session.connect(host, credentialsProvider); |
| 51 }); | 54 }).catch(remoting.Error.handler( |
| 55 function(/** !remoting.Error */ error) { |
| 56 that.parentActivity_.onConnectionFailed(error); |
| 57 })); |
| 52 }; | 58 }; |
| 53 | 59 |
| 54 remoting.DesktopRemotingActivity.prototype.stop = function() { | 60 remoting.DesktopRemotingActivity.prototype.stop = function() { |
| 55 if (this.session_) { | 61 if (this.session_) { |
| 56 this.session_.disconnect(remoting.Error.none()); | 62 this.session_.disconnect(remoting.Error.none()); |
| 57 console.log('Disconnected.'); | 63 console.log('Disconnected.'); |
| 58 } | 64 } |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 /** | 67 /** |
| 62 * @param {remoting.ConnectionInfo} connectionInfo | 68 * @param {remoting.ConnectionInfo} connectionInfo |
| 63 */ | 69 */ |
| 64 remoting.DesktopRemotingActivity.prototype.onConnected = | 70 remoting.DesktopRemotingActivity.prototype.onConnected = |
| 65 function(connectionInfo) { | 71 function(connectionInfo) { |
| 72 this.connectingDialog_.hide(); |
| 66 remoting.setMode(remoting.AppMode.IN_SESSION); | 73 remoting.setMode(remoting.AppMode.IN_SESSION); |
| 67 if (!base.isAppsV2()) { | 74 if (!base.isAppsV2()) { |
| 68 remoting.toolbar.center(); | 75 remoting.toolbar.center(); |
| 69 remoting.toolbar.preview(); | 76 remoting.toolbar.preview(); |
| 70 } | 77 } |
| 71 | 78 |
| 72 this.connectedView_ = new remoting.DesktopConnectedView( | 79 this.connectedView_ = new remoting.DesktopConnectedView( |
| 73 document.getElementById('client-container'), connectionInfo); | 80 document.getElementById('client-container'), connectionInfo); |
| 74 | 81 |
| 75 // By default, under ChromeOS, remap the right Control key to the right | 82 // By default, under ChromeOS, remap the right Control key to the right |
| 76 // Win / Cmd key. | 83 // Win / Cmd key. |
| 77 if (remoting.platformIsChromeOS()) { | 84 if (remoting.platformIsChromeOS()) { |
| 78 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); | 85 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); |
| 79 } | 86 } |
| 80 | 87 |
| 81 if (connectionInfo.plugin().hasCapability( | 88 if (connectionInfo.plugin().hasCapability( |
| 82 remoting.ClientSession.Capability.VIDEO_RECORDER)) { | 89 remoting.ClientSession.Capability.VIDEO_RECORDER)) { |
| 83 var recorder = new remoting.VideoFrameRecorder(); | 90 var recorder = new remoting.VideoFrameRecorder(); |
| 84 connectionInfo.plugin().extensions().register(recorder); | 91 connectionInfo.plugin().extensions().register(recorder); |
| 85 this.connectedView_.setVideoFrameRecorder(recorder); | 92 this.connectedView_.setVideoFrameRecorder(recorder); |
| 86 } | 93 } |
| 87 | 94 |
| 88 this.parentActivity_.onConnected(connectionInfo); | 95 this.parentActivity_.onConnected(connectionInfo); |
| 89 }; | 96 }; |
| 90 | 97 |
| 91 remoting.DesktopRemotingActivity.prototype.onDisconnected = function() { | 98 remoting.DesktopRemotingActivity.prototype.onDisconnected = function(reason) { |
| 92 this.parentActivity_.onDisconnected(); | 99 if (this.handleError_(reason)) { |
| 93 this.dispose(); | 100 return; |
| 101 } |
| 102 this.parentActivity_.onDisconnected(reason); |
| 94 }; | 103 }; |
| 95 | 104 |
| 96 /** | 105 /** |
| 97 * @param {!remoting.Error} error | 106 * @param {!remoting.Error} error |
| 98 */ | 107 */ |
| 99 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = | 108 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = |
| 100 function(error) { | 109 function(error) { |
| 110 if (this.handleError_(error)) { |
| 111 return; |
| 112 } |
| 101 this.parentActivity_.onConnectionFailed(error); | 113 this.parentActivity_.onConnectionFailed(error); |
| 102 }; | 114 }; |
| 103 | 115 |
| 104 /** | 116 /** |
| 105 * @param {!remoting.Error} error The error to be localized and displayed. | 117 * @param {!remoting.Error} error The error to be localized and displayed. |
| 118 * @return {boolean} returns true if the error is handled. |
| 119 * @private |
| 106 */ | 120 */ |
| 107 remoting.DesktopRemotingActivity.prototype.onError = function(error) { | 121 remoting.DesktopRemotingActivity.prototype.handleError_ = function(error) { |
| 108 console.error('Connection failed: ' + error.toString()); | |
| 109 | |
| 110 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { | 122 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
| 111 remoting.setMode(remoting.AppMode.HOME); | 123 remoting.setMode(remoting.AppMode.HOME); |
| 112 remoting.handleAuthFailureAndRelaunch(); | 124 remoting.handleAuthFailureAndRelaunch(); |
| 113 return; | 125 return true; |
| 114 } | 126 } |
| 115 | 127 return false; |
| 116 this.parentActivity_.onError(error); | |
| 117 | |
| 118 this.dispose(); | |
| 119 }; | 128 }; |
| 120 | 129 |
| 121 remoting.DesktopRemotingActivity.prototype.dispose = function() { | 130 remoting.DesktopRemotingActivity.prototype.dispose = function() { |
| 122 base.dispose(this.connectedView_); | 131 base.dispose(this.connectedView_); |
| 123 this.connectedView_ = null; | 132 this.connectedView_ = null; |
| 124 base.dispose(this.session_); | 133 base.dispose(this.session_); |
| 125 this.session_ = null; | 134 this.session_ = null; |
| 135 this.connectingDialog_.hide(); |
| 126 }; | 136 }; |
| 127 | 137 |
| 128 /** @return {remoting.DesktopConnectedView} */ | 138 /** @return {remoting.DesktopConnectedView} */ |
| 129 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { | 139 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { |
| 130 return this.connectedView_; | 140 return this.connectedView_; |
| 131 }; | 141 }; |
| 132 | 142 |
| 133 /** | 143 /** |
| 134 * @return {remoting.ClientSession}. | 144 * @return {remoting.ClientSession}. |
| 135 */ | 145 */ |
| 136 remoting.DesktopRemotingActivity.prototype.getSession = function() { | 146 remoting.DesktopRemotingActivity.prototype.getSession = function() { |
| 137 return this.session_; | 147 return this.session_; |
| 138 }; | 148 }; |
| 139 | 149 |
| 150 /** @return {remoting.ConnectingDialog} */ |
| 151 remoting.DesktopRemotingActivity.prototype.getConnectingDialog = function() { |
| 152 return this.connectingDialog_; |
| 153 }; |
| 154 |
| 140 })(); | 155 })(); |
| OLD | NEW |