OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; |
| 9 |
| 10 /** |
| 11 * Entry point ('load' handler) for Chromoting webapp. |
| 12 */ |
| 13 remoting.initChromoting = function() { |
| 14 remoting.initGlobalObjects(); |
| 15 remoting.initIdentity(); |
| 16 remoting.initIdentityEmail(remoting.onEmailAvailable); |
| 17 |
| 18 remoting.initEventHandlers(); |
| 19 |
| 20 if (base.isAppsV2()) { |
| 21 remoting.fullscreen = new remoting.FullscreenAppsV2(); |
| 22 remoting.windowFrame = new remoting.WindowFrame( |
| 23 document.getElementById('title-bar')); |
| 24 remoting.optionsMenu = remoting.windowFrame.createOptionsMenu(); |
| 25 } else { |
| 26 remoting.fullscreen = new remoting.FullscreenAppsV1(); |
| 27 remoting.toolbar = new remoting.Toolbar( |
| 28 document.getElementById('session-toolbar')); |
| 29 remoting.optionsMenu = remoting.toolbar.createOptionsMenu(); |
| 30 } |
| 31 |
| 32 remoting.initHostlist_(); |
| 33 |
| 34 var homeFeedback = new remoting.MenuButton( |
| 35 document.getElementById('help-feedback-main')); |
| 36 var toolbarFeedback = new remoting.MenuButton( |
| 37 document.getElementById('help-feedback-toolbar')); |
| 38 remoting.manageHelpAndFeedback( |
| 39 document.getElementById('title-bar')); |
| 40 remoting.manageHelpAndFeedback( |
| 41 document.getElementById('help-feedback-toolbar')); |
| 42 remoting.manageHelpAndFeedback( |
| 43 document.getElementById('help-feedback-main')); |
| 44 |
| 45 remoting.windowShape.updateClientWindowShape(); |
| 46 |
| 47 remoting.showOrHideIT2MeUi(); |
| 48 remoting.showOrHideMe2MeUi(); |
| 49 |
| 50 // For Apps v1, check the tab type to warn the user if they are not getting |
| 51 // the best keyboard experience. |
| 52 if (!base.isAppsV2() && !remoting.platformIsMac()) { |
| 53 /** @param {boolean} isWindowed */ |
| 54 var onIsWindowed = function(isWindowed) { |
| 55 if (!isWindowed) { |
| 56 document.getElementById('startup-mode-box-me2me').hidden = false; |
| 57 document.getElementById('startup-mode-box-it2me').hidden = false; |
| 58 } |
| 59 }; |
| 60 isWindowed_(onIsWindowed); |
| 61 } |
| 62 |
| 63 remoting.ClientPlugin.factory.preloadPlugin(); |
| 64 |
| 65 } |
| 66 |
| 67 /** |
| 68 * Display the user's email address and allow access to the rest of the app, |
| 69 * including parsing URL parameters. |
| 70 * |
| 71 * @param {string} email The user's email address. |
| 72 * @return {void} Nothing. |
| 73 */ |
| 74 remoting.onEmailAvailable = function(email, fullName) { |
| 75 document.getElementById('current-email').innerText = email; |
| 76 document.getElementById('get-started-it2me').disabled = false; |
| 77 document.getElementById('get-started-me2me').disabled = false; |
| 78 }; |
| 79 |
| 80 /** |
| 81 * Initialize the host list. |
| 82 */ |
| 83 remoting.initHostlist_ = function() { |
| 84 remoting.hostList = new remoting.HostList( |
| 85 document.getElementById('host-list'), |
| 86 document.getElementById('host-list-empty'), |
| 87 document.getElementById('host-list-error-message'), |
| 88 document.getElementById('host-list-refresh-failed-button'), |
| 89 document.getElementById('host-list-loading-indicator')); |
| 90 |
| 91 isHostModeSupported_().then( |
| 92 /** @param {Boolean} supported */ |
| 93 function(supported){ |
| 94 if (supported) { |
| 95 var noShare = document.getElementById('chrome-os-no-share'); |
| 96 noShare.parentNode.removeChild(noShare); |
| 97 } else { |
| 98 var button = document.getElementById('share-button'); |
| 99 button.disabled = true; |
| 100 } |
| 101 }); |
| 102 |
| 103 /** |
| 104 * @return {Promise} A promise that resolves to the id of the current |
| 105 * containing tab/window. |
| 106 */ |
| 107 var getCurrentId = function () { |
| 108 if (base.isAppsV2()) { |
| 109 return Promise.resolve(chrome.app.window.current().id); |
| 110 } |
| 111 |
| 112 /** |
| 113 * @param {function(*=):void} resolve |
| 114 * @param {function(*=):void} reject |
| 115 */ |
| 116 return new Promise(function(resolve, reject) { |
| 117 /** @param {chrome.Tab} tab */ |
| 118 chrome.tabs.getCurrent(function(tab){ |
| 119 if (tab) { |
| 120 resolve(String(tab.id)); |
| 121 } |
| 122 reject('Cannot retrieve the current tab.'); |
| 123 }); |
| 124 }); |
| 125 }; |
| 126 |
| 127 var onLoad = function() { |
| 128 // Parse URL parameters. |
| 129 var urlParams = getUrlParameters_(); |
| 130 if ('mode' in urlParams) { |
| 131 if (urlParams['mode'] === 'me2me') { |
| 132 var hostId = urlParams['hostId']; |
| 133 remoting.connectMe2Me(hostId); |
| 134 return; |
| 135 } else if (urlParams['mode'] === 'hangout') { |
| 136 /** @param {*} id */ |
| 137 getCurrentId().then(function(id) { |
| 138 /** @type {string} */ |
| 139 var accessCode = urlParams['accessCode']; |
| 140 remoting.ensureSessionConnector_(); |
| 141 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 142 remoting.connector.connectIT2Me(accessCode); |
| 143 |
| 144 document.body.classList.add('hangout-remote-desktop'); |
| 145 var senderId = /** @type {string} */ String(id); |
| 146 var hangoutSession = new remoting.HangoutSession(senderId); |
| 147 hangoutSession.init(); |
| 148 }); |
| 149 return; |
| 150 } |
| 151 } |
| 152 // No valid URL parameters, start up normally. |
| 153 remoting.initHomeScreenUi(); |
| 154 } |
| 155 remoting.hostList.load(onLoad); |
| 156 } |
| 157 |
| 158 /** |
| 159 * initHomeScreenUi is called if the app is not starting up in session mode, |
| 160 * and also if the user cancels pin entry or the connection in session mode. |
| 161 */ |
| 162 remoting.initHomeScreenUi = function() { |
| 163 remoting.hostController = new remoting.HostController(); |
| 164 remoting.setMode(remoting.AppMode.HOME); |
| 165 remoting.hostSetupDialog = |
| 166 new remoting.HostSetupDialog(remoting.hostController); |
| 167 var dialog = document.getElementById('paired-clients-list'); |
| 168 var message = document.getElementById('paired-client-manager-message'); |
| 169 var deleteAll = document.getElementById('delete-all-paired-clients'); |
| 170 var close = document.getElementById('close-paired-client-manager-dialog'); |
| 171 var working = document.getElementById('paired-client-manager-dialog-working'); |
| 172 var error = document.getElementById('paired-client-manager-dialog-error'); |
| 173 var noPairedClients = document.getElementById('no-paired-clients'); |
| 174 remoting.pairedClientManager = |
| 175 new remoting.PairedClientManager(remoting.hostController, dialog, message, |
| 176 deleteAll, close, noPairedClients, |
| 177 working, error); |
| 178 // Display the cached host list, then asynchronously update and re-display it. |
| 179 remoting.updateLocalHostState(); |
| 180 remoting.hostList.refresh(remoting.updateLocalHostState); |
| 181 remoting.butterBar = new remoting.ButterBar(); |
| 182 }; |
| 183 |
| 184 /** |
| 185 * Fetches local host state and updates the DOM accordingly. |
| 186 */ |
| 187 remoting.updateLocalHostState = function() { |
| 188 /** |
| 189 * @param {remoting.HostController.State} state Host state. |
| 190 */ |
| 191 var onHostState = function(state) { |
| 192 if (state == remoting.HostController.State.STARTED) { |
| 193 remoting.hostController.getLocalHostId(onHostId.bind(null, state)); |
| 194 } else { |
| 195 onHostId(state, null); |
| 196 } |
| 197 }; |
| 198 |
| 199 /** |
| 200 * @param {remoting.HostController.State} state Host state. |
| 201 * @param {string?} hostId Host id. |
| 202 */ |
| 203 var onHostId = function(state, hostId) { |
| 204 remoting.hostList.setLocalHostStateAndId(state, hostId); |
| 205 remoting.hostList.display(); |
| 206 }; |
| 207 |
| 208 /** |
| 209 * @param {boolean} response True if the feature is present. |
| 210 */ |
| 211 var onHasFeatureResponse = function(response) { |
| 212 /** |
| 213 * @param {remoting.Error} error |
| 214 */ |
| 215 var onError = function(error) { |
| 216 console.error('Failed to get pairing status: ' + error); |
| 217 remoting.pairedClientManager.setPairedClients([]); |
| 218 }; |
| 219 |
| 220 if (response) { |
| 221 remoting.hostController.getPairedClients( |
| 222 remoting.pairedClientManager.setPairedClients.bind( |
| 223 remoting.pairedClientManager), |
| 224 onError); |
| 225 } else { |
| 226 console.log('Pairing registry not supported by host.'); |
| 227 remoting.pairedClientManager.setPairedClients([]); |
| 228 } |
| 229 }; |
| 230 |
| 231 remoting.hostController.hasFeature( |
| 232 remoting.HostController.Feature.PAIRING_REGISTRY, onHasFeatureResponse); |
| 233 remoting.hostController.getLocalHostState(onHostState); |
| 234 }; |
| 235 |
| 236 window.addEventListener('load', remoting.initChromoting, false); |
OLD | NEW |