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 * 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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 remoting.HangoutSession.prototype.init = function() { | 36 remoting.HangoutSession.prototype.init = function() { |
37 var portName = 'it2me.helper.webapp@' + this.senderId_; | 37 var portName = 'it2me.helper.webapp@' + this.senderId_; |
38 this.port_ = chrome.runtime.connect({name: portName}); | 38 this.port_ = chrome.runtime.connect({name: portName}); |
39 | 39 |
40 remoting.hangoutSessionEvents.addEventListener( | 40 remoting.hangoutSessionEvents.addEventListener( |
41 remoting.hangoutSessionEvents.sessionStateChanged, | 41 remoting.hangoutSessionEvents.sessionStateChanged, |
42 this.onSessionStateChanged_.bind(this)); | 42 this.onSessionStateChanged_.bind(this)); |
43 }; | 43 }; |
44 | 44 |
45 /** | 45 /** |
46 * @param {remoting.ClientSession.State} state | 46 * @param {remoting.ClientSession.State=} state |
47 */ | 47 */ |
48 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { | 48 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { |
49 var State = remoting.ClientSession.State; | 49 var State = remoting.ClientSession.State; |
50 try { | 50 try { |
51 this.port_.postMessage({method: 'sessionStateChanged', state: state}); | 51 this.port_.postMessage({method: 'sessionStateChanged', state: state}); |
52 } catch (e) { | 52 } catch (/** @type {*} */ e) { |
53 // postMessage will throw an exception if the port is disconnected. | 53 // postMessage will throw an exception if the port is disconnected. |
54 // We can safely ignore this exception. | 54 // We can safely ignore this exception. |
55 var error = /** @type {Error} */ e; | 55 var error = /** @type {Error} */ (e); |
56 console.error(error); | 56 console.error(error); |
57 } finally { | 57 } finally { |
58 if (state === State.FAILED || state === State.CLOSED) { | 58 if (state === State.FAILED || state === State.CLOSED) { |
59 // close the current window | 59 // close the current window |
60 if (base.isAppsV2()) { | 60 if (base.isAppsV2()) { |
61 chrome.app.window.current().close(); | 61 chrome.app.window.current().close(); |
62 } else { | 62 } else { |
63 window.close(); | 63 window.close(); |
64 } | 64 } |
65 } | 65 } |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 | 69 |
70 /** | 70 /** |
71 * remoting.clientSession does not exist until the session is connected. | 71 * remoting.clientSession does not exist until the session is connected. |
72 * hangoutSessionEvents serves as a global event source to plumb session | 72 * hangoutSessionEvents serves as a global event source to plumb session |
73 * state changes until we cleanup clientSession and sessionConnector. | 73 * state changes until we cleanup clientSession and sessionConnector. |
74 * @type {base.EventSource} | 74 * @type {base.EventSource} |
75 */ | 75 */ |
76 remoting.hangoutSessionEvents = new base.EventSource(); | 76 remoting.hangoutSessionEvents = new base.EventSource(); |
77 | 77 |
78 /** @type {string} */ | 78 /** @type {string} */ |
79 remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged"; | 79 remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged"; |
80 | 80 |
81 remoting.hangoutSessionEvents.defineEvents( | 81 remoting.hangoutSessionEvents.defineEvents( |
82 [remoting.hangoutSessionEvents.sessionStateChanged]); | 82 [remoting.hangoutSessionEvents.sessionStateChanged]); |
OLD | NEW |