Index: remoting/webapp/remoting.js |
diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js |
index c02a48bda37e80a47f5c4802eaf72827dd565435..7a8e7811cd76c9aa33fe790c638abe82d9ff512b 100644 |
--- a/remoting/webapp/remoting.js |
+++ b/remoting/webapp/remoting.js |
@@ -133,23 +133,52 @@ remoting.init = function() { |
button.disabled = true; |
} |
+ /** |
+ * @return {Promise} A promise that will resolves to the current id of the |
Jamie
2014/08/13 01:44:53
s/resolves/resolve/ (or remove "will").
Jamie
2014/08/13 01:44:54
Remove "current".
kelvinp
2014/08/13 23:44:11
Done.
kelvinp
2014/08/13 23:44:11
Done.
|
+ * current container (tabId or window Id). |
+ */ |
+ var getCurrentId = function () { |
+ if (remoting.isAppsV2) { |
+ return Promise.resolve(chrome.app.window.current().id); |
+ } |
+ |
+ /** |
+ * @param {function(*=):void} resolve |
+ * @param {function(*=):void} reject |
+ */ |
+ return new Promise(function(resolve, reject) { |
+ /** @param {chrome.Tab} tab */ |
+ chrome.tabs.getCurrent(function(tab){ |
+ if (tab) { |
+ resolve(String(tab.id)); |
+ } |
+ reject(); |
Jamie
2014/08/13 01:44:54
I think reject should always specify a reason. I f
kelvinp
2014/08/13 23:44:11
Done.
|
+ }); |
+ }); |
+ }; |
+ |
var onLoad = function() { |
// Parse URL parameters. |
var urlParams = getUrlParameters_(); |
if ('mode' in urlParams) { |
- if (urlParams['mode'] == 'me2me') { |
+ if (urlParams['mode'] === 'me2me') { |
var hostId = urlParams['hostId']; |
remoting.connectMe2Me(hostId); |
return; |
- } else if (urlParams['mode'] == 'hangout') { |
- var accessCode = urlParams['accessCode']; |
- remoting.ensureSessionConnector_(); |
- remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
- remoting.connector.connectIT2Me(accessCode); |
- |
- document.body.classList.add('hangout-remote-desktop'); |
- var hangoutSession = new remoting.HangoutSession(); |
- hangoutSession.init(); |
+ } else if (urlParams['mode'] === 'hangout') { |
+ /** @param {*} id */ |
+ getCurrentId().then(function(id) { |
+ /** @type {string} */ |
+ var accessCode = urlParams['accessCode']; |
+ remoting.ensureSessionConnector_(); |
+ remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
+ remoting.connector.connectIT2Me(accessCode); |
+ |
+ document.body.classList.add('hangout-remote-desktop'); |
+ var senderId = /** @type {string} */ String(id); |
+ var hangoutSession = new remoting.HangoutSession(senderId); |
+ hangoutSession.init(); |
+ }); |
return; |
} |
} |