OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** @constructor */ | 10 /** @constructor */ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 var e = new Array(); | 113 var e = new Array(); |
114 for (var i = 0; i < 8; i++) { | 114 for (var i = 0; i < 8; i++) { |
115 e[i] = (/** @type {number} */random[i] + 0x10000). | 115 e[i] = (/** @type {number} */random[i] + 0x10000). |
116 toString(16).substring(1); | 116 toString(16).substring(1); |
117 } | 117 } |
118 return e[0] + e[1] + '-' + e[2] + "-" + e[3] + '-' + | 118 return e[0] + e[1] + '-' + e[2] + "-" + e[3] + '-' + |
119 e[4] + '-' + e[5] + e[6] + e[7]; | 119 e[4] + '-' + e[5] + e[6] + e[7]; |
120 }; | 120 }; |
121 | 121 |
122 var newHostId = generateUuid(); | 122 var newHostId = generateUuid(); |
123 // TODO(jamiewalch): Create an unprivileged API to get the host id from the | |
124 // plugin instead of storing it locally (crbug.com/121518). | |
125 window.localStorage.setItem('me2me-host-id', newHostId); | |
126 | 123 |
127 /** @param {function(remoting.HostController.AsyncResult):void} callback | 124 /** @param {function(remoting.HostController.AsyncResult):void} callback |
128 * @param {remoting.HostController.AsyncResult} result | 125 * @param {remoting.HostController.AsyncResult} result |
129 * @param {string} hostName */ | 126 * @param {string} hostName */ |
130 function onStarted(callback, result, hostName) { | 127 function onStarted(callback, result, hostName) { |
131 if (result == remoting.HostController.AsyncResult.OK) { | 128 if (result == remoting.HostController.AsyncResult.OK) { |
132 // Create a dummy remoting.Host instance to represent the local host. | 129 // Create a dummy remoting.Host instance to represent the local host. |
133 // Refreshing the list is no good in general, because the directory | 130 // Refreshing the list is no good in general, because the directory |
134 // information won't be in sync for several seconds. We don't know the | 131 // information won't be in sync for several seconds. We don't know the |
135 // host JID or public key, but they can be missing from the cache with | 132 // host JID or public key, but they can be missing from the cache with |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 * @return {void} Nothing. | 214 * @return {void} Nothing. |
218 */ | 215 */ |
219 remoting.HostController.prototype.stop = function(callback) { | 216 remoting.HostController.prototype.stop = function(callback) { |
220 /** @type {remoting.HostController} */ | 217 /** @type {remoting.HostController} */ |
221 var that = this; | 218 var that = this; |
222 | 219 |
223 /** @param {remoting.HostController.AsyncResult} result */ | 220 /** @param {remoting.HostController.AsyncResult} result */ |
224 function onStopped(result) { | 221 function onStopped(result) { |
225 if (that.localHost && that.localHost.hostId) | 222 if (that.localHost && that.localHost.hostId) |
226 remoting.HostList.unregisterHostById(that.localHost.hostId); | 223 remoting.HostList.unregisterHostById(that.localHost.hostId); |
227 window.localStorage.removeItem('me2me-host-id'); | |
228 callback(result); | 224 callback(result); |
229 }; | 225 }; |
230 this.plugin_.stopDaemon(onStopped); | 226 this.plugin_.stopDaemon(onStopped); |
231 }; | 227 }; |
232 | 228 |
233 /** | 229 /** |
234 * @param {string} newPin The new PIN to set | 230 * @param {string} newPin The new PIN to set |
235 * @param {function(remoting.HostController.AsyncResult):void} callback | 231 * @param {function(remoting.HostController.AsyncResult):void} callback |
236 * Callback to be called when finished. | 232 * Callback to be called when finished. |
237 * @return {void} Nothing. | 233 * @return {void} Nothing. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 this.hostTableEntry_ = null; | 293 this.hostTableEntry_ = null; |
298 } | 294 } |
299 }; | 295 }; |
300 | 296 |
301 /** | 297 /** |
302 * Update the internal state so that the local host can be correctly filtered | 298 * Update the internal state so that the local host can be correctly filtered |
303 * out of the host list. | 299 * out of the host list. |
304 * | 300 * |
305 * @param {remoting.HostList} hostList The new host list, returned by the | 301 * @param {remoting.HostList} hostList The new host list, returned by the |
306 * Chromoting service. | 302 * Chromoting service. |
307 * @param {function():void} onDone Completion callback. TODO(jamiewalch): For | 303 * @param {function():void} onDone Completion callback. |
308 * now, this is synchronous and reads the host id from local storage. In | |
309 * the future, it will asynchronously read the host id from the plugin | |
310 * (crbug.com/121518). | |
311 */ | 304 */ |
312 remoting.HostController.prototype.onHostListRefresh = | 305 remoting.HostController.prototype.onHostListRefresh = |
313 function(hostList, onDone) { | 306 function(hostList, onDone) { |
314 var hostId = window.localStorage.getItem('me2me-host-id'); | 307 /** @type {remoting.HostController} */ |
315 if (hostId && typeof(hostId) == 'string') { | 308 var that = this; |
316 this.setHost(hostList.getHostForId(/** @type{string} */(hostId))); | 309 /** @param {string} configStr */ |
317 } else { | 310 function onConfig(configStr) { |
318 this.setHost(null); | 311 var config = /** @type {Object.<string,string>} */ JSON.parse(configStr); |
319 } | 312 if (('host_id' in config) && typeof config['host_id'] == 'string') { |
320 onDone(); | 313 var hostId = config['host_id']; |
simonmorris
2012/04/23 17:29:18
It's less repetitive to test for hostId not being
Jamie
2012/04/23 20:24:25
I want to check that host_id is a string, but you'
| |
314 that.setHost(hostList.getHostForId(hostId)); | |
315 } else { | |
316 that.setHost(null); | |
317 } | |
318 onDone(); | |
319 }; | |
320 this.plugin_.getDaemonConfig(onConfig); | |
321 }; | 321 }; |
322 | 322 |
323 /** @type {remoting.HostController} */ | 323 /** @type {remoting.HostController} */ |
324 remoting.hostController = null; | 324 remoting.hostController = null; |
OLD | NEW |