This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,860 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
# node-wrtc-agent | ||
WebRTC agent for load testing | ||
|
||
# Installation | ||
|
||
```bash | ||
git clone [email protected]:netology-group/node-wrtc-agent.git | ||
cd node-wrtc-agent | ||
npm i | ||
|
||
# macOS | ||
npm run copy-module-darwin | ||
# or linux | ||
npm run copy-module-linux | ||
|
||
sudo npm link | ||
``` | ||
|
||
# Options | ||
|
||
```bash | ||
$ wrtc-agent --help | ||
Options: | ||
--version Show version number [boolean] | ||
-c, --client-id Client id for mqtt-client [string] [required] | ||
-n, --name Conference app name [string] [required] | ||
-P, --password Password for mqtt-client [string] [required] | ||
-r, --room-id Conference room id [string] [required] | ||
--relay-only Use only "relay" ICE candidates [boolean] | ||
--stun STUN server URL [string] [required] | ||
--turn TURN server URL [string] [required] | ||
--turn-password TURN password [string] [required] | ||
--turn-username TURN username [string] [required] | ||
-u, --uri MQTT broker URI [string] [required] | ||
--help Show help [boolean] | ||
--version Show version number [boolean] | ||
-c, --client-id Client id for mqtt-client [string] [required] | ||
-n, --name Conference app name [string] [required] | ||
-P, --password Password for mqtt-client [string] [required] | ||
-r, --room-id Conference room id [string] [required] | ||
--relay-only Use only "relay" ICE candidates [boolean] | ||
--stun STUN server URL [string] [required] | ||
--telemetry Telemetry app name [string] | ||
--telemetry-interval Telemetry interval (ms) [number] [default: 5000] | ||
--turn TURN server URL [string] [required] | ||
--turn-password TURN password [string] [required] | ||
--turn-username TURN username [string] [required] | ||
-u, --uri MQTT broker URI [string] [required] | ||
--help Show help [boolean] | ||
``` | ||
|
||
# Usage | ||
|
@@ -27,8 +44,10 @@ Options: | |
|
||
ACCESS_TOKEN=foobar | ||
BROKER_URI=ws://example.org/ | ||
CONFERENCE_APP_NAME=conference.svc.netology-group.services | ||
CONFERENCE_APP_NAME=conference.example.org | ||
CONFERENCE_ROOM_ID=ea3f9fd1-3356-43b4-b709-b7cfc563ea59 | ||
STUN_URL=stun:stun.example.org:3478 | ||
TELEMETRY_APP_NAME=telemetry.example.org | ||
TURN_URL=turn:example.org:3478 | ||
TURN_USERNAME=username | ||
TURN_PASSWORD=password | ||
|
@@ -37,9 +56,11 @@ wrtc-agent \ | |
-c web.john-doe.example.org \ | ||
-n ${CONFERENCE_APP_NAME} \ | ||
-P ${ACCESS_TOKEN} \ | ||
-r ea3f9fd1-3356-43b4-b709-b7cfc563ea59 \ | ||
-r ${CONFERENCE_ROOM_ID} \ | ||
--relay-only \ | ||
--stun ${STUN_URL} \ | ||
--telemetry ${TELEMETRY_APP_NAME} \ | ||
--telemetry-interval 10000 \ | ||
--turn ${TURN_URL} \ | ||
--turn-username ${TURN_USERNAME} \ | ||
--turn-password ${TURN_PASSWORD} \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
const { WebRTCStats } = require('@peermetrics/webrtc-stats') | ||
const { snakeCase } = require('change-case') | ||
const { v4 } = require('uuid') | ||
const wrtc = require('wrtc') | ||
|
||
function stats2metrics (stats) { | ||
// const localAudioMetricList = [ | ||
// 'packetsSent', | ||
// 'retransmittedPacketsSent', | ||
// 'bytesSent', | ||
// 'headerBytesSent', | ||
// 'retransmittedBytesSent', | ||
// 'bitrate', | ||
// 'packetRate' | ||
// ] | ||
const remoteAudioMetricList = [ | ||
'packetsReceived', | ||
'bytesReceived', | ||
'headerBytesReceived', | ||
'packetsLost', | ||
'jitter', | ||
'jitterBufferDelay', | ||
'jitterBufferEmittedCount', | ||
'audioLevel', | ||
'totalAudioEnergy', | ||
'totalSamplesReceived', | ||
'totalSamplesDuration', | ||
'bitrate', | ||
'packetRate' | ||
] | ||
// const localVideoMetricList = [ | ||
// 'firCount', | ||
// 'pliCount', | ||
// 'nackCount', | ||
// 'qpSum', | ||
// 'packetsSent', | ||
// 'retransmittedPacketsSent', | ||
// 'bytesSent', | ||
// 'headerBytesSent', | ||
// 'retransmittedBytesSent', | ||
// 'framesEncoded', | ||
// 'keyFramesEncoded', | ||
// 'totalEncodeTime', | ||
// 'totalEncodedBytesTarget', | ||
// 'totalPacketSendDelay', | ||
// 'qualityLimitationReason', | ||
// 'qualityLimitationResolutionChanges', | ||
// 'frameWidth', | ||
// 'frameHeight', | ||
// 'framesSent', | ||
// 'hugeFramesSent', | ||
// 'bitrate', | ||
// 'packetRate' | ||
// ] | ||
const remoteVideoMetricList = [ | ||
'firCount', | ||
'pliCount', | ||
'nackCount', | ||
'qpSum', | ||
'packetsReceived', | ||
'bytesReceived', | ||
'headerBytesReceived', | ||
'packetsLost', | ||
'framesDecoded', | ||
'keyFramesDecoded', | ||
'totalDecodeTime', | ||
'totalInterFrameDelay', | ||
'totalSquaredInterFrameDelay', | ||
'jitterBufferDelay', | ||
'jitterBufferEmittedCount', | ||
'frameWidth', | ||
'frameHeight', | ||
'framesReceived', | ||
'framesDropped', | ||
'bitrate', | ||
'packetRate' | ||
] | ||
const connectionMetricList = [ | ||
'bytesSent', | ||
'bytesReceived', | ||
'totalRoundTripTime', | ||
'currentRoundTripTime', | ||
'availableOutgoingBitrate' | ||
] | ||
|
||
const metricBaseName = 'apps.wrtc-agent.pc' | ||
// const localAudioMetricName = `${metricBaseName}.audio.local` | ||
// const localAudioMetrics = localAudioMetricList.map(_ => ({ | ||
// metric: `${localAudioMetricName}.${snakeCase(_)}`, | ||
// value: stats.data.audio.local[_] || 0 | ||
// })) | ||
const remoteAudioMetricName = `${metricBaseName}.audio.remote` | ||
const remoteAudioMetrics = remoteAudioMetricList.map(_ => ({ | ||
metric: `${remoteAudioMetricName}.${snakeCase(_)}`, | ||
value: stats.data.audio.remote[_] || 0 | ||
})) | ||
// const localVideoMetricName = `${metricBaseName}.video.local` | ||
// const localVideoMetrics = localVideoMetricList.map(_ => ({ | ||
// metric: `${localVideoMetricName}.${snakeCase(_)}`, | ||
// value: stats.data.video.local[_] || 0 | ||
// })) | ||
const remoteVideoMetricName = `${metricBaseName}.video.remote` | ||
const remoteVideoMetrics = remoteVideoMetricList.map(_ => ({ | ||
metric: `${remoteVideoMetricName}.${snakeCase(_)}`, | ||
value: stats.data.video.remote[_] || 0 | ||
})) | ||
const connectionMetricName = `${metricBaseName}.connection` | ||
const connectionMetrics = connectionMetricList.map(_ => ({ | ||
metric: `${connectionMetricName}.${snakeCase(_)}`, | ||
value: stats.data.connection[_] || 0 | ||
})) | ||
|
||
return [ | ||
// ...localAudioMetrics, | ||
...remoteAudioMetrics, | ||
// ...localVideoMetrics, | ||
...remoteVideoMetrics, | ||
...connectionMetrics | ||
] | ||
} | ||
|
||
function createPeerStatsMonitor (peer, interval, statsHandler) { | ||
const p = new WebRTCStats({ | ||
getStatsInterval: interval, | ||
wrtc | ||
}) | ||
|
||
p.on('stats', statsHandler) | ||
|
||
p.addPeer({ | ||
pc: peer, | ||
peerId: v4() | ||
}) | ||
|
||
return p | ||
} | ||
|
||
module.exports = { | ||
createPeerStatsMonitor, | ||
stats2metrics | ||
} |
Oops, something went wrong.