Deleting a Publisher
You can delete a Publisher by calling its destroy() method:
Calling the destroy() method deletes the Publisher object and removes it from the HTML DOM.
Getting statistics about a publisher's stream
The Publisher.getStats() method provides you with an array of objects defining the current audio-video statistics for the publisher. For a publisher in a routed session (one that uses the Media Router), this array includes one object, defining the statistics for the single audio-media stream that is sent to the OpenTok Media Router. In a relayed session, the array includes an object for each subscriber to the published stream. Each object in the array contains a stats property that includes the following properties:
- The total number of audio and video packets sent
- The total number of audio and video packets lost
- The total number of audio and video bytes sent
- The current average video frame rate
Additionally, for a publisher in a relayed session, each object in the array contains the following two properties:
connectionId— The unique ID of the client's connection, which matches theidproperty of theconnectionproperty of theconnectionCreatedevent that the Session object dispatched for the remote client.subscriberId— The unique ID of the subscriber, which matches theidproperty of the Subscriber object in the subscribing client's app.
These two properties are undefined for a publisher in a routed session.
The following code logs the audio packet loss ratio, the audio bit rate, and the video packet loss ratio, and the video bit rate for the publisher's stream every second:
To get more detailed stream statistics, use the Publisher.getRtcStatsReport() method. It returns a promise that, on success, resolves with an array of RtcStatsReport objects:
Testing a publisher's stream
You can publish a test stream and check its audio and video statistics to determine the type of stream (such as high-resolution or audio-only) supported by your connection.
To get statistics for a stream published by the local client, you must use a session that uses the Media Router (sessions with the media mode set to routed), and you must set the testNetwork property to true in the options object you pass into the Session.subscribe() method. You can then use the getStats() method of the Subscriber object to get audio and video statistics for the stream you publish. See this tutorial for more information.