@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
61 lines (60 loc) • 2.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PeerConnectionTransportDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class PeerConnectionTransportDecoder {
constructor(id, _attachmentsDecoder) {
this.id = id;
this._attachmentsDecoder = _attachmentsDecoder;
this._visited = false;
this._actualValue = undefined;
this._idDecoder = new utils_1.StringToStringDecoder();
this._timestampDecoder = new utils_1.NumberToNumberDecoder();
this._dataChannelsOpenedDecoder = new utils_1.NumberToNumberDecoder();
this._dataChannelsClosedDecoder = new utils_1.NumberToNumberDecoder();
}
get visited() {
const result = this._visited;
this._visited = false;
return result;
}
reset() {
this._idDecoder.reset();
this._timestampDecoder.reset();
this._dataChannelsOpenedDecoder.reset();
this._dataChannelsClosedDecoder.reset();
this._attachmentsDecoder.reset();
}
decode(input) {
this._visited = true;
const timestamp = this._timestampDecoder.decode(input.timestamp);
if (!timestamp) {
Logger_1.logger.warn("Invalid peer connection transport sample: missing timestamp or id");
return undefined;
}
this._actualValue = {
id: this.id,
timestamp,
dataChannelsOpened: this._dataChannelsOpenedDecoder.decode(input.dataChannelsOpened),
dataChannelsClosed: this._dataChannelsClosedDecoder.decode(input.dataChannelsClosed),
attachments: this._attachmentsDecoder.decode(input.attachments),
};
return this._actualValue;
}
get actualValue() {
return this._actualValue;
}
set actualValue(sample) {
if (!sample)
return;
this._actualValue = sample;
this._visited = true;
this._timestampDecoder.actualValue = sample.timestamp;
this._idDecoder.actualValue = sample.id;
this._dataChannelsOpenedDecoder.actualValue = sample.dataChannelsOpened;
this._dataChannelsClosedDecoder.actualValue = sample.dataChannelsClosed;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.PeerConnectionTransportDecoder = PeerConnectionTransportDecoder;