feat: complete Ancestor quote bot with production-ready Docker support
This commit is contained in:
123
node_modules/matrix-js-sdk/lib/webrtc/stats/callStatsReportGatherer.js
generated
vendored
123
node_modules/matrix-js-sdk/lib/webrtc/stats/callStatsReportGatherer.js
generated
vendored
@@ -1,46 +1,52 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
"use strict";
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ConnectionStats } from "./connectionStats.js";
|
||||
import { ConnectionStatsBuilder } from "./connectionStatsBuilder.js";
|
||||
import { TransportStatsBuilder } from "./transportStatsBuilder.js";
|
||||
import { MediaSsrcHandler } from "./media/mediaSsrcHandler.js";
|
||||
import { MediaTrackHandler } from "./media/mediaTrackHandler.js";
|
||||
import { MediaTrackStatsHandler } from "./media/mediaTrackStatsHandler.js";
|
||||
import { TrackStatsBuilder } from "./trackStatsBuilder.js";
|
||||
import { ConnectionStatsReportBuilder } from "./connectionStatsReportBuilder.js";
|
||||
import { ValueFormatter } from "./valueFormatter.js";
|
||||
import { logger } from "../../logger.js";
|
||||
import { CallFeedStatsReporter } from "./callFeedStatsReporter.js";
|
||||
export class CallStatsReportGatherer {
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.CallStatsReportGatherer = void 0;
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _connectionStats = require("./connectionStats");
|
||||
var _connectionStatsBuilder = require("./connectionStatsBuilder");
|
||||
var _transportStatsBuilder = require("./transportStatsBuilder");
|
||||
var _mediaSsrcHandler = require("./media/mediaSsrcHandler");
|
||||
var _mediaTrackHandler = require("./media/mediaTrackHandler");
|
||||
var _mediaTrackStatsHandler = require("./media/mediaTrackStatsHandler");
|
||||
var _trackStatsBuilder = require("./trackStatsBuilder");
|
||||
var _connectionStatsReportBuilder = require("./connectionStatsReportBuilder");
|
||||
var _valueFormatter = require("./valueFormatter");
|
||||
var _logger = require("../../logger");
|
||||
var _callFeedStatsReporter = require("./callFeedStatsReporter");
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /*
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
class CallStatsReportGatherer {
|
||||
constructor(callId, opponentMemberId, pc, emitter, isFocus = true) {
|
||||
_defineProperty(this, "isActive", true);
|
||||
_defineProperty(this, "previousStatsReport", void 0);
|
||||
_defineProperty(this, "currentStatsReport", void 0);
|
||||
_defineProperty(this, "connectionStats", new ConnectionStats());
|
||||
_defineProperty(this, "trackStats", void 0);
|
||||
this.callId = callId;
|
||||
this.opponentMemberId = opponentMemberId;
|
||||
this.pc = pc;
|
||||
this.emitter = emitter;
|
||||
this.isFocus = isFocus;
|
||||
(0, _defineProperty2.default)(this, "isActive", true);
|
||||
(0, _defineProperty2.default)(this, "previousStatsReport", void 0);
|
||||
(0, _defineProperty2.default)(this, "currentStatsReport", void 0);
|
||||
(0, _defineProperty2.default)(this, "connectionStats", new _connectionStats.ConnectionStats());
|
||||
(0, _defineProperty2.default)(this, "trackStats", void 0);
|
||||
pc.addEventListener("signalingstatechange", this.onSignalStateChange.bind(this));
|
||||
this.trackStats = new MediaTrackStatsHandler(new MediaSsrcHandler(), new MediaTrackHandler(pc));
|
||||
this.trackStats = new _mediaTrackStatsHandler.MediaTrackStatsHandler(new _mediaSsrcHandler.MediaSsrcHandler(), new _mediaTrackHandler.MediaTrackHandler(pc));
|
||||
}
|
||||
async processStats(groupCallId, localUserId) {
|
||||
const summary = {
|
||||
@@ -67,10 +73,11 @@ export class CallStatsReportGatherer {
|
||||
};
|
||||
if (this.isActive) {
|
||||
const statsPromise = this.pc.getStats();
|
||||
if (typeof statsPromise?.then === "function") {
|
||||
if (typeof (statsPromise === null || statsPromise === void 0 ? void 0 : statsPromise.then) === "function") {
|
||||
return statsPromise.then(report => {
|
||||
var _this$connectionStats, _this$connectionStats2;
|
||||
// @ts-ignore
|
||||
this.currentStatsReport = typeof report?.result === "function" ? report.result() : report;
|
||||
this.currentStatsReport = typeof (report === null || report === void 0 ? void 0 : report.result) === "function" ? report.result() : report;
|
||||
try {
|
||||
this.processStatsReport(groupCallId, localUserId);
|
||||
} catch (error) {
|
||||
@@ -79,9 +86,9 @@ export class CallStatsReportGatherer {
|
||||
}
|
||||
this.previousStatsReport = this.currentStatsReport;
|
||||
summary.receivedMedia = this.connectionStats.bitrate.download;
|
||||
summary.receivedAudioMedia = this.connectionStats.bitrate.audio?.download || 0;
|
||||
summary.receivedVideoMedia = this.connectionStats.bitrate.video?.download || 0;
|
||||
const trackSummary = TrackStatsBuilder.buildTrackSummary(Array.from(this.trackStats.getTrack2stats().values()));
|
||||
summary.receivedAudioMedia = ((_this$connectionStats = this.connectionStats.bitrate.audio) === null || _this$connectionStats === void 0 ? void 0 : _this$connectionStats.download) || 0;
|
||||
summary.receivedVideoMedia = ((_this$connectionStats2 = this.connectionStats.bitrate.video) === null || _this$connectionStats2 === void 0 ? void 0 : _this$connectionStats2.download) || 0;
|
||||
const trackSummary = _trackStatsBuilder.TrackStatsBuilder.buildTrackSummary(Array.from(this.trackStats.getTrack2stats().values()));
|
||||
return _objectSpread(_objectSpread({}, summary), {}, {
|
||||
audioTrackSummary: trackSummary.audioTrackSummary,
|
||||
videoTrackSummary: trackSummary.videoTrackSummary
|
||||
@@ -96,15 +103,16 @@ export class CallStatsReportGatherer {
|
||||
return Promise.resolve(summary);
|
||||
}
|
||||
processStatsReport(groupCallId, localUserId) {
|
||||
var _this$currentStatsRep;
|
||||
const byteSentStatsReport = new Map();
|
||||
byteSentStatsReport.callId = this.callId;
|
||||
byteSentStatsReport.opponentMemberId = this.opponentMemberId;
|
||||
this.currentStatsReport?.forEach(now => {
|
||||
(_this$currentStatsRep = this.currentStatsReport) === null || _this$currentStatsRep === void 0 ? void 0 : _this$currentStatsRep.forEach(now => {
|
||||
const before = this.previousStatsReport ? this.previousStatsReport.get(now.id) : null;
|
||||
// RTCIceCandidatePairStats - https://w3c.github.io/webrtc-stats/#candidatepair-dict*
|
||||
if (now.type === "candidate-pair" && now.nominated && now.state === "succeeded") {
|
||||
this.connectionStats.bandwidth = ConnectionStatsBuilder.buildBandwidthReport(now);
|
||||
this.connectionStats.transport = TransportStatsBuilder.buildReport(this.currentStatsReport, now, this.connectionStats.transport, this.isFocus);
|
||||
this.connectionStats.bandwidth = _connectionStatsBuilder.ConnectionStatsBuilder.buildBandwidthReport(now);
|
||||
this.connectionStats.transport = _transportStatsBuilder.TransportStatsBuilder.buildReport(this.currentStatsReport, now, this.connectionStats.transport, this.isFocus);
|
||||
|
||||
// RTCReceivedRtpStreamStats
|
||||
// https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*
|
||||
@@ -116,7 +124,7 @@ export class CallStatsReportGatherer {
|
||||
return;
|
||||
}
|
||||
if (before) {
|
||||
TrackStatsBuilder.buildPacketsLost(trackStats, now, before);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildPacketsLost(trackStats, now, before);
|
||||
}
|
||||
|
||||
// Get the resolution and framerate for only remote video sources here. For the local video sources,
|
||||
@@ -125,30 +133,30 @@ export class CallStatsReportGatherer {
|
||||
// more calculations needed to determine what is the highest resolution stream sent by the client if the
|
||||
// 'outbound-rtp' stats are used.
|
||||
if (now.type === "inbound-rtp") {
|
||||
TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
||||
if (before) {
|
||||
TrackStatsBuilder.buildBitrateReceived(trackStats, now, before);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildBitrateReceived(trackStats, now, before);
|
||||
}
|
||||
const ts = this.trackStats.findTransceiverByTrackId(trackStats.trackId);
|
||||
TrackStatsBuilder.setTrackStatsState(trackStats, ts);
|
||||
TrackStatsBuilder.buildJitter(trackStats, now);
|
||||
TrackStatsBuilder.buildAudioConcealment(trackStats, now);
|
||||
_trackStatsBuilder.TrackStatsBuilder.setTrackStatsState(trackStats, ts);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildJitter(trackStats, now);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildAudioConcealment(trackStats, now);
|
||||
} else if (before) {
|
||||
byteSentStatsReport.set(trackStats.trackId, ValueFormatter.getNonNegativeValue(now.bytesSent));
|
||||
TrackStatsBuilder.buildBitrateSend(trackStats, now, before);
|
||||
byteSentStatsReport.set(trackStats.trackId, _valueFormatter.ValueFormatter.getNonNegativeValue(now.bytesSent));
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildBitrateSend(trackStats, now, before);
|
||||
}
|
||||
TrackStatsBuilder.buildCodec(this.currentStatsReport, trackStats, now);
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildCodec(this.currentStatsReport, trackStats, now);
|
||||
} else if (now.type === "track" && now.kind === "video" && !now.remoteSource) {
|
||||
const trackStats = this.trackStats.findLocalVideoTrackStats(now);
|
||||
if (!trackStats) {
|
||||
return;
|
||||
}
|
||||
TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
||||
TrackStatsBuilder.calculateSimulcastFramerate(trackStats, now, before, this.trackStats.mediaTrackHandler.getActiveSimulcastStreams());
|
||||
_trackStatsBuilder.TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
||||
_trackStatsBuilder.TrackStatsBuilder.calculateSimulcastFramerate(trackStats, now, before, this.trackStats.mediaTrackHandler.getActiveSimulcastStreams());
|
||||
}
|
||||
});
|
||||
this.emitter.emitByteSendReport(byteSentStatsReport);
|
||||
this.emitter.emitCallFeedReport(CallFeedStatsReporter.buildCallFeedReport(this.callId, this.opponentMemberId, this.pc));
|
||||
this.emitter.emitCallFeedReport(_callFeedStatsReporter.CallFeedStatsReporter.buildCallFeedReport(this.callId, this.opponentMemberId, this.pc));
|
||||
this.processAndEmitConnectionStatsReport();
|
||||
}
|
||||
setActive(isActive) {
|
||||
@@ -159,10 +167,10 @@ export class CallStatsReportGatherer {
|
||||
}
|
||||
handleError(error) {
|
||||
this.isActive = false;
|
||||
logger.warn(`CallStatsReportGatherer ${this.callId} processStatsReport fails and set to inactive ${error}`);
|
||||
_logger.logger.warn(`CallStatsReportGatherer ${this.callId} processStatsReport fails and set to inactive ${error}`);
|
||||
}
|
||||
processAndEmitConnectionStatsReport() {
|
||||
const report = ConnectionStatsReportBuilder.build(this.trackStats.getTrack2stats());
|
||||
const report = _connectionStatsReportBuilder.ConnectionStatsReportBuilder.build(this.trackStats.getTrack2stats());
|
||||
report.callId = this.callId;
|
||||
report.opponentMemberId = this.opponentMemberId;
|
||||
this.connectionStats.bandwidth = report.bandwidth;
|
||||
@@ -188,4 +196,5 @@ export class CallStatsReportGatherer {
|
||||
this.opponentMemberId = id;
|
||||
}
|
||||
}
|
||||
exports.CallStatsReportGatherer = CallStatsReportGatherer;
|
||||
//# sourceMappingURL=callStatsReportGatherer.js.map
|
||||
Reference in New Issue
Block a user