@ceeblue/web-utils
    Preparing search index...

    Class ByteRate

    Class to compute a weighted average byte rate over a specified time interval.

    This class continuously tracks data transmission and computes the byte rate based on a weighted average, considering both the duration and the number of bytes in each sample. It allows for real-time monitoring of bandwidth usage and provides mechanisms to dynamically adjust the measurement interval.

    Features:

    • Computes the byte rate using a weighted average approach.
    • Allows setting a custom interval for tracking.
    • Supports dynamic clipping to manually shrink the observation window.
    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Constructor initializes the ByteRate object with a specified interval (default: 1000ms). It sets up necessary variables to track byte rate over time.

      Parameters

      • interval: number = 1000

        Time interval in milliseconds to compute the byte rate.

      Returns ByteRate

    Accessors

    • get interval(): number

      Returns the interval used for computing the byte rate

      Returns number

    • set interval(value: number): void

      Sets a new interval for computing the average byte rate

      Parameters

      • value: number

      Returns void

    Methods

    • Adds a new byte sample to the tracking system. Updates the list of samples and recomputes the byte rate

      Parameters

      • bytes: number

        Number of bytes added in this interval

      Returns ByteRate

    • Clips the byte rate tracking by marking the last sample as clipped. If a previous clip exists, removes the clipped sample and all preceding samples. Allows to shrink the interval manually between two positions.

      Returns ByteRate

    • Computes the exact byte rate in bytes per second

      Returns number

    • Raised when new bytes are added

      Parameters

      • bytes: number

      Returns void

    • Returns the computed byte rate rounded to the nearest integer

      Returns number