This PR adds a .stats() function to return current WebRTC network statistics. This is a synchronous function that can be called at relatively high frequency. The following is the API.
import { Network } from '@sinclair/smoke'
const { WebRtc } = new Network({ ... })
const stats = WebRtc.stats()
This function will return an array of WebRtcPeerStatistics structures of the following form.
// ------------------------------------------------------------------
// WebRtcPeerStatistic
// ------------------------------------------------------------------
export interface WebRtcPeerStatistic {
/** The local address of this peer */
localAddress: string
/** The remote address of this peer */
remoteAddress: string
/** If this peer is making an offer */
makingOffer: boolean
/** If this peer is ignoring offers */
ignoreOffer: boolean
/** The number of bytes sent to this peer */
bytesSent: number
/** The number of bytes received from this peer */
bytesReceived: number
/** The number of send bytes being buffered for this peer */
bytesBuffered: number
/** The number of data channels being managed by this peer */
channelCount: number
}
Note: As of this PR, the bytesReceived and bytesSent totals are accumulated inside the NetModule (not inside the WebRtcModule). While the bytesReceived could technically be handled via the WebRtcModule, this update holds that all interactions with a channel (including subscribing to message events) should be handled exterior to the WebRtcModule (where the WebRtcModule is limited to peer connection establishment only, not interactions with channels or media on that connection).
This PR adds a
.stats()
function to return current WebRTC network statistics. This is a synchronous function that can be called at relatively high frequency. The following is the API.This function will return an array of
WebRtcPeerStatistics
structures of the following form.Note: As of this PR, the
bytesReceived
andbytesSent
totals are accumulated inside theNetModule
(not inside theWebRtcModule
). While thebytesReceived
could technically be handled via theWebRtcModule
, this update holds that all interactions with a channel (including subscribing to message events) should be handled exterior to theWebRtcModule
(where theWebRtcModule
is limited to peer connection establishment only, not interactions with channels or media on that connection).