Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: remoting/webapp/hangout_session.js

Issue 468693002: Hangouts remote desktop part III - It2MeService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * Class to communicate with the background scripts via chrome runtime 7 * Class to communicate with the background scripts via chrome runtime
8 * messages to 8 * messages to
9 * 1. Forward session state notifications 9 * 1. Forward session state notifications
10 * 2. Closes the window when the session terminates 10 * 2. Closes the window when the session terminates
11 */ 11 */
12 12
13 'use strict'; 13 'use strict';
14 14
15 /** @suppress {duplicate} */ 15 /** @suppress {duplicate} */
16 var remoting = remoting || {}; 16 var remoting = remoting || {};
17 17
18 /** 18 /**
19 * @constructor 19 * @constructor
20 * @param {string} senderId id of the current tab or window.
20 */ 21 */
21 remoting.HangoutSession = function() { 22 remoting.HangoutSession = function(senderId) {
22 /** 23 /**
23 * @private 24 * @private
24 * @type {chrome.runtime.Port} 25 * @type {chrome.runtime.Port}
25 */ 26 */
26 this.port_ = null; 27 this.port_ = null;
28
29 /**
30 * @private
31 * @type {string}
32 */
33 this.senderId_ = senderId;
27 }; 34 };
28 35
29 remoting.HangoutSession.prototype.init = function() { 36 remoting.HangoutSession.prototype.init = function() {
30 this.port_ = chrome.runtime.connect({name: 'it2me.helper.webapp'}); 37 var portName = 'it2me.helper.webapp@' + this.senderId_;
38 this.port_ = chrome.runtime.connect({name: portName});
31 39
32 remoting.hangoutSessionEvents.addEventListener( 40 remoting.hangoutSessionEvents.addEventListener(
33 remoting.hangoutSessionEvents.sessionStateChanged, 41 remoting.hangoutSessionEvents.sessionStateChanged,
34 this.onSessionStateChanged_.bind(this)); 42 this.onSessionStateChanged_.bind(this));
35 }; 43 };
36 44
37 /** 45 /**
38 * @param {remoting.ClientSession.State} state 46 * @param {remoting.ClientSession.State} state
39 */ 47 */
40 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { 48 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) {
41 var State = remoting.ClientSession.State; 49 var State = remoting.ClientSession.State;
42 try { 50 try {
43 this.port_.postMessage({method: 'sessionStateChanged', state: state}); 51 this.port_.postMessage({method: 'sessionStateChanged', state: state});
44 } catch (e) { 52 } catch (e) {
45 // postMessage will throw an exception if the port is disconnected. 53 // postMessage will throw an exception if the port is disconnected.
46 // We can safely ignore this exception. 54 // We can safely ignore this exception.
55 var error = /** @type{Error} */ e;
Jamie 2014/08/13 01:44:53 Nit: Space after @type.
kelvinp 2014/08/13 23:44:11 Done.
56 console.error(error);
47 } finally { 57 } finally {
48 if (state === State.FAILED || state === State.CLOSED) { 58 if (state === State.FAILED || state === State.CLOSED) {
49 // close the current window 59 // close the current window
50 if (remoting.isAppsV2) { 60 if (remoting.isAppsV2) {
51 chrome.app.window.current().close(); 61 chrome.app.window.current().close();
52 } else { 62 } else {
53 window.close(); 63 window.close();
54 } 64 }
55 } 65 }
56 } 66 }
57 }; 67 };
58 68
59 69
60 /** 70 /**
61 * remoting.clientSession does not exist until the session is connected. 71 * remoting.clientSession does not exist until the session is connected.
62 * hangoutSessionEvents serves as a global event source to plumb session 72 * hangoutSessionEvents serves as a global event source to plumb session
63 * state changes until we cleanup clientSession and sessionConnector. 73 * state changes until we cleanup clientSession and sessionConnector.
64 * @type {base.EventSource} 74 * @type {base.EventSource}
65 */ 75 */
66 remoting.hangoutSessionEvents = new base.EventSource(); 76 remoting.hangoutSessionEvents = new base.EventSource();
67 77
68 /** @type {string} */ 78 /** @type {string} */
69 remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged"; 79 remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged";
70 80
71 remoting.hangoutSessionEvents.defineEvents( 81 remoting.hangoutSessionEvents.defineEvents(
72 [remoting.hangoutSessionEvents.sessionStateChanged]); 82 [remoting.hangoutSessionEvents.sessionStateChanged]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698