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
3 // found in the LICENSE file.
7 * The deserialized form of the chromoting host as returned by Apiary.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
20 * Note that the object has more fields than are detailed below--these
21 * are just the ones that we refer to directly.
23 * TODO(kelvinp):Make fields private and expose them via getters.
26 remoting.Host = function() {
38 this.hostVersion = '';
39 /** @type {Array<string>} */
40 this.tokenUrlPatterns = [];
42 this.updatedTime = '';
44 this.hostOfflineReason = '';
45 /** @type {remoting.Host.Options} */
46 this.options = new remoting.Host.Options(this.hostId);
51 * @param {string} hostId
54 remoting.Host.Options = function(hostId) {
56 this.hostId_ = hostId;
57 /** @type {boolean} */
58 this.shrinkToFit = true;
59 /** @type {boolean} */
60 this.resizeToClient = true;
64 this.desktopScale = 1;
67 remoting.Host.Options.prototype.save = function() {
68 // TODO(kelvinp): Migrate pairingInfo to use this class as well and get rid of
69 // remoting.HostSettings.
70 remoting.HostSettings.save(this.hostId_, this);
74 /** @return {Promise} A promise that resolves when the settings are loaded. */
75 remoting.Host.Options.prototype.load = function() {
77 return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then(
79 * @param {Object.<string|boolean|number>} options
82 // Must be defaulted to true so that app-remoting can resize the host
84 // TODO(kelvinp): Uses a separate host options for app-remoting that
85 // hardcodes resizeToClient to true.
87 getBooleanAttr(options, 'resizeToClient', true);
88 that.shrinkToFit = getBooleanAttr(options, 'shrinkToFit', true);
89 that.desktopScale = getNumberAttr(options, 'desktopScale', 1);
90 that.remapKeys = getStringAttr(options, 'remapKeys', '');
95 * Determine whether a host needs to be manually updated. This is the case if
96 * the host's major version number is more than 1 lower than that of the web-
97 * app (a difference of 1 is tolerated due to the different update mechanisms)
98 * and if the host is on-line (off-line hosts are not expected to auto-update).
100 * @param {remoting.Host} host The host information from the directory.
101 * @param {string|number} webappVersion The version number of the web-app, in
102 * either dotted-decimal notation notation, or directly represented by the
104 * @return {boolean} True if the host is on-line but out-of-date.
106 remoting.Host.needsUpdate = function(host, webappVersion) {
107 if (host.status != 'ONLINE') {
110 var hostMajorVersion = parseInt(host.hostVersion, 10);
111 if (isNaN(hostMajorVersion)) {
112 // Host versions 26 and higher include the version number in heartbeats,
113 // so if it's missing then the host is at most version 25.
114 hostMajorVersion = 25;
116 return (parseInt(webappVersion, 10) - hostMajorVersion) > 1;