Source: lib/ads/ads_stats.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ads.AdsStats');
  7. /**
  8. * This class tracks all the various components (some optional) that are used to
  9. * populate |shaka.extern.AdsStats| which is passed to the app.
  10. *
  11. * @final
  12. */
  13. shaka.ads.AdsStats = class {
  14. /** */
  15. constructor() {
  16. /** @private {!Array.<number>} */
  17. this.loadTimes_ = [];
  18. /** @private {number} */
  19. this.started_ = 0;
  20. /** @private {number} */
  21. this.playedCompletely_ = 0;
  22. /** @private {number} */
  23. this.skipped_ = 0;
  24. }
  25. /**
  26. * Record the time it took to get the final manifest.
  27. *
  28. * @param {number} seconds
  29. */
  30. addLoadTime(seconds) {
  31. this.loadTimes_.push(seconds);
  32. }
  33. /**
  34. * Increase the number of ads started by one.
  35. */
  36. incrementStarted() {
  37. this.started_++;
  38. }
  39. /**
  40. * Increase the number of ads played completely by one.
  41. */
  42. incrementPlayedCompletely() {
  43. this.playedCompletely_++;
  44. }
  45. /**
  46. * Increase the number of ads skipped by one.
  47. */
  48. incrementSkipped() {
  49. this.skipped_++;
  50. }
  51. /**
  52. * Create a stats blob that we can pass up to the app. This blob will not
  53. * reference any internal data.
  54. *
  55. * @return {shaka.extern.AdsStats}
  56. */
  57. getBlob() {
  58. return {
  59. loadTimes: this.loadTimes_,
  60. started: this.started_,
  61. playedCompletely: this.playedCompletely_,
  62. skipped: this.skipped_,
  63. };
  64. }
  65. };