karelkryda / universal-speedtest

This library allows you to test the speed of the Internet using several test sites.
https://www.npmjs.com/package/universal-speedtest
GNU General Public License v3.0
15 stars 5 forks source link

[BUG] TypeError: UniversalSpeedtest is not a constructor - when using V3.0.0 from the build branch #29

Open sjonniesensei opened 4 days ago

sjonniesensei commented 4 days ago

Describe the bug Im getting the error TypeError: UniversalSpeedtest is not a constructor.

To Reproduce Steps to reproduce the behavior:

  1. install universalspeedtest v 3.0.0 from the build branch
  2. setup an express server. Here is the code of my express server.js file: `const express = require("express"); const { UniversalSpeedtest, SpeedUnits } = require("universal-speedtest");

const app = express(); const port = 3000;

app.use(express.static("public"));

app.get("/api/speedtest", async (req, res) => { const universalSpeedtest = new UniversalSpeedtest({ measureUpload: true, downloadUnit: SpeedUnits.MBps, }); universalSpeedtest .runSpeedtestNet() .then((result) => { res.json({ speed: result }); }) .catch((error) => { res.status(500).json({ error: error.message }); }); });

app.listen(port, () => { console.log(Server running at http://localhost:${port}); }); `

  1. run "node server.js"
  2. you will see the error in the terminal

Expected behavior expected the results of the speed test as I made an index.html with a script where Im calling the /api/speedtest: `function runSpeedtest() { startTestButton.disabled = true;

const eventSource = new EventSource("/api/speedtest");

eventSource.onmessage = function (event) { const data = JSON.parse(event.data); console.log(data);

if (data.type === "complete") {
  eventSource.close();
  startTestButton.disabled = false;
}

};

eventSource.onerror = function (error) { console.error("EventSource failed:", error); eventSource.close(); startTestButton.disabled = false; }; }`

Screenshots Screenshot 2024-09-15 150135

Desktop (please complete the following information):

karelkryda commented 4 days ago

Hello,

I remember that in the original version 3.0.0 I made modifications including renaming methods and constructors. However, by never officially releasing this version, I believe I have not updated the documentation either.

In February, I started a complete rewrite of the library. One of the benefits should be much higher quality testing using Ookla Speedtest. Unfortunately the last few months have been very chaotic for me and I never finished this release. Today I found the time to get started again. At the current stage, I just need to rewrite the upload speed measurement technology and make a few minor improvements. The beta release of the new version 3.0.0 will probably be stripped of the ability to use the Cloudflare test for testing, but I believe most users primarily use the Ookla test anyway, which is why I've given it my full effort.

This release will use different libraries, different technologies and different ways of packaging the resulting code. This should solve the problem you mentioned.

I ask for your patience until the new release comes out. I will try to devote all my spare time to it if possible.

sjonniesensei commented 4 days ago

Hi @karelkryda ,

Thanks for the reaction. Alright, looking forward to the new version. Please let me know when it is out.

Have a good day!