Chromium Code Reviews| Index: remoting/webapp/background/it2me_helper_channel.js |
| diff --git a/remoting/webapp/background/it2me_helper_channel.js b/remoting/webapp/background/it2me_helper_channel.js |
| index e25c443b6a64cd848bd595b91dbae9ecce908b84..4eae781ae9a1e703b18a0ea3b9b077bfe2d31ea8 100644 |
| --- a/remoting/webapp/background/it2me_helper_channel.js |
| +++ b/remoting/webapp/background/it2me_helper_channel.js |
| @@ -10,13 +10,20 @@ |
| * assistance). |
| * |
| * It runs in the background page and contains two chrome.runtime.Port objects, |
| - * respresenting connections to the webapp and hangout, respectively. |
| + * representing connections to the webapp and hangout, respectively. |
| * |
| - * Connection is always initiated from Hangouts. |
| + * Connection is always initiated from Hangouts by calling |
| + * var port = chrome.runtime.connect({name:'it2me.helper.hangout'}, extId). |
| + * port.postMessage('hello') |
| + * If the webapp is not installed, |port.onDisconnect| will fire. |
| + * If the webapp is installed, Hangouts will receive a hello response with the |
| + * list of supported features. |
| * |
| * Hangout It2MeHelperChannel Chrome Remote Desktop |
| * |-----runtime.connect() ------>| | |
| - * |------connect message-------->| | |
| + * |--------hello message-------->| | |
| + * | |<-----helloResponse message-----| |
| + * |-------connect message------->| | |
| * | |-------appLauncher.launch()---->| |
| * | |<------runtime.connect()------- | |
| * | |<-----sessionStateChanged------ | |
| @@ -109,13 +116,23 @@ remoting.It2MeHelperChannel = |
| /** @enum {string} */ |
| remoting.It2MeHelperChannel.HangoutMessageTypes = { |
| + HELLO: 'hello', |
| + HELLO_RESPONSE: 'helloResponse', |
| CONNECT: 'connect', |
| - DISCONNECT: 'disconnect' |
| + DISCONNECT: 'disconnect', |
| + SESSION_STATE_CHANGED: 'sessionStateChanged', |
| + ERROR: 'error' |
| +}; |
| + |
| +/** @enum {string} */ |
| +remoting.It2MeHelperChannel.Features = { |
| + REMOTE_ASSISTANCE: 'remoteAssistance' |
| }; |
| /** @enum {string} */ |
| remoting.It2MeHelperChannel.WebappMessageTypes = { |
| - SESSION_STATE_CHANGED: 'sessionStateChanged' |
| + SESSION_STATE_CHANGED: 'sessionStateChanged', |
| + ERROR: 'error' |
| }; |
| remoting.It2MeHelperChannel.prototype.init = function() { |
| @@ -143,12 +160,19 @@ remoting.It2MeHelperChannel.prototype.onHangoutMessage_ = function(message) { |
| case MessageTypes.DISCONNECT: |
| this.closeWebapp_(message); |
| return true; |
| + case MessageTypes.HELLO: |
| + this.hangoutPort_.postMessage({ |
| + method: MessageTypes.HELLO_RESPONSE, |
| + supportedFeatures: base.values(remoting.It2MeHelperChannel.Features) |
| + }); |
| + return true; |
| } |
| + throw new Error('Unknown message method=' + message.method); |
| } catch(e) { |
| var error = /** @type {Error} */ e; |
| console.error(error); |
| this.hangoutPort_.postMessage({ |
| - method: message.method + 'Response', |
| + method: MessageTypes.ERROR, |
|
Jamie
2014/08/15 21:57:31
My comment about appending "Response" was just in
kelvinp
2014/08/15 23:25:01
I will make the change in error in later CL's
|
| error: error.message |
| }); |
| } |
| @@ -165,9 +189,10 @@ remoting.It2MeHelperChannel.prototype.closeWebapp_ = |
| function(message) { |
| // TODO(kelvinp): Closing the v2 app currently doesn't disconnect the IT2me |
| // session (crbug.com/402137), so send an explicit notification to Hangouts. |
| + var MessageTypes = remoting.It2MeHelperChannel.HangoutMessageTypes; |
| this.sessionState_ = remoting.ClientSession.State.CLOSED; |
| this.hangoutPort_.postMessage({ |
| - method: 'sessionStateChanged', |
| + method: MessageTypes.SESSION_STATE_CHANGED, |
| state: this.sessionState_ |
| }); |
| this.appLauncher_.close(this.instanceId_); |
| @@ -228,11 +253,12 @@ remoting.It2MeHelperChannel.prototype.onWebappDisconnect_ = function(port) { |
| // If the webapp port got disconnected while the session is still connected, |
| // treat it as an error. |
| var States = remoting.ClientSession.State; |
| + var HangoutMessageTypes = remoting.It2MeHelperChannel.HangoutMessageTypes; |
| if (this.sessionState_ === States.CONNECTING || |
| this.sessionState_ === States.CONNECTED) { |
| this.sessionState_ = States.FAILED; |
| this.hangoutPort_.postMessage({ |
| - method: 'sessionStateChanged', |
| + method: HangoutMessageTypes.SESSION_STATE_CHANGED, |
| state: this.sessionState_ |
| }); |
| } |
| @@ -247,13 +273,16 @@ remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) { |
| try { |
| console.log('It2MeHelperChannel id=' + this.instanceId_ + |
| ' incoming message method=' + message.method); |
| - var MessageTypes = remoting.It2MeHelperChannel.WebappMessageTypes; |
| + var WebappMessageTypes = remoting.It2MeHelperChannel.WebappMessageTypes; |
| + var HangoutMessageTypes = remoting.It2MeHelperChannel.HangoutMessageTypes; |
| switch (message.method) { |
| - case MessageTypes.SESSION_STATE_CHANGED: |
| + case WebappMessageTypes.SESSION_STATE_CHANGED: |
| var state = getNumberAttr(message, 'state'); |
| - this.sessionState_ = |
| - /** @type {remoting.ClientSession.State} */ state; |
| - this.hangoutPort_.postMessage(message); |
| + this.sessionState_ = /** @type {remoting.ClientSession.State} */ state; |
| + this.hangoutPort_.postMessage({ |
| + method: HangoutMessageTypes.SESSION_STATE_CHANGED, |
| + state: state |
| + }); |
|
Jamie
2014/08/15 21:57:31
As above, I like this change, but it doesn't reall
|
| return true; |
| } |
| throw new Error('Unknown message method=' + message.method); |
| @@ -261,7 +290,7 @@ remoting.It2MeHelperChannel.prototype.onWebappMessage_ = function(message) { |
| var error = /** @type {Error} */ e; |
| console.error(error); |
| this.webappPort_.postMessage({ |
| - method: message.method + 'Response', |
| + method: WebappMessageTypes.ERROR, |
| error: error.message |
| }); |
| } |