Registry / communication / opentok-network-test-js

opentok-network-test-js

JSON →
library5.0.0jsnpmunverified

The `opentok-network-test-js` library provides a client-side JavaScript utility for pre-call network diagnostics within applications using the Vonage OpenTok platform. It enables developers to proactively test an end-user's network conditions, including UDP/TCP connectivity to OpenTok servers, available bandwidth, and estimated media quality (packet loss, jitter, latency). The library is currently at version 5.0.0, indicating active development. While there isn't a fixed, rapid release cadence, minor and patch updates are regularly issued to address bugs and dependencies, with major versions released as significant behavioral changes or API refactorings occur. Its primary differentiation lies in its direct integration with the OpenTok ecosystem, offering specific and relevant diagnostic feedback for OpenTok-based WebRTC sessions, which generic WebRTC tests might miss. It ships with TypeScript definitions, making it well-suited for modern JavaScript and TypeScript projects.

npm install opentok-network-test-js
INSTALL
IMPORT
SIG · OPENTOK-NETWORK-TE
O
opentok-network-test-js
communicationjavascriptv5.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OTNetworkTest
✓ import { OTNetworkTest } from '@opentok/opentok-network-test-js';
✗ const OTNetworkTest = require('@opentok/opentok-network-test-js');
The library primarily uses ES modules; CommonJS 'require' syntax is generally incorrect and may lead to issues.
ConnectivityTestResults
✓ import type { ConnectivityTestResults } from '@opentok/opentok-network-test-js';
✗ import { ConnectivityTestResults } from '@opentok/opentok-network-test-js';
Import types using 'import type' for clarity and to avoid bundling type-only declarations. Available since v4.0.1.
OTNetworkTestEvent
✓ import { OTNetworkTestEvent } from '@opentok/opentok-network-test-js';
Event definitions for subscribing to network test progress and results.

Demonstrates how to instantiate the OTNetworkTest, subscribe to events, and run both connectivity and quality tests. It highlights error handling and cleanup.

import { OTNetworkTest } from '@opentok/opentok-network-test-js'; const API_KEY = process.env.VONAGE_API_KEY ?? 'YOUR_API_KEY'; const SESSION_ID = process.env.VONAGE_SESSION_ID ?? 'YOUR_SESSION_ID'; const TOKEN = process.env.VONAGE_TOKEN ?? 'YOUR_TOKEN'; async function runNetworkTest() { const networkTest = new OTNetworkTest(); networkTest.on('connectivityTestResult', (results) => { console.log('Connectivity Test Result:', results); }); networkTest.on('qualityTestRTCStats', (stats) => { console.log('Quality Test RTC Stats:', stats); }); networkTest.on('qualityTestVideoEvent', (event) => { console.log('Quality Test Video Event:', event); }); try { console.log('Starting connectivity test...'); const connectivityResults = await networkTest.testConnectivity(API_KEY, SESSION_ID, TOKEN); console.log('Connectivity Test Complete:', connectivityResults); if (connectivityResults.success) { console.log('Starting quality test...'); const qualityResults = await networkTest.testQuality(API_KEY, SESSION_ID, TOKEN, { maxDuration: 10000 // Test for 10 seconds }); console.log('Quality Test Complete:', qualityResults); } else { console.error('Connectivity test failed. Skipping quality test.'); } } catch (error) { console.error('Network test failed:', error); } finally { networkTest.stop(); console.log('Network test stopped and cleaned up.'); } } runNetworkTest();
Debug
Known issues
breakingThe `testConnectivity` and `testQuality` methods now reject their promises upon test failure instead of resolving with a success: false object. This requires updating error handling logic (e.g., using `.catch()` or `try...catch` blocks) if migrating from v4.x.
fix
Refactor promise handling for `testConnectivity` and `testQuality` to use `try...catch` blocks or `.catch()` for explicit error management, as failures are now propagated as rejections.
affects: >=5.0.0
breakingTypeScript type definitions were refactored to align with official OpenTok SDK types. This might necessitate updates to existing type imports or interface implementations if your application relies heavily on internal type structures of the library.
fix
Review your TypeScript code for type mismatches related to `opentok-network-test-js` and update type imports or custom interfaces according to the new type definitions.
affects: >=4.0.0
gotchaThe library requires camera and microphone permissions to perform quality tests. If permissions are denied or revoked during an active test, the test may fail or become unresponsive.
fix
Ensure that camera and microphone permissions are requested and granted before initiating `testQuality`. Implement UI feedback and re-request mechanisms for `Permission Denied` errors.
affects: >=3.0.0
securityOlder versions of the library (e.g., v3.1.5, v3.1.4) included updates to address security vulnerabilities in internal dependencies like `axios`, `cross-spawn`, `webpack`, and `ws`. While these were internal, staying updated is crucial to mitigate potential transitive security risks.
fix
Always use the latest stable version of `opentok-network-test-js` to ensure you benefit from the most recent security patches and dependency updates.
affects: <5.0.0
Errors
Common errors & fixes
DOMException: Permission denied
The user denied access to the camera or microphone, which is required for the quality test.
fix
Ensure your application requests camera/microphone permissions before starting `testQuality`. Provide clear UI prompts to the user.
TypeError: Cannot read properties of undefined (reading 'on') or 'testConnectivity' is not a function
Incorrect import of the `OTNetworkTest` class, often due to using CommonJS `require` syntax in an ES module environment, or not importing `OTNetworkTest` as a named export.
fix
Use `import { OTNetworkTest } from '@opentok/opentok-network-test-js';` for ESM. If using CJS in an older environment (uncommon), you might need `const { OTNetworkTest } = require('@opentok/opentok-network-test-js');` but the library is primarily designed for ESM.
Network test appears to be stuck or unresponsive after revoking permissions.
In versions prior to 4.0.2, revoking camera/microphone permissions while `testQuality` was actively running could lead to the test freezing.
fix
Update to version `4.0.2` or later. If using an older version, ensure permissions are not revoked during an active test, or manually stop the test instance (`networkTest.stop()`) if permissions change.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
opentok-network-test-js — npm install opentok-network-test-js · libregistry