{"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install opentok-network-test-js"],"cli":null},"imports":["import { OTNetworkTest } from '@opentok/opentok-network-test-js';","import type { ConnectivityTestResults } from '@opentok/opentok-network-test-js';","import { OTNetworkTestEvent } from '@opentok/opentok-network-test-js';"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}