All files / widgets/Source/PerformanceWatchdog PerformanceWatchdog.js

100% Statements 34/34
100% Branches 6/6
100% Functions 5/5
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                7x 2x   5x 1x       4x   3x   3x 3x 3x   3x 3x 3x 3x 3x 3x   3x 3x 3x 3x   3x   3x   3x 3x 3x     1x                 1x                       1x                 1x 1x               1x 1x 1x 1x   1x      
import {
  defined,
  destroyObject,
  DeveloperError,
  getElement,
} from "@cesium/engine";
import knockout from "../ThirdParty/knockout.js";
import PerformanceWatchdogViewModel from "./PerformanceWatchdogViewModel.js";
 
/**
 * Monitors performance of the application and displays a message if poor performance is detected.
 *
 * @alias PerformanceWatchdog
 * @constructor
 *
 * @param {object} [options] Object with the following properties:
 * @param {Element|string} options.container The DOM element or ID that will contain the widget.
 * @param {Scene} options.scene The {@link Scene} for which to monitor performance.
 * @param {string} [options.lowFrameRateMessage='This application appears to be performing poorly on your system.  Please try using a different web browser or updating your video drivers.'] The
 *        message to display when a low frame rate is detected.  The message is interpeted as HTML, so make sure
 *        it comes from a trusted source so that your application is not vulnerable to cross-site scripting attacks.
 */
function PerformanceWatchdog(options) {
  //>>includeStart('debug', pragmas.debug);
  if (!defined(options) || !defined(options.container)) {
    throw new DeveloperError("options.container is required.");
  }
  if (!defined(options.scene)) {
    throw new DeveloperError("options.scene is required.");
  }
  //>>includeEnd('debug');
 
  const container = getElement(options.container);
 
  const viewModel = new PerformanceWatchdogViewModel(options);
 
  const element = document.createElement("div");
  element.className = "cesium-performance-watchdog-message-area";
  element.setAttribute("data-bind", "visible: showingLowFrameRateMessage");
 
  const dismissButton = document.createElement("button");
  dismissButton.setAttribute("type", "button");
  dismissButton.className = "cesium-performance-watchdog-message-dismiss";
  dismissButton.innerHTML = "×";
  dismissButton.setAttribute("data-bind", "click: dismissMessage");
  element.appendChild(dismissButton);
 
  const message = document.createElement("div");
  message.className = "cesium-performance-watchdog-message";
  message.setAttribute("data-bind", "html: lowFrameRateMessage");
  element.appendChild(message);
 
  container.appendChild(element);
 
  knockout.applyBindings(viewModel, element);
 
  this._container = container;
  this._viewModel = viewModel;
  this._element = element;
}
 
Object.defineProperties(PerformanceWatchdog.prototype, {
  /**
   * Gets the parent container.
   * @memberof PerformanceWatchdog.prototype
   *
   * @type {Element}
   */
  container: {
    get: function () {
      return this._container;
    },
  },
 
  /**
   * Gets the view model.
   * @memberof PerformanceWatchdog.prototype
   *
   * @type {PerformanceWatchdogViewModel}
   */
  viewModel: {
    get: function () {
      return this._viewModel;
    },
  },
});
 
/**
 * @memberof PerformanceWatchdog
 * @returns {boolean} true if the object has been destroyed, false otherwise.
 */
PerformanceWatchdog.prototype.isDestroyed = function () {
  return false;
};
 
/**
 * Destroys the widget.  Should be called if permanently
 * removing the widget from layout.
 * @memberof PerformanceWatchdog
 */
PerformanceWatchdog.prototype.destroy = function () {
  this._viewModel.destroy();
  knockout.cleanNode(this._element);
  this._container.removeChild(this._element);
 
  return destroyObject(this);
};
export default PerformanceWatchdog;