{"id":13719,"library":"opentok-network-test-js","title":"OpenTok Network Test JavaScript SDK","description":"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.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/opentok/opentok-network-test-js","tags":["javascript","tokbox","opentok","network test","connectivity","webrtc","typescript"],"install":[{"cmd":"npm install opentok-network-test-js","lang":"bash","label":"npm"},{"cmd":"yarn add opentok-network-test-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add opentok-network-test-js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses ES modules; CommonJS 'require' syntax is generally incorrect and may lead to issues.","wrong":"const OTNetworkTest = require('@opentok/opentok-network-test-js');","symbol":"OTNetworkTest","correct":"import { OTNetworkTest } from '@opentok/opentok-network-test-js';"},{"note":"Import types using 'import type' for clarity and to avoid bundling type-only declarations. Available since v4.0.1.","wrong":"import { ConnectivityTestResults } from '@opentok/opentok-network-test-js';","symbol":"ConnectivityTestResults","correct":"import type { ConnectivityTestResults } from '@opentok/opentok-network-test-js';"},{"note":"Event definitions for subscribing to network test progress and results.","symbol":"OTNetworkTestEvent","correct":"import { OTNetworkTestEvent } from '@opentok/opentok-network-test-js';"}],"quickstart":{"code":"import { OTNetworkTest } from '@opentok/opentok-network-test-js';\n\nconst API_KEY = process.env.VONAGE_API_KEY ?? 'YOUR_API_KEY';\nconst SESSION_ID = process.env.VONAGE_SESSION_ID ?? 'YOUR_SESSION_ID';\nconst TOKEN = process.env.VONAGE_TOKEN ?? 'YOUR_TOKEN';\n\nasync function runNetworkTest() {\n  const networkTest = new OTNetworkTest();\n\n  networkTest.on('connectivityTestResult', (results) => {\n    console.log('Connectivity Test Result:', results);\n  });\n\n  networkTest.on('qualityTestRTCStats', (stats) => {\n    console.log('Quality Test RTC Stats:', stats);\n  });\n\n  networkTest.on('qualityTestVideoEvent', (event) => {\n    console.log('Quality Test Video Event:', event);\n  });\n\n  try {\n    console.log('Starting connectivity test...');\n    const connectivityResults = await networkTest.testConnectivity(API_KEY, SESSION_ID, TOKEN);\n    console.log('Connectivity Test Complete:', connectivityResults);\n\n    if (connectivityResults.success) {\n      console.log('Starting quality test...');\n      const qualityResults = await networkTest.testQuality(API_KEY, SESSION_ID, TOKEN, {\n        maxDuration: 10000 // Test for 10 seconds\n      });\n      console.log('Quality Test Complete:', qualityResults);\n    } else {\n      console.error('Connectivity test failed. Skipping quality test.');\n    }\n  } catch (error) {\n    console.error('Network test failed:', error);\n  } finally {\n    networkTest.stop();\n    console.log('Network test stopped and cleaned up.');\n  }\n}\n\nrunNetworkTest();","lang":"typescript","description":"Demonstrates how to instantiate the OTNetworkTest, subscribe to events, and run both connectivity and quality tests. It highlights error handling and cleanup."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":">=5.0.0"},{"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.","message":"TypeScript 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.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=3.0.0"},{"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.","message":"Older 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.","severity":"security","affected_versions":"<5.0.0"}],"env_vars":null,"search_vec":"'5.0.0':68 'activ':70 'address':89 'api':102 'applic':27 'avail':52 'bandwidth':53 'base':126 'behavior':99 'bug':90 'cadenc':80 'call':23 'chang':100 'client':16 'client-sid':15 'condit':45 'connect':48,156 'current':65 'definit':139 'depend':92 'develop':35,71 'diagnost':25,121 'differenti':107 'direct':111 'ecosystem':116 'enabl':34 'end':41 'end-us':40 'estim':55 'feedback':122 'fix':77 'generic':130 'includ':46 'indic':69 'integr':112 'isn':74 'issu':87 'javascript':4,18,147,151 'jitter':60 'js':11 'latenc':61 'librari':12,63 'lie':108 'loss':59 'major':94 'make':140 'media':56 'might':133 'minor':81 'miss':134 'modern':146 'network':2,9,24,44,154 'occur':104 'offer':117 'opentok':1,8,31,50,115,125,153 'opentok-bas':124 'opentok-network-test-j':7 'packet':58 'patch':83 'platform':32 'pre':22 'pre-cal':21 'primari':106 'proactiv':37 'project':150 'provid':13 'qualiti':57 'rapid':78 'refactor':103 'regular':86 'releas':79,96 'relev':120 'sdk':5 'server':51 'session':128 'ship':136 'side':17 'signific':98 'specif':118 'suit':144 'test':3,10,38,132,155 'tokbox':152 'typescript':138,149,158 'udp/tcp':47 'updat':84 'use':28 'user':42 'util':19 'version':67,95 'vonag':30 'webrtc':127,131,157 'well':143 'well-suit':142 'within':26","created_at":"2026-04-20T01:55:57.520945+00:00","updated_at":"2026-04-20T01:55:57.520945+00:00","problems":[{"fix":"Ensure your application requests camera/microphone permissions before starting `testQuality`. Provide clear UI prompts to the user.","cause":"The user denied access to the camera or microphone, which is required for the quality test.","error":"DOMException: Permission denied"},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'on') or 'testConnectivity' is not a function"},{"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.","cause":"In versions prior to 4.0.2, revoking camera/microphone permissions while `testQuality` was actively running could lead to the test freezing.","error":"Network test appears to be stuck or unresponsive after revoking permissions."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://vonage.com","github":"https://github.com/opentok/opentok-network-test-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/opentok-network-test-js","openapi_spec":null,"status_page":null,"smithery":null,"categories":["communication","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}