gather WebRTC API traces and statistics
npm install @jitsi/rtcstatsThis repo represents the client side component. It's meant to run in a browsers/electron environment which exposes GUM and WebRTC standard functionality.
In short, once integrated, the library overwrites GUM and RTCPeerConnection functionality and proxies most calls and events going through them, sending the gathered data via a websocket to the rtcstats-server. On top of that, each newly created RTCPeerConnection has a configured interval set for it, which calls getStats periodically, this too is sent to the rtcstats-server.
To install simply.
```
npm install github:jitsi/rtcstats#vx.x.x
javascript
import rtcstatsInit from 'rtcstats/rtcstats';
import traceInit from 'rtcstats/trace-ws';/**
* Initialises the trace object which is the channel that rtcstats uses to send data.
*
* @rtcstatsEndpoint - rtcstats-server endpoint ex: "wss:\\sample-rtcstata-endpoing.org:3000"
* @handleTraceWSClose - callback for handling websocket closed event.
*/
const trace = traceInit(rtcstatsEndpoint, handleTraceWSClose);
/**
* Initialises rtcstats, overwrites GUM and RTCPeerConnection and starts sending data.
*
* @trace - trace channel on which data is sent.
* @pollInterval - interval at which getStats is called and sent.
* @prefixesToWrap - legacy RTCPeerConnection prefixes for older browser compatibility. Almost all browser now support the RTCPeerConnection API so it can be left empty
* @connectionFilter - callback used to filter out RTCPeerConnections based on their config.
*/
rtcstatsInit(trace, pollInterval, ['', 'webkit', 'moz'], connectionFilter);
`
Because GUM and RTCPeerConnection are overwritten, rtcstats needs to be initialized before any aliases to them are created. For instance lib-jitsi-meet doesn't directly call these functions but rather has references, thus initializing rtcstats after lib-jitsi-meet would result in the original methods being called and
not those that are proxied.If you need things like a client or conference identifier to be sent along, the recommended way is to use the legacy peerconnection constraints when constructing your RTCPeerConnection like this:
`javascript
var pc = new RTCPeerConnection(yourConfiguration, {
optional: [
{rtcStatsClientId: "your client identifier"},
{rtcStatsPeerId: "identifier for the current peer"},
{rtcStatsConferenceId: "identifier for the conference, e.g. room name"}
]
})
`If that integration is not possible there is a fallback integration which allows
sending per-client information about the user id and conference id. This
can be used by calling
`javascript
trace('identity', null, {user: 'your client identifier',
conference:'identifier for the conference, e.g. room name'});
``When using ontop of adapter it is typically not necessary (and potentially harmful) to shim the webkit and moz prefixes in addition to the unprefixed version.
Data regarding each event is sent to the server.
RTCPeerConnection methods are also hooked into and parameters sent to the server:
* createDataChannel
* addStream, removeStream
* addTrack
* removeTrack
* addTransceiver
* createOffer
* createAnswer
* setLocalDescription
* setRemoteDescription
* addIceCandidate
When a participant leaves a conference, the server will have a complete overview of the gum and peer connection flows.
At this point the server will begin extracting a “feature set”, which is sent to a database, once this is complete the statistics dump is stored on s3.
The s3 dump can be visualized, giving you an almost chrome://webrtc-internals view of the participants sessions see Importing the dumps.