add screenshare's peer information to video stats in connection status modal

Added support for getStats in screenshare's service. This works similar
to the getStats for video provider, and the information retrieved from
screenshare is added to the video information for cameras.
This commit is contained in:
Mario Jr 2021-08-23 12:36:01 -03:00
parent 46e4066f6e
commit 00e01c1872
5 changed files with 89 additions and 5 deletions

View File

@ -53,6 +53,26 @@ export default class KurentoScreenshareBridge {
this._gdmStream = stream; this._gdmStream = stream;
} }
/**
* Get the RTCPeerConnection object related to the screensharing stream.
* @returns {Object} The RTCPeerConnection object related to the presenter/
* viewer peer. If there's no stream being shared, returns
* null.
*/
getPeerConnection() {
try {
let peerConnection = null;
if (this.broker && this.broker.webRtcPeer) {
peerConnection = this.broker.webRtcPeer.peerConnection;
}
return peerConnection;
} catch (error) {
return null;
}
}
outboundStreamReconnect() { outboundStreamReconnect() {
const currentRestartIntervalMs = this.restartIntervalMs; const currentRestartIntervalMs = this.restartIntervalMs;
const stream = this.gdmStream; const stream = this.gdmStream;

View File

@ -10,6 +10,7 @@ import { notify } from '/imports/ui/services/notification';
import { makeCall } from '/imports/ui/services/api'; import { makeCall } from '/imports/ui/services/api';
import AudioService from '/imports/ui/components/audio/service'; import AudioService from '/imports/ui/components/audio/service';
import VideoService from '/imports/ui/components/video-provider/service'; import VideoService from '/imports/ui/components/video-provider/service';
import ScreenshareService from '/imports/ui/components/screenshare/service';
const STATS = Meteor.settings.public.stats; const STATS = Meteor.settings.public.stats;
const NOTIFICATION = STATS.notification; const NOTIFICATION = STATS.notification;
@ -352,7 +353,7 @@ const addExtraInboundNetworkParameters = (data) => {
}; };
/** /**
* Retrieves the inbound and outbound data using WebRTC getStats API. * Retrieves the inbound and outbound data using WebRTC getStats API, for audio.
* @returns An Object with format (property:type) : * @returns An Object with format (property:type) :
* { * {
* transportStats: Object, * transportStats: Object,
@ -374,12 +375,23 @@ const getAudioData = async () => {
return data; return data;
}; };
/**
* Retrieves the inbound and outbound data using WebRTC getStats API, for video.
* The video stats contains the stats about all video peers (cameras) and
* for screenshare peer appended into one single object, containing the id
* of the peers with it's stats information.
* @returns An Object containing video data for all video peers and screenshare
* peer
*/
const getVideoData = async () => { const getVideoData = async () => {
const data = await VideoService.getStats(); const camerasData = await VideoService.getStats() || {};
if (!data) return {}; const screenshareData = await ScreenshareService.getStats() || {};
return data; return {
...camerasData,
...screenshareData,
};
}; };
/** /**

View File

@ -12,6 +12,14 @@ import {Meteor} from "meteor/meteor";
const SCREENSHARE_MEDIA_ELEMENT_NAME = 'screenshareVideo'; const SCREENSHARE_MEDIA_ELEMENT_NAME = 'screenshareVideo';
/**
* Screenshare status to be filtered in getStats()
*/
const FILTER_SCREENSHARE_STATS = [
'outbound-rtp',
'inbound-rtp',
];
let _isSharingScreen = false; let _isSharingScreen = false;
const _sharingScreenDep = { const _sharingScreenDep = {
value: false, value: false,
@ -144,6 +152,41 @@ const screenShareEndAlert = () => AudioService
const dataSavingSetting = () => Settings.dataSaving.viewScreenshare; const dataSavingSetting = () => Settings.dataSaving.viewScreenshare;
/**
* Get stats about all active screenshare peer.
* We filter the status based on FILTER_SCREENSHARE_STATS constant.
*
* For more information see:
* https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
* and
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
* @returns An Object containing the information about each active peer
* (currently one, for screenshare). The returned format
* follows the format returned by video's service getStats, which
* considers more than one peer connection to be returned.
* The format is given by:
* {
* peerIdString: RTCStatsReport
* }
*/
const getStats = async () => {
const peer = KurentoBridge.getPeerConnection();
if (!peer) return null;
const peerStats = await peer.getStats();
const screenshareStats = {};
peerStats.forEach((stat) => {
if (FILTER_SCREENSHARE_STATS.includes(stat.type)) {
screenshareStats[stat.type] = stat;
}
});
return { screenshareStats };
};
export { export {
SCREENSHARE_MEDIA_ELEMENT_NAME, SCREENSHARE_MEDIA_ELEMENT_NAME,
isVideoBroadcasting, isVideoBroadcasting,
@ -157,4 +200,5 @@ export {
getMediaElement, getMediaElement,
attachLocalPreviewStream, attachLocalPreviewStream,
isGloballyBroadcasting, isGloballyBroadcasting,
getStats,
}; };

View File

@ -854,7 +854,13 @@ class VideoService {
* *
* For more information see: * For more information see:
* https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats * https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
* @returns An Object containing the information about each active peer * and
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
* @returns An Object containing the information about each active peer.
* The returned object follows the format:
* {
* peerId: RTCStatsReport
* }
*/ */
async getStats() { async getStats() {
const peers = this.getActivePeers(); const peers = this.getActivePeers();

View File

@ -838,6 +838,8 @@ class AudioManager {
* *
* For more information see: * For more information see:
* https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats * https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
* and
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
*/ */
async getStats() { async getStats() {
const bridge = this.getCurrentBridge(); const bridge = this.getCurrentBridge();