|
@@ -468,6 +468,32 @@ TraceablePeerConnection.prototype._getDesiredMediaDirection = function(
|
468
|
468
|
return 'inactive';
|
469
|
469
|
};
|
470
|
470
|
|
|
471
|
+/**
|
|
472
|
+ * Returns the list of RTCRtpReceivers created for the source of the given media type associated with
|
|
473
|
+ * the set of remote endpoints specified.
|
|
474
|
+ * @param {Array<string>} endpoints list of the endpoints
|
|
475
|
+ * @param {string} mediaType 'audio' or 'video'
|
|
476
|
+ * @returns {Array<RTCRtpReceiver>} list of receivers created by the peerconnection.
|
|
477
|
+ */
|
|
478
|
+TraceablePeerConnection.prototype._getReceiversByEndpointIds = function(endpoints, mediaType) {
|
|
479
|
+ let remoteTracks = [];
|
|
480
|
+ let receivers = [];
|
|
481
|
+
|
|
482
|
+ for (const endpoint of endpoints) {
|
|
483
|
+ remoteTracks = remoteTracks.concat(this.getRemoteTracks(endpoint, mediaType));
|
|
484
|
+ }
|
|
485
|
+
|
|
486
|
+ // Get the ids of the MediaStreamTracks associated with each of these remote tracks.
|
|
487
|
+ const remoteTrackIds = remoteTracks.map(remote => remote.track?.id);
|
|
488
|
+
|
|
489
|
+ receivers = this.peerconnection.getReceivers()
|
|
490
|
+ .filter(receiver => receiver.track
|
|
491
|
+ && receiver.track.kind === mediaType
|
|
492
|
+ && remoteTrackIds.find(trackId => trackId === receiver.track.id));
|
|
493
|
+
|
|
494
|
+ return receivers;
|
|
495
|
+};
|
|
496
|
+
|
471
|
497
|
/**
|
472
|
498
|
* Tells whether or not this TPC instance is using Simulcast.
|
473
|
499
|
* @return {boolean} <tt>true</tt> if simulcast is enabled and active or
|
|
@@ -526,16 +552,17 @@ TraceablePeerConnection.prototype._peerMutedChanged = function(
|
526
|
552
|
};
|
527
|
553
|
|
528
|
554
|
/**
|
529
|
|
- * Obtains audio levels of the remote audio tracks by getting the source
|
530
|
|
- * information on the RTCRtpReceivers. The information relevant to the ssrc
|
531
|
|
- * is updated each time a RTP packet constaining the ssrc is received.
|
532
|
|
- * @returns {Object} containing ssrc and audio level information as a
|
533
|
|
- * key-value pair.
|
|
555
|
+ * Obtains audio levels of the remote audio tracks by getting the source information on the RTCRtpReceivers.
|
|
556
|
+ * The information relevant to the ssrc is updated each time a RTP packet constaining the ssrc is received.
|
|
557
|
+ * @param {Array<string>} speakerList list of endpoint ids for which audio levels are to be gathered.
|
|
558
|
+ * @returns {Object} containing ssrc and audio level information as a key-value pair.
|
534
|
559
|
*/
|
535
|
|
-TraceablePeerConnection.prototype.getAudioLevels = function() {
|
|
560
|
+TraceablePeerConnection.prototype.getAudioLevels = function(speakerList = []) {
|
536
|
561
|
const audioLevels = {};
|
537
|
|
- const audioReceivers = this.peerconnection.getReceivers()
|
538
|
|
- .filter(receiver => receiver.track && receiver.track.kind === MediaType.AUDIO);
|
|
562
|
+ const audioReceivers = speakerList.length
|
|
563
|
+ ? this._getReceiversByEndpointIds(speakerList, MediaType.AUDIO)
|
|
564
|
+ : this.peerconnection.getReceivers()
|
|
565
|
+ .filter(receiver => receiver.track && receiver.track.kind === MediaType.AUDIO && receiver.track.enabled);
|
539
|
566
|
|
540
|
567
|
audioReceivers.forEach(remote => {
|
541
|
568
|
const ssrc = remote.getSynchronizationSources();
|