hubbleiq-services
v2.7.5
Published
HubbleIQ testing SDK
Downloads
98
Readme
HubbleSDK: A JavaScript library to easily measure and analyze internet performance for web applications. Improve user experience by identifying and troubleshooting network issues.
- Getting Started
- Configuration Options
- Examples
- Using the Library
- Functions
- Events
- Dependencies
- Support
- Additional Information
A JavaScript library for measuring and analyzing internet performance.
Getting Started
Note: Node.js versions 18 and above are supported. We recommend using the latest stable version. It is also important for you to obtaining the API key and company key from the HubbleIQ admin panel before using this library.
Installation:
yarn add hubbleiq-services
or
npm install hubbleiq-services
Once installed, you can import the HubbleIQLib component into your React application as follows:
// import the component
import { HubbleIQLib } from "hubbleiq-services";
Configuration
To initialize the HubbleIQ SDK, you need to provide two objects: authData
and options
.
Where authData
contains:
{
apiKey: 'your apiKey',
companyKey: 'your companyKey'
}
and options
contains additional configuration data. These keys can be obtained from the admin panel after registering on HubbleIQ.
Configuration Options:
| Property Name | Type | Default Value | Description | | ------------- | :----: | ------------: | --------------------------------------------------------------------------------------------------------------------------------------- | | options | object | Not set | Configuration object for the HubbleIQ library, example: { enablePageLoadCalculation: true, checkNetTimeOut: 2000 } |
Examples:
const hubbleIQLib = new HubbleIQLib(
{
apiKey: "your apiKey",
companyKey: "your companyKey"
},
options
);
Usage Examples:
Explore the following code samples that demonstrate how to leverage HubbleIQ SDK’s functionalities within your application:
1. To use the SDK we should first initialize it. Create a file called hubbleIQLib.js:
import { HubbleIQLib } from "hubbleiq-services";
const options = {
enablePageLoadCalculation: false,
env: 'local'
};
// construct the library
const hubbleIQLib = new HubbleIQLib (
{
apiKey: 'c14aa742-5aac-41cf-abf9-45157df2d3ca',
companyKey: 'mediumCompanyKey',
},
options
);
hubbleIQLib.init();
export default hubbleIQLib;
2. The next step is to create a functions that call the tests from hubbleIQLib:
async function callPocketLossTest() {
await hubbleIQLib.calculatePacketLoss();
}
async function callInternetConnectionTest() {
await hubbleIQLib.checkInternetConnection();
}
async function startTest() {
await hubbleIQLib.run();
}
3. Each SDK method fires an event once the action is finished. We should declare them and save the data we receive from the events into our state using useEffect.
useEffect(() => {
hubbleIQLib.on("connection-status", (status: string) => {
// connection status
});
hubbleIQLib.on("upload-measurement", (data: IUploadAndDownloadData) => {
// upload speed: data.ClientToServerSpeed
});
hubbleIQLib.on("download-measurement", (data: IUploadAndDownloadData) => {
// downlod speed: data.ServerToClientSpeed
});
hubbleIQLib.on("complete", (data: ICompleteData) => {
// latency and jitter: data.jitter && data.latency
});
hubbleIQLib.on("packet-loss", (data: number) => {
// packet loss percentage
});
hubbleIQLib.on("connection-stability", (data: number) => {
// heart beat data.
});
}, []);
Events:
The library emits various events to communicate results. You can listen to these events to handle the data accordingly.
| Event name | Type of response | description | |------------------------| :--------------: | -------------------------------------------------------------------------------: | | onstart | string | Fired when the library starts. Contains the name of the server being contacted. | | complete | object | Emitted after a complete internet performance test is finished. | | connection-status | string | Indicates the current internet connection status (online or offline). | | connection-stability | int | Connection latency (ms). | | connection-msg | object | Provides details about the current connection, including latency. | | upload-measurement | object | Contains results from an upload speed measurement. | | download-measurement | object | Contains results from a download speed measurement. | | test-results | object | Emitted with the complete set of results after a full internet performance test. | | packet-loss | number | Provides the measured packet loss percentage. |
Dependencies:
The HubbleIQ library depends on the following external libraries:
@m-lab/ndt7
: used for network speed testing.
crypto-browserify
: provides cryptographic functionalities (used for security?).
form-data
: used for constructing multipart form data for requests.
node-fetch
: enables making HTTP requests in Node.js environments.
stream-browserify
: used for handling data streams.
tslib
: utility library for compatibility across environments.
web-worker
: enables utilizing web workers for background tasks.
worker-plugin
: a plugin for handling web workers.
Support:
If you encounter any issues, feel free to contact us by email at [email protected].
Additional Information:
Dependencies: Refer to the documentation for a list of dependencies.
Authors: Hubble Teams
License:
This project uses an API Key Licensing model. You are free to use the functionality provided by the API, but a valid API key is required for access.