@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
66 lines (65 loc) • 2.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InboundTrackDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class InboundTrackDecoder {
constructor(id, _attachmentsDecoder) {
this.id = id;
this._attachmentsDecoder = _attachmentsDecoder;
this._visited = false;
this._actualValue = undefined;
this._timestampDecoder = new utils_1.NumberToNumberDecoder();
this._idDecoder = new utils_1.StringToStringDecoder();
this._kindDecoder = new utils_1.StringToStringDecoder();
this._scoreDecoder = new utils_1.NumberToNumberDecoder();
this._scoreReasonsDecoder = new utils_1.StringToStringDecoder();
}
get visited() {
const result = this._visited;
this._visited = false;
return result;
}
reset() {
this._timestampDecoder.reset();
this._idDecoder.reset();
this._kindDecoder.reset();
this._scoreDecoder.reset();
this._scoreReasonsDecoder.reset();
this._attachmentsDecoder.reset();
}
decode(input) {
this._visited = true;
const timestamp = this._timestampDecoder.decode(input.timestamp);
const kind = this._kindDecoder.decode(input.kind);
if (!timestamp || kind === undefined) {
Logger_1.logger.warn("Invalid inbound track sample: missing timestamp or id");
return undefined;
}
this._actualValue = {
timestamp,
id: this.id,
kind,
score: this._scoreDecoder.decode(input.score),
scoreReasons: this._scoreReasonsDecoder.decode(input.scoreReasons),
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._idDecoder.actualValue = sample.id;
this._kindDecoder.actualValue = sample.kind;
this._scoreDecoder.actualValue = sample.score;
this._scoreReasonsDecoder.actualValue = sample.scoreReasons;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.InboundTrackDecoder = InboundTrackDecoder;