npm package containing a set of custom hooks for your next WebRTC+React project.
# Using npm
npm install webrtc-connection-tester
# Using yarn
yarn add webrtc-connection-tester
This React custom hook facilitates testing WebRTC connectivity.
import React from 'react';
import {useConnectivityTest} from 'webrtc-connection-tester';
const MyComponent = () => {
const { message } = useConnectivityTest('srflx', [
{
credential: "your turn server password",
urls: ['your turn servers urls'],
username: "your turn servers username",
},
],);
return (
<div>
{message.map((msg, index) => (
<p key={index}>{msg}</p>
))}
</div>
);
};
- type: ('relay' | 'srflx' | 'host') Defines the preferred ICE candidate type.
- iceServers: (RTCIceServer[]) An array of ICE servers for connectivity.
- message: (string[]) An array of messages logging test progress and results.
Gathered candidate of Type: host Protocol: udp Address: 192.168.1.100
Gathered candidate of Type: host Protocol: udp Address: 2402:8100:24aa:d2f4:bb3:49bc:3797:c28a
Data successfully transmitted between peers.
Test done:
This React custom hook measures WebRTC data channel throughput.
import React from 'react';
import {useDataChannelThroughputTest} from 'webrtc-connection-tester';
const MyComponent = () => {
const { message } = useDataChannelThroughputTest([
{
credential: "your turn server password",
urls: ['your turn servers urls'],
username: "your turn servers username",
},
]);
return (
<div>
{message.map((msg, index) => (
<p key={index}>{msg}</p>
))}
</div>
);
};
- iceServers : (RTCIceServer[]) An array of ICE servers for connectivity.
- message: (string[]) An array of messages logging test progress and results.
Transmitting at 1234 kbps.
...
Total transmitted: 5678 kilo-bits in 1.23 seconds.
Test done.
This React custom hook gathers WebRTC ICE candidates based on a specified protocol.
import React from 'react';
import {useNetworkTest} from 'webrtc-connection-tester';
const MyComponent = () => {
const { message } = useNetworkTest('tcp', [
{
credential: "your turn server password",
urls: ['your turn servers urls'],
username: "your turn servers username",
},
]);
return (
<div>
{message.map((msg, index) => (
<p key={index}>{msg}</p>
))}
</div>
);
};
- protocol: ('tcp' | 'udp') The protocol to filter ICE candidates for.
- iceServers: (RTCIceServer[]) An array of ICE servers for connectivity.
- message: (string[]) An array of messages logging test progress and results.
Gathered candidate of Type: host Protocol: tcp Address: 192.168.1.100
Test done.
This React custom hook measures video bandwidth using WebRTC.
import React from 'react';
import {useVideoBandwidth} from 'webrtc-connection-tester';
const MyComponent = () => {
const gatheredStatsReport = useVideoBandwidth([
{
credential: "your turn server password",
urls: ['your turn servers urls'],
username: "your turn servers username",
},
]);
// Access and display the gatheredStatsReport data here
// ...
return (
<div>
{gatheredStatsReport ? (
<ul>
<li>Round Trip Time: {gatheredStatsReport.RoundTripTime} sec</li>
<li>
Bandwidth Estimate Average:{" "}
{gatheredStatsReport.bandwidth_estimate_average} kbps
</li>
<li>
Bandwidth Estimate Max: {gatheredStatsReport.bandwidth_estimate_max}{" "}
kbps
</li>
<li>Packets Sent: {gatheredStatsReport.packetsSent}</li>
<li>Packets Received: {gatheredStatsReport.packetsReceived}</li>
<li>NACK Count: {gatheredStatsReport.nackCount}</li>
<li>PLI Count: {gatheredStatsReport.pliCount}</li>
<li>QP Sum: {gatheredStatsReport.qpSum}</li>
<li>Frames Encoded: {gatheredStatsReport.framesEncoded}</li>
<li>Frames Decoded: {gatheredStatsReport.framesDecoded}</li>
</ul>
) : null}
</div>
);
};
- iceServers: (RTCIceServer[]) An array of ICE servers for connectivity.
- reportType | null: An object containing video bandwidth statistics if successful, otherwise null.
Round Trip Time: 0.123 sec
Bandwidth Estimate Average: 1234 kbps
Bandwidth Estimate Max: 5678 kbps
Packets Sent: 1024
Packets Received: 987
NACK Count: 5
PLI Count: 2
QP Sum: 12345
Frames Encoded: 100
Frames Decoded: 99