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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 this.onWebappDisconnectRef_ = this.onWebappDisconnect_.bind(this); | 112 this.onWebappDisconnectRef_ = this.onWebappDisconnect_.bind(this); |
113 this.onHangoutMessageRef_ = this.onHangoutMessage_.bind(this); | 113 this.onHangoutMessageRef_ = this.onHangoutMessage_.bind(this); |
114 this.onHangoutDisconnectRef_ = this.onHangoutDisconnect_.bind(this); | 114 this.onHangoutDisconnectRef_ = this.onHangoutDisconnect_.bind(this); |
115 }; | 115 }; |
116 | 116 |
117 /** @enum {string} */ | 117 /** @enum {string} */ |
118 remoting.It2MeHelperChannel.HangoutMessageTypes = { | 118 remoting.It2MeHelperChannel.HangoutMessageTypes = { |
119 HELLO: 'hello', | 119 HELLO: 'hello', |
120 HELLO_RESPONSE: 'helloResponse', | 120 HELLO_RESPONSE: 'helloResponse', |
121 CONNECT: 'connect', | 121 CONNECT: 'connect', |
122 DISCONNECT: 'disconnect' | 122 DISCONNECT: 'disconnect', |
| 123 ERROR: 'error' |
123 }; | 124 }; |
124 | 125 |
125 /** @enum {string} */ | 126 /** @enum {string} */ |
126 remoting.It2MeHelperChannel.Features = { | 127 remoting.It2MeHelperChannel.Features = { |
127 REMOTE_ASSISTANCE: 'remoteAssistance' | 128 REMOTE_ASSISTANCE: 'remoteAssistance' |
128 }; | 129 }; |
129 | 130 |
130 /** @enum {string} */ | 131 /** @enum {string} */ |
131 remoting.It2MeHelperChannel.WebappMessageTypes = { | 132 remoting.It2MeHelperChannel.WebappMessageTypes = { |
132 SESSION_STATE_CHANGED: 'sessionStateChanged' | 133 SESSION_STATE_CHANGED: 'sessionStateChanged' |
(...skipping 27 matching lines...) Expand all Loading... |
160 case MessageTypes.HELLO: | 161 case MessageTypes.HELLO: |
161 this.hangoutPort_.postMessage({ | 162 this.hangoutPort_.postMessage({ |
162 method: MessageTypes.HELLO_RESPONSE, | 163 method: MessageTypes.HELLO_RESPONSE, |
163 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) | 164 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) |
164 }); | 165 }); |
165 return true; | 166 return true; |
166 } | 167 } |
167 throw new Error('Unknown message method=' + message.method); | 168 throw new Error('Unknown message method=' + message.method); |
168 } catch(e) { | 169 } catch(e) { |
169 var error = /** @type {Error} */ e; | 170 var error = /** @type {Error} */ e; |
170 console.error(error); | 171 this.sendErrorResponse_(this.hangoutPort_, error, message); |
171 this.hangoutPort_.postMessage({ | |
172 method: message.method + 'Response', | |
173 error: error.message | |
174 }); | |
175 } | 172 } |
176 return false; | 173 return false; |
177 }; | 174 }; |
178 | 175 |
179 /** | 176 /** |
180 * Disconnect the existing connection to the helpee. | 177 * Disconnect the existing connection to the helpee. |
181 * | 178 * |
182 * @param {{method:string, data:Object.<string,*>}} message | 179 * @param {{method:string, data:Object.<string,*>}} message |
183 * @private | 180 * @private |
184 */ | 181 */ |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 case MessageTypes.SESSION_STATE_CHANGED: | 270 case MessageTypes.SESSION_STATE_CHANGED: |
274 var state = getNumberAttr(message, 'state'); | 271 var state = getNumberAttr(message, 'state'); |
275 this.sessionState_ = | 272 this.sessionState_ = |
276 /** @type {remoting.ClientSession.State} */ state; | 273 /** @type {remoting.ClientSession.State} */ state; |
277 this.hangoutPort_.postMessage(message); | 274 this.hangoutPort_.postMessage(message); |
278 return true; | 275 return true; |
279 } | 276 } |
280 throw new Error('Unknown message method=' + message.method); | 277 throw new Error('Unknown message method=' + message.method); |
281 } catch(e) { | 278 } catch(e) { |
282 var error = /** @type {Error} */ e; | 279 var error = /** @type {Error} */ e; |
283 console.error(error); | 280 this.sendErrorResponse_(this.webappPort_, error, message); |
284 this.webappPort_.postMessage({ | |
285 method: message.method + 'Response', | |
286 error: error.message | |
287 }); | |
288 } | 281 } |
289 return false; | 282 return false; |
290 }; | 283 }; |
291 | 284 |
292 remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() { | 285 remoting.It2MeHelperChannel.prototype.unhookPorts_ = function() { |
293 if (this.webappPort_) { | 286 if (this.webappPort_) { |
294 this.webappPort_.onMessage.removeListener(this.onWebappMessageRef_); | 287 this.webappPort_.onMessage.removeListener(this.onWebappMessageRef_); |
295 this.webappPort_.onDisconnect.removeListener(this.onWebappDisconnectRef_); | 288 this.webappPort_.onDisconnect.removeListener(this.onWebappDisconnectRef_); |
296 this.webappPort_.disconnect(); | 289 this.webappPort_.disconnect(); |
297 this.webappPort_ = null; | 290 this.webappPort_ = null; |
298 } | 291 } |
299 | 292 |
300 if (this.hangoutPort_) { | 293 if (this.hangoutPort_) { |
301 this.hangoutPort_.onMessage.removeListener(this.onHangoutMessageRef_); | 294 this.hangoutPort_.onMessage.removeListener(this.onHangoutMessageRef_); |
302 this.hangoutPort_.onDisconnect.removeListener(this.onHangoutDisconnectRef_); | 295 this.hangoutPort_.onDisconnect.removeListener(this.onHangoutDisconnectRef_); |
303 this.hangoutPort_.disconnect(); | 296 this.hangoutPort_.disconnect(); |
304 this.hangoutPort_ = null; | 297 this.hangoutPort_ = null; |
305 } | 298 } |
306 | 299 |
307 if (this.onDisconnectCallback_) { | 300 if (this.onDisconnectCallback_) { |
308 this.onDisconnectCallback_(this); | 301 this.onDisconnectCallback_(this); |
309 this.onDisconnectCallback_ = null; | 302 this.onDisconnectCallback_ = null; |
310 } | 303 } |
311 }; | 304 }; |
| 305 |
| 306 /** |
| 307 * @param {chrome.runtime.Port} port |
| 308 * @param {string|Error} error |
| 309 * @param {?{method:string, data:Object.<string,*>}=} opt_incomingMessage |
| 310 * @private |
| 311 */ |
| 312 remoting.It2MeHelperChannel.prototype.sendErrorResponse_ = |
| 313 function(port, error, opt_incomingMessage) { |
| 314 if (error instanceof Error) { |
| 315 error = error.message; |
| 316 } |
| 317 |
| 318 console.error('Error responding to message method:' + |
| 319 (opt_incomingMessage ? opt_incomingMessage.method : 'null') + |
| 320 ' error:' + error); |
| 321 port.postMessage({ |
| 322 method: remoting.It2MeHelperChannel.HangoutMessageTypes.ERROR, |
| 323 message: error, |
| 324 request: opt_incomingMessage |
| 325 }); |
| 326 }; |
OLD | NEW |