Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.8.8 #31

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Revision 0.8.8 #31

merged 2 commits into from
Aug 13, 2024

Conversation

sinclairzx81
Copy link
Owner

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).

@sinclairzx81 sinclairzx81 merged commit dfd163d into master Aug 13, 2024
2 checks passed
@sinclairzx81 sinclairzx81 deleted the stat branch August 13, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant