All Projects → peermetrics → webrtc-stats

peermetrics / webrtc-stats

Licence: MIT License
Helps you collect stats for peer connections

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to webrtc-stats

foxrtc
media sdk based on webrtc
Stars: ✭ 36 (+16.13%)
Mutual labels:  webrtc, webrtc-tools
Webrtc Experiment
WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
Stars: ✭ 10,335 (+33238.71%)
Mutual labels:  webrtc, webrtc-tools
client-sdk-js
LiveKit browser client SDK (javascript)
Stars: ✭ 114 (+267.74%)
Mutual labels:  webrtc
chattery
A GitHub action that creates chatrooms for pull requests
Stars: ✭ 30 (-3.23%)
Mutual labels:  webrtc
ion-avp
Audio/Video Processing Service
Stars: ✭ 55 (+77.42%)
Mutual labels:  webrtc
webtorrent-dht
This is an example implementation of something that might become WebTorrent DHT
Stars: ✭ 26 (-16.13%)
Mutual labels:  webrtc
docker-nvidia-glx-desktop
MATE Desktop container designed for Kubernetes supporting OpenGL GLX and Vulkan for NVIDIA GPUs with WebRTC and HTML5, providing an open source remote cloud graphics or game streaming platform. Spawns its own fully isolated X Server instead of using the host X server, therefore not requiring /tmp/.X11-unix host sockets or host configuration.
Stars: ✭ 47 (+51.61%)
Mutual labels:  webrtc
onchat-web
A simple, beautiful, mobile-first instant messaging progressive web application.
Stars: ✭ 138 (+345.16%)
Mutual labels:  webrtc
easy-voice-call
A self-hosting voice chating App
Stars: ✭ 30 (-3.23%)
Mutual labels:  webrtc
apprtc-go
apprtc demo with golang.It's rewrite project WebRTC(https://github.com/webrtc/apprtc) with golang
Stars: ✭ 17 (-45.16%)
Mutual labels:  webrtc
Tubumu.Abp.Meeting
An abp module to create meeting app quickly.
Stars: ✭ 15 (-51.61%)
Mutual labels:  webrtc
securbot
Security robot prototype
Stars: ✭ 20 (-35.48%)
Mutual labels:  webrtc
spectacle-sync
💁 Present Spectacle presentations synchronised on multiple devices
Stars: ✭ 57 (+83.87%)
Mutual labels:  webrtc
Diffy
🎞️💓🍿 Love streaming - It's always best to watch a movie together ! 🤗
Stars: ✭ 37 (+19.35%)
Mutual labels:  webrtc
singo
Simple WebRTC Signaling Server written in Go
Stars: ✭ 57 (+83.87%)
Mutual labels:  webrtc
baresip-webrtc
Baresip WebRTC Demo
Stars: ✭ 33 (+6.45%)
Mutual labels:  webrtc
Study-Room
Connect and study together with friends over text and voice channels, over a click of a button. Web application for chat and audio streaming.
Stars: ✭ 21 (-32.26%)
Mutual labels:  webrtc
RTCEngine-server
WebRTC Media Server that scales well
Stars: ✭ 20 (-35.48%)
Mutual labels:  webrtc
node-sctp
SCTP userspace sockets for Node.js
Stars: ✭ 47 (+51.61%)
Mutual labels:  webrtc
sdp
A Go implementation of the SDP
Stars: ✭ 89 (+187.1%)
Mutual labels:  webrtc

WebRTCStats

WebRTCStats is the most complete utility belt that helps with everything related to getting and parsing the stats for WebRTC PeerConnections.

The main advantage of WebRTCStats is that it parses and groups the stats from PeerConnections and offers them in a easy to read way

On top of that, it offers the timeline which is a list of all the events fired while setting up a PeerConnection. Optionally, you can also wrap getUserMedia to get a better picture.

WebRTCStats extends EventEmitter and uses the same event system to communicate with the rest of the app.

Migrating from v4

To see the changes that appeared in V5 see the changelog

Install

npm install @peermetrics/webrtc-stats

Usage

Loading the module

WebRTC Stats can be loaded as an ES6 module, node module or directly in the browser.

After loading, the library needs to be initialized. See Options for all the initialize options

import {WebRTCStats} from '@peermetrics/webrtc-stats'

let webrtcStats = new WebRTCStats({
    getStatsInterval: 5000
})

Add event listeners for stats:

webrtcStats.on('stats', (ev) => {
    console.log('stats', ev)
})

Use addConnection to add connections to the list of monitored peers:

let pc1 = new RTCPeerConnection({...})
webrtcStats.addConnection({
    pc: pc1, // RTCPeerConnection instance
    peerId: '1', // any string that helps you identify this peer,
   	connectionId: '06d54adc-e478-4f95-9144-bbb3562a2aad', // optional, an id that you can use to keep track of this connection
    remote: false // optional, override the global remote flag
})

Now every 5000 ms WebRTCStats will fire the stats event which will come with the object:

{
    event: 'stats',
    tag: 'stats',
    peerId: '1',
    timestamp: 'Sun Mar 22 2020 18:02:02', // a timestamp when this was fired
    data: {...}, // an object created after parsing the stats
    timeTaken: 5, // how many ms the .getStats() call took
    rawStats: RTCStatsReport, // the actual RTCStatsReport results from `getStats()`
    statsObject: {}, // an object created from RTCStatsReport that uses the `id` for each report as a key
    filteredStats: {}, // same as statsObject but with some report types filtered out (eg: `codec`, `certificate`)
}

Options

The module accepts the following options when initialized:

let stats = new WebRTCStats({
    // the interval in ms of how often we should get stats
    getStatsInterval: 5000, // Default: 1000

    // if we should include the original RTCStatsReport map when firing the `stats` event
    rawStats: false, // Default: false

    // include an object that resulted from transforming RTCStatsReport into an oject (`report.id` as the key)
    statsObject: true, // Default: false
    
    // if we should filter out some stats
    filteredStats: false, // Default: false

    // If the data object should contain a remote attribute that will contain stats for the remote peer, from `remote-inbound-rtp`, etc
    remote: true, // Default: true

    // If we should wrap the `geUserMedia` calls so we can gather events when the methods is called or success/error
    wrapGetUserMedia: false, // Default: false
    
    // If we should log messages
    debug: false, // Default: false
    
    // What kind of level of logs the lib should display. Values: 'none', 'error', 'warn', 'info', 'debug'
    logLevel: 'warn' // Default: 'none'
})

API

.addConnection(options)

Adds a connection to the watch list. options

  • pc: the RTCPeerConnection instance
  • peerId: String a unique Id to identify this peer Monitoring of a peer will automatically end when the connection is closed.
  • connectionId: optional, string. A way to identify this connection. If a connectionId is not offered, the lib will assign a random one

Returns:

{
    connectionId: '', // the ID assigned to this connection
}

.removeConnection(options)

Removes the RTCPeerConnection from the list of watched connections for that peer.

options object:

  • peerId: the peer id for which we want to remove the connection

  • pc: The RTCPeerConnection instance we want to remove

    or

  • connectionId: the id of the connection (the one returned when calling .addConnection())

.removePeer(peerId)

Stop listening for events/stats on all connections for this peer

.getTimeline([filter])

Return the array of events from the timeline up to that point. If the optional filter string is present it will filter out events. Possible values: peer, connection, track, stats, getUserMedia

.addPeer(peerId, pc) - Deprecated

This method is deprecated, please use .addConnection() instead

Events

The module uses EventEmitter to emit events. You can listen to them using .on()

stats.on('eventName', (ev) => {
})

ev will have the following structure:

{
    // The event name. Usually the method called (addTrack, createAnswer)
    event: '',
    // The tag for this event. `stats`, `sdp`, `getUserMedia`, etc
    tag: '',
    // The id for the peer that fired this event
    peerId: '',
    // A timestamp for when the event happened
    timestamp: '',
    // Data for each event type
    data: {},
    
    // The following attrs appear at certain times
    // The error that appeared in the method we were watching
    error: {},
    // These appear on the `stats` event
    rawStats: {},
    statsObject: {},
    filteredStats: {}
}

List of fired events

The tags for the events fired by WebRTCStats are:

  • timeline: this will fire when something has been added to the timeline. This event is a duplicate of the following events
  • stats: fired for each peer when we've collected stats for it
  • getUserMedia: when getUserMedia is called initially
  • peer: when a peer was added
  • track: a track event: addTrack, removeTrack, mute, unmute, overconstrained
  • connection: any event related to connection
  • datachannel: any datachannel event

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].