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). |
11 * | 11 * |
12 * It runs in the background page and contains two chrome.runtime.Port objects, | 12 * It runs in the background page and contains two chrome.runtime.Port objects, |
13 * respresenting connections to the webapp and hangout, respectively. | 13 * representing connections to the webapp and hangout, respectively. |
14 * | 14 * |
15 * Connection is always initiated from Hangouts. | 15 * Connection is always initiated from Hangouts by calling |
| 16 * var port = chrome.runtime.connect({name:'it2me.helper.hangout'}, extId). |
| 17 * port.postMessage('hello') |
| 18 * If the webapp is not installed, |port.onDisconnect| will fire. |
| 19 * If the webapp is installed, Hangouts will receive a hello response with the |
| 20 * list of supported features. |
16 * | 21 * |
17 * Hangout It2MeHelperChannel Chrome Remote Desktop | 22 * Hangout It2MeHelperChannel Chrome Remote Desktop |
18 * |-----runtime.connect() ------>| | | 23 * |-----runtime.connect() ------>| | |
19 * |------connect message-------->| | | 24 * |--------hello message-------->| | |
| 25 * | |<-----helloResponse message-----| |
| 26 * |-------connect message------->| | |
20 * | |-------appLauncher.launch()---->| | 27 * | |-------appLauncher.launch()---->| |
21 * | |<------runtime.connect()------- | | 28 * | |<------runtime.connect()------- | |
22 * | |<-----sessionStateChanged------ | | 29 * | |<-----sessionStateChanged------ | |
23 * |<----sessionStateChanged------| | | 30 * |<----sessionStateChanged------| | |
24 * | 31 * |
25 * Disconnection can be initiated from either side: | 32 * Disconnection can be initiated from either side: |
26 * 1. In the normal flow initiated from hangout | 33 * 1. In the normal flow initiated from hangout |
27 * Hangout It2MeHelperChannel Chrome Remote Desktop | 34 * Hangout It2MeHelperChannel Chrome Remote Desktop |
28 * |-----disconnect message------>| | | 35 * |-----disconnect message------>| | |
29 * |<-sessionStateChanged(CLOSED)-| | | 36 * |<-sessionStateChanged(CLOSED)-| | |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 this.onDisconnectCallback_ = onDisconnectCallback; | 109 this.onDisconnectCallback_ = onDisconnectCallback; |
103 | 110 |
104 this.onWebappMessageRef_ = this.onWebappMessage_.bind(this); | 111 this.onWebappMessageRef_ = this.onWebappMessage_.bind(this); |
105 this.onWebappDisconnectRef_ = this.onWebappDisconnect_.bind(this); | 112 this.onWebappDisconnectRef_ = this.onWebappDisconnect_.bind(this); |
106 this.onHangoutMessageRef_ = this.onHangoutMessage_.bind(this); | 113 this.onHangoutMessageRef_ = this.onHangoutMessage_.bind(this); |
107 this.onHangoutDisconnectRef_ = this.onHangoutDisconnect_.bind(this); | 114 this.onHangoutDisconnectRef_ = this.onHangoutDisconnect_.bind(this); |
108 }; | 115 }; |
109 | 116 |
110 /** @enum {string} */ | 117 /** @enum {string} */ |
111 remoting.It2MeHelperChannel.HangoutMessageTypes = { | 118 remoting.It2MeHelperChannel.HangoutMessageTypes = { |
| 119 HELLO: 'hello', |
| 120 HELLO_RESPONSE: 'helloResponse', |
112 CONNECT: 'connect', | 121 CONNECT: 'connect', |
113 DISCONNECT: 'disconnect' | 122 DISCONNECT: 'disconnect' |
114 }; | 123 }; |
115 | 124 |
116 /** @enum {string} */ | 125 /** @enum {string} */ |
| 126 remoting.It2MeHelperChannel.Features = { |
| 127 REMOTE_ASSISTANCE: 'remoteAssistance' |
| 128 }; |
| 129 |
| 130 /** @enum {string} */ |
117 remoting.It2MeHelperChannel.WebappMessageTypes = { | 131 remoting.It2MeHelperChannel.WebappMessageTypes = { |
118 SESSION_STATE_CHANGED: 'sessionStateChanged' | 132 SESSION_STATE_CHANGED: 'sessionStateChanged' |
119 }; | 133 }; |
120 | 134 |
121 remoting.It2MeHelperChannel.prototype.init = function() { | 135 remoting.It2MeHelperChannel.prototype.init = function() { |
122 this.hangoutPort_.onMessage.addListener(this.onHangoutMessageRef_); | 136 this.hangoutPort_.onMessage.addListener(this.onHangoutMessageRef_); |
123 this.hangoutPort_.onDisconnect.addListener(this.onHangoutDisconnectRef_); | 137 this.hangoutPort_.onDisconnect.addListener(this.onHangoutDisconnectRef_); |
124 }; | 138 }; |
125 | 139 |
126 /** @return {string} */ | 140 /** @return {string} */ |
127 remoting.It2MeHelperChannel.prototype.instanceId = function() { | 141 remoting.It2MeHelperChannel.prototype.instanceId = function() { |
128 return this.instanceId_; | 142 return this.instanceId_; |
129 }; | 143 }; |
130 | 144 |
131 /** | 145 /** |
132 * @param {{method:string, data:Object.<string,*>}} message | 146 * @param {{method:string, data:Object.<string,*>}} message |
133 * @return {boolean} whether the message is handled or not. | 147 * @return {boolean} whether the message is handled or not. |
134 * @private | 148 * @private |
135 */ | 149 */ |
136 remoting.It2MeHelperChannel.prototype.onHangoutMessage_ = function(message) { | 150 remoting.It2MeHelperChannel.prototype.onHangoutMessage_ = function(message) { |
137 try { | 151 try { |
138 var MessageTypes = remoting.It2MeHelperChannel.HangoutMessageTypes; | 152 var MessageTypes = remoting.It2MeHelperChannel.HangoutMessageTypes; |
139 switch (message.method) { | 153 switch (message.method) { |
140 case MessageTypes.CONNECT: | 154 case MessageTypes.CONNECT: |
141 this.launchWebapp_(message); | 155 this.launchWebapp_(message); |
142 return true; | 156 return true; |
143 case MessageTypes.DISCONNECT: | 157 case MessageTypes.DISCONNECT: |
144 this.closeWebapp_(message); | 158 this.closeWebapp_(message); |
145 return true; | 159 return true; |
| 160 case MessageTypes.HELLO: |
| 161 this.hangoutPort_.postMessage({ |
| 162 method: MessageTypes.HELLO_RESPONSE, |
| 163 supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) |
| 164 }); |
| 165 return true; |
146 } | 166 } |
| 167 throw new Error('Unknown message method=' + message.method); |
147 } catch(e) { | 168 } catch(e) { |
148 var error = /** @type {Error} */ e; | 169 var error = /** @type {Error} */ e; |
149 console.error(error); | 170 console.error(error); |
150 this.hangoutPort_.postMessage({ | 171 this.hangoutPort_.postMessage({ |
151 method: message.method + 'Response', | 172 method: message.method + 'Response', |
152 error: error.message | 173 error: error.message |
153 }); | 174 }); |
154 } | 175 } |
155 return false; | 176 return false; |
156 }; | 177 }; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 this.hangoutPort_.onDisconnect.removeListener(this.onHangoutDisconnectRef_); | 302 this.hangoutPort_.onDisconnect.removeListener(this.onHangoutDisconnectRef_); |
282 this.hangoutPort_.disconnect(); | 303 this.hangoutPort_.disconnect(); |
283 this.hangoutPort_ = null; | 304 this.hangoutPort_ = null; |
284 } | 305 } |
285 | 306 |
286 if (this.onDisconnectCallback_) { | 307 if (this.onDisconnectCallback_) { |
287 this.onDisconnectCallback_(this); | 308 this.onDisconnectCallback_(this); |
288 this.onDisconnectCallback_ = null; | 309 this.onDisconnectCallback_ = null; |
289 } | 310 } |
290 }; | 311 }; |
OLD | NEW |