| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * | 7 * |
| 8 * It2MeHelperChannel relays messages between Hangouts and Chrome Remote Desktop | 8 * It2MeHelperChannel relays messages between Hangouts and Chrome Remote Desktop |
| 9 * (webapp) for the helper (the Hangouts participant who is giving remote | 9 * (webapp) for the helper (the Hangouts participant who is giving remote |
| 10 * assistance). | 10 * assistance). |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 this.closeWebapp_(message); | 159 this.closeWebapp_(message); |
| 160 return true; | 160 return true; |
| 161 case MessageTypes.HELLO: | 161 case MessageTypes.HELLO: |
| 162 this.hangoutPort_.postMessage({ | 162 this.hangoutPort_.postMessage({ |
| 163 method: MessageTypes.HELLO_RESPONSE, | 163 method: MessageTypes.HELLO_RESPONSE, |
| 164 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) | 164 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) |
| 165 }); | 165 }); |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 throw new Error('Unknown message method=' + message.method); | 168 throw new Error('Unknown message method=' + message.method); |
| 169 } catch(e) { | 169 } catch(/** @type {*} */ e) { |
| 170 var error = /** @type {Error} */ e; | 170 var error = /** @type {Error} */ (e); |
| 171 this.sendErrorResponse_(this.hangoutPort_, error, message); | 171 this.sendErrorResponse_(this.hangoutPort_, error, message); |
| 172 } | 172 } |
| 173 return false; | 173 return false; |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Disconnect the existing connection to the helpee. | 177 * Disconnect the existing connection to the helpee. |
| 178 * | 178 * |
| 179 * @param {{method:string, data:Object.<string,*>}} message | 179 * @param {{method:string, data:Object.<string,*>}} message |
| 180 * @private | 180 * @private |
| (...skipping 16 matching lines...) Expand all Loading... |
| 197 * @param {{method:string, data:Object.<string,*>}} message | 197 * @param {{method:string, data:Object.<string,*>}} message |
| 198 * @private | 198 * @private |
| 199 */ | 199 */ |
| 200 remoting.It2MeHelperChannel.prototype.launchWebapp_ = | 200 remoting.It2MeHelperChannel.prototype.launchWebapp_ = |
| 201 function(message) { | 201 function(message) { |
| 202 var accessCode = getStringAttr(message, 'accessCode'); | 202 var accessCode = getStringAttr(message, 'accessCode'); |
| 203 if (!accessCode) { | 203 if (!accessCode) { |
| 204 throw new Error('Access code is missing'); | 204 throw new Error('Access code is missing'); |
| 205 } | 205 } |
| 206 | 206 |
| 207 /** |
| 208 * @this {remoting.It2MeHelperChannel} |
| 209 * @param {string} instanceId |
| 210 */ |
| 211 var setInstance = function(instanceId) { |
| 212 this.instanceId_ = instanceId; |
| 213 }; |
| 214 |
| 207 // Launch the webapp. | 215 // Launch the webapp. |
| 208 this.appLauncher_.launch({ | 216 this.appLauncher_.launch({ |
| 209 mode: 'hangout', | 217 mode: 'hangout', |
| 210 accessCode: accessCode | 218 accessCode: accessCode |
| 211 }).then( | 219 }).then(setInstance.bind(this)); |
| 212 /** | |
| 213 * @this {remoting.It2MeHelperChannel} | |
| 214 * @param {string} instanceId | |
| 215 */ | |
| 216 function(instanceId){ | |
| 217 this.instanceId_ = instanceId; | |
| 218 }.bind(this)); | |
| 219 }; | 220 }; |
| 220 | 221 |
| 221 /** | 222 /** |
| 222 * @private | 223 * @private |
| 223 */ | 224 */ |
| 224 remoting.It2MeHelperChannel.prototype.onHangoutDisconnect_ = function() { | 225 remoting.It2MeHelperChannel.prototype.onHangoutDisconnect_ = function() { |
| 225 this.appLauncher_.close(this.instanceId_); | 226 this.appLauncher_.close(this.instanceId_); |
| 226 this.unhookPorts_(); | 227 this.unhookPorts_(); |
| 227 }; | 228 }; |
| 228 | 229 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 */ | 264 */ |
| 264 remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) { | 265 remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) { |
| 265 try { | 266 try { |
| 266 console.log('It2MeHelperChannel id=' + this.instanceId_ + | 267 console.log('It2MeHelperChannel id=' + this.instanceId_ + |
| 267 ' incoming message method=' + message.method); | 268 ' incoming message method=' + message.method); |
| 268 var MessageTypes = remoting.It2MeHelperChannel.WebappMessageTypes; | 269 var MessageTypes = remoting.It2MeHelperChannel.WebappMessageTypes; |
| 269 switch (message.method) { | 270 switch (message.method) { |
| 270 case MessageTypes.SESSION_STATE_CHANGED: | 271 case MessageTypes.SESSION_STATE_CHANGED: |
| 271 var state = getNumberAttr(message, 'state'); | 272 var state = getNumberAttr(message, 'state'); |
| 272 this.sessionState_ = | 273 this.sessionState_ = |
| 273 /** @type {remoting.ClientSession.State} */ state; | 274 /** @type {remoting.ClientSession.State} */(state); |
| 274 this.hangoutPort_.postMessage(message); | 275 this.hangoutPort_.postMessage(message); |
| 275 return true; | 276 return true; |
| 276 } | 277 } |
| 277 throw new Error('Unknown message method=' + message.method); | 278 throw new Error('Unknown message method=' + message.method); |
| 278 } catch(e) { | 279 } catch(/** @type {*} */ e) { |
| 279 var error = /** @type {Error} */ e; | 280 var error = /** @type {Error} */ (e); |
| 280 this.sendErrorResponse_(this.webappPort_, error, message); | 281 this.sendErrorResponse_(this.webappPort_, error, message); |
| 281 } | 282 } |
| 282 return false; | 283 return false; |
| 283 }; | 284 }; |
| 284 | 285 |
| 285 remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() { | 286 remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() { |
| 286 if (this.webappPort_) { | 287 if (this.webappPort_) { |
| 287 this.webappPort_.onMessage.removeListener(this.onWebappMessageRef_); | 288 this.webappPort_.onMessage.removeListener(this.onWebappMessageRef_); |
| 288 this.webappPort_.onDisconnect.removeListener(this.onWebappDisconnectRef_); | 289 this.webappPort_.onDisconnect.removeListener(this.onWebappDisconnectRef_); |
| 289 this.webappPort_.disconnect(); | 290 this.webappPort_.disconnect(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 317 | 318 |
| 318 console.error('Error responding to message method:' + | 319 console.error('Error responding to message method:' + |
| 319 (opt_incomingMessage ? opt_incomingMessage.method : 'null') + | 320 (opt_incomingMessage ? opt_incomingMessage.method : 'null') + |
| 320 ' error:' + error); | 321 ' error:' + error); |
| 321 port.postMessage({ | 322 port.postMessage({ |
| 322 method: remoting.It2MeHelperChannel.HangoutMessageTypes.ERROR, | 323 method: remoting.It2MeHelperChannel.HangoutMessageTypes.ERROR, |
| 323 message: error, | 324 message: error, |
| 324 request: opt_incomingMessage | 325 request: opt_incomingMessage |
| 325 }); | 326 }); |
| 326 }; | 327 }; |
| OLD | NEW |