npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

streaming-bandwidth-calculator

v0.0.9

Published

A library to calculate the bandwidth consumed through streaming connections.

Downloads

14

Readme

Note: I am not a software developer. This project was made solely and exclusively for personal learning purposes. I would greatly appreciate it if you could send me criticisms, tips, suggestions, and any other comments that may help me to evolve.

streaming-bandwidth-calculator

A library to calculate the bandwidth consumed through streaming connections.

Examples:

  • Get total listeners from bitrate, time and bandwidth
  • Get total bandwidth consumed from bitrate, time and listeners

How to use:

Back-end implementation:

Install the library via NPM:

npm i streaming-bandwidth-calculator

For Node.js, import the library as follows:

const { calculator,streaming } = require('streaming-bandwidth-calculator')

Inside the demo folder, node-example.js provide a simple example of how to use the library on the back-end.

If you're using node type as ES Modules, you'll need to comment all "require" and "module.exports" from the .js files, and uncomment the "import" and "export" lines.

Front end implementation:

Install the library via NPM:

npm i streaming-bandwidth-calculator

Copy the /src folder and main.js file from /node_modules to your working directory.

In order to work on a browser, you'll need to make some changes in these files:

./main.js
./src/bandwidth-calc.js

All you need to do is comment the lines using "require" or "module.exports" and uncomment the lines using "import" and "export", like this example on bandwidth-calc.js:

import { calculator } from "../../bytes-and-bits-converter/script.js"
// const calculator = require('bytes-and-bits-converter')
...
export {bandwidthCalc, streaming}
// module.exports = { bandwidthCalc,streaming }

If you want to use this project right through your HTML file, import the library at the end of the <body> tag, as follows:

<body>
...your html code...
<script src="./main.js" type="module"></script
</body>

Inside the demo folder, index.html and example.js provides an example of how to use the libray on the front-end.

Syntax

streaming.bandwidth(inputBitrate,inputListeners,inputTime)

Return: bandwidth in bytes

streaming.listeners(inputBitrate,inputTime,inputListeners)

Return: Average amount of listeners

streaming.time(inputBitrate,inputListeners,inputBandwidth)

Return: Average amount of time per listener in seconds

streaming.bitrate(inputListeners,inputTime,inputBandwidth)

Return: Maximum bitrate in bits

Where:

  • inputBitrate: the streaming bitrate. Ex: 128000, 192000, 320000, etc. Should be only numbers and in bits
  • inputListeners: the average listeners number.
  • inputTime: the total time connected in seconds.
  • inputBandwidth: the total bandwidth consumed in bytes.

Also, you can convert numerous units of measurement from bits and bytes through the calculator function. Type this for more info:

calculator.help()

Help:

index.html and example.js are unnecessary files, provided as an exemple of how to use this library on your front-end project.

node-example.js also is an unnecessary file, provided as an exemple of how to use this library on your Node.js project.

Aditional info:

This application utilizes a library to work:

bytes-and-bits-converter: A library to convert magnitudes

Changelog:

Last updates: [0.0.9] - 2023-05-18

Updating "type" from ES Modules to CommonJS.

Added:

  • On all .js files, added const xx = require('') and module.exports in order to work as CommonJS.
  • On all .js files, added commented import and export lines to facilitate any potential change on node type to ES Modules.

View complete history