Getting statistics about a publisher's stream

The OTPublisher audioNetworkStats and audioNetworkStats events provide an array of objects defining the current audio or video statistics for the publisher. For a publisher in a routed session (one that uses the Media Router), these event arrays each include one object, defining the statistics for the audio or video that is sent to the Media Router. In a relayed session, the array includes an object for each subscriber to the published stream. Each object in the array has the following properties:

videoBytesSent — The total number of audio and video bytes sent videoPacketsSent — The total number of audio and video packets sent videoPacketsSent — The total number of audio and video packets lost Additionally, for a publisher in a relayed session, each object in the array contains the following two properties:

connectionId — The unique ID of the subscribing client's connection, which matches the connectionId property of the connectionCreated event for that client's connection.

subscriberId — The unique ID of the subscriber.

The following code logs these stats for the publisher's stream every second:

To get more detailed stream statics, use the OTPublisher.getRtcStatsReport() method. Calling this method results in the OTPublisher instance dispatching an rtcStatsReport event:

For a publisher in a routed session, event array includes one object, defining the stats of the stream sent to the OpenTok Media Router. In a relayed session, the array includes an object defining the RTC Stats Reports for each subscriber to the published stream. Each object in the array has a jsonArrayOfReports property that includes the data. The structure of the JSON array is similar to the format of the RtcStatsReport object implemented in web browsers (see the Mozilla docs). Also see this W3C documentation.