Home | History | Annotate | Download | only in webapp
      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.
      4 
      5 /**
      6  * @fileoverview
      7  * The deserialized form of the chromoting host as returned by Apiary.
      8  */
      9 
     10 'use strict';
     11 
     12 /** @suppress {duplicate} */
     13 var remoting = remoting || {};
     14 
     15 /**
     16  * Note that the object has more fields than are detailed below--these
     17  * are just the ones that we refer to directly.
     18  * @constructor
     19  */
     20 remoting.Host = function() {
     21   /** @type {string} */
     22   this.hostName = '';
     23   /** @type {string} */
     24   this.hostId = '';
     25   /** @type {string} */
     26   this.status = '';
     27   /** @type {string} */
     28   this.jabberId = '';
     29   /** @type {string} */
     30   this.publicKey = '';
     31   /** @type {string} */
     32   this.hostVersion = '';
     33   /** @type {Array.<string>} */
     34   this.tokenUrlPatterns = [];
     35 };
     36 
     37 /**
     38  * Determine whether a host needs to be manually updated. This is the case if
     39  * the host's major version number is more than 1 lower than that of the web-
     40  * app (a difference of 1 is tolerated due to the different update mechanisms)
     41  * and if the host is on-line (off-line hosts are not expected to auto-update).
     42  *
     43  * @param {remoting.Host} host The host information from the directory.
     44  * @param {string|number} webappVersion The version number of the web-app, in
     45  *     either dotted-decimal notation notation, or directly represented by the
     46  *     major version.
     47  * @return {boolean} True if the host is on-line but out-of-date.
     48  */
     49 remoting.Host.needsUpdate = function(host, webappVersion) {
     50   if (host.status != 'ONLINE') {
     51     return false;
     52   }
     53   var hostMajorVersion = parseInt(host.hostVersion, 10);
     54   if (isNaN(hostMajorVersion)) {
     55     // Host versions 26 and higher include the version number in heartbeats,
     56     // so if it's missing then the host is at most version 25.
     57     hostMajorVersion = 25;
     58   }
     59   return (parseInt(webappVersion, 10) - hostMajorVersion) > 1;
     60 };
     61