Search code examples
javascriptwebrtcrtcdatachannel

Measure data volume sent over RTCDataChannel


I have connected two users over a RTCdatachannel. This works, but I would like monitor the traffic generated by it, e.g 1Mbit/s. Is there a way to get this?

The motivation is that one user creates content and the other side mirrors this, kind of a remote support application. The use case requires the content (text, images, 3D models) to be updated very frequently (mainly the location), causing a traffic increase. When it reaches some set threshold, I would like to reduce the rate at which the application sends updates, but for that the application would need to know the currently consumed bandwidth.

I imagine I can write an interval that collects all the messages that were passed to the send function during one second and sum up the sizes, but maybe there is some built in way?


Solution

  • There is no built in API which will tell the amount of bandwidth or egress/ingress it consumed in total. You can measure these values by sum up the egress and ingress during the lifetime of a data channel.