-
Notifications
You must be signed in to change notification settings - Fork 8
/
host.js
119 lines (107 loc) · 3.57 KB
/
host.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* The deserialized form of the chromoting host as returned by Apiary.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
(function() {
'use strict';
/**
* Note that the object has more fields than are detailed below--these
* are just the ones that we refer to directly.
*
* TODO(kelvinp):Make fields private and expose them via getters.
* @constructor
*/
remoting.Host = function() {
/** @type {string} */
this.hostName = '';
/** @type {string} */
this.hostId = '';
/** @type {string} */
this.status = '';
/** @type {string} */
this.jabberId = '';
/** @type {string} */
this.publicKey = '';
/** @type {string} */
this.hostVersion = '';
/** @type {Array<string>} */
this.tokenUrlPatterns = [];
/** @type {string} */
this.updatedTime = '';
/** @type {string} */
this.hostOfflineReason = '';
/** @type {remoting.Host.Options} */
this.options = new remoting.Host.Options(this.hostId);
};
/**
* @constructor
* @param {string} hostId
* @struct
*/
remoting.Host.Options = function(hostId) {
/** @private */
this.hostId_ = hostId;
/** @type {boolean} */
this.shrinkToFit = true;
/** @type {boolean} */
this.resizeToClient = true;
/** @type {string} */
this.remapKeys = '';
/** @type {number} */
this.desktopScale = 1;
};
remoting.Host.Options.prototype.save = function() {
// TODO(kelvinp): Migrate pairingInfo to use this class as well and get rid of
// remoting.HostSettings.
remoting.HostSettings.save(this.hostId_, this);
};
/** @return {Promise} A promise that resolves when the settings are loaded. */
remoting.Host.Options.prototype.load = function() {
var that = this;
return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then(
/**
* @param {Object.<string|boolean|number>} options
*/
function(options) {
// Must be defaulted to true so that app-remoting can resize the host
// upon launching.
// TODO(kelvinp): Uses a separate host options for app-remoting that
// hardcodes resizeToClient to true.
that.resizeToClient =
getBooleanAttr(options, 'resizeToClient', true);
that.shrinkToFit = getBooleanAttr(options, 'shrinkToFit', true);
that.desktopScale = getNumberAttr(options, 'desktopScale', 1);
that.remapKeys = getStringAttr(options, 'remapKeys', '');
});
};
/**
* Determine whether a host needs to be manually updated. This is the case if
* the host's major version number is more than 1 lower than that of the web-
* app (a difference of 1 is tolerated due to the different update mechanisms)
* and if the host is on-line (off-line hosts are not expected to auto-update).
*
* @param {remoting.Host} host The host information from the directory.
* @param {string|number} webappVersion The version number of the web-app, in
* either dotted-decimal notation notation, or directly represented by the
* major version.
* @return {boolean} True if the host is on-line but out-of-date.
*/
remoting.Host.needsUpdate = function(host, webappVersion) {
if (host.status != 'ONLINE') {
return false;
}
var hostMajorVersion = parseInt(host.hostVersion, 10);
if (isNaN(hostMajorVersion)) {
// Host versions 26 and higher include the version number in heartbeats,
// so if it's missing then the host is at most version 25.
hostMajorVersion = 25;
}
return (parseInt(webappVersion, 10) - hostMajorVersion) > 1;
};
})();