@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
77 lines (76 loc) • 3.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodecStatsDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class CodecStatsDecoder {
constructor(id, _attachmentsDecoder) {
this.id = id;
this._attachmentsDecoder = _attachmentsDecoder;
this._visited = false;
this._actualValue = undefined;
this._timestampDecoder = new utils_1.NumberToNumberDecoder();
this._typeDecoder = new utils_1.StringToStringDecoder();
this._payloadTypeDecoder = new utils_1.NumberToNumberDecoder();
this._transportIdDecoder = new utils_1.StringToStringDecoder();
this._mimeTypeDecoder = new utils_1.StringToStringDecoder();
this._clockRateDecoder = new utils_1.NumberToNumberDecoder();
this._channelsDecoder = new utils_1.NumberToNumberDecoder();
this._sdpFmtpLineDecoder = new utils_1.StringToStringDecoder();
}
get visited() {
const result = this._visited;
this._visited = false;
return result;
}
reset() {
this._attachmentsDecoder.reset();
this._channelsDecoder.reset();
this._clockRateDecoder.reset();
this._mimeTypeDecoder.reset();
this._payloadTypeDecoder.reset();
this._sdpFmtpLineDecoder.reset();
this._timestampDecoder.reset();
this._transportIdDecoder.reset();
this._typeDecoder.reset();
}
decode(input) {
this._visited = true;
const timestamp = this._timestampDecoder.decode(input.timestamp);
const mimeType = this._mimeTypeDecoder.decode(input.mimeType);
if (!timestamp || mimeType === undefined) {
Logger_1.logger.warn("Invalid codec stats sample: missing timestamp or id");
return undefined;
}
this._actualValue = {
id: this.id,
timestamp,
payloadType: this._payloadTypeDecoder.decode(input.payloadType),
transportId: this._transportIdDecoder.decode(input.transportId),
mimeType,
clockRate: this._clockRateDecoder.decode(input.clockRate),
channels: this._channelsDecoder.decode(input.channels),
sdpFmtpLine: this._sdpFmtpLineDecoder.decode(input.sdpFmtpLine),
attachments: this._attachmentsDecoder.decode(input.attachments),
};
return this._actualValue;
}
get actualValue() {
return this._actualValue;
}
set actualValue(sample) {
if (!sample)
return;
this._visited = true;
this._actualValue = sample;
this._timestampDecoder.actualValue = sample.timestamp;
this._payloadTypeDecoder.actualValue = sample.payloadType;
this._transportIdDecoder.actualValue = sample.transportId;
this._mimeTypeDecoder.actualValue = sample.mimeType;
this._clockRateDecoder.actualValue = sample.clockRate;
this._channelsDecoder.actualValue = sample.channels;
this._sdpFmtpLineDecoder.actualValue = sample.sdpFmtpLine;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.CodecStatsDecoder = CodecStatsDecoder;