@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
51 lines (50 loc) • 1.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultClientIssueDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class DefaultClientIssueDecoder {
constructor() {
this._visited = false;
this._typeDecoder = new utils_1.StringToStringDecoder();
this._payloadDecoder = new utils_1.StringToStringDecoder();
this._timestampDecoder = new utils_1.NumberToNumberDecoder();
}
get visited() {
const result = this._visited;
this._visited = false;
return result;
}
reset() {
this._typeDecoder.reset();
this._payloadDecoder.reset();
this._timestampDecoder.reset();
}
decode(input) {
this._visited = true;
const type = this._typeDecoder.decode(input.type);
if (!type) {
Logger_1.logger.warn("Invalid client issue sample: missing type");
return undefined;
}
this._actualValue = {
type,
payload: this._payloadDecoder.decode(input.payload),
timestamp: this._timestampDecoder.decode(input.timestamp),
};
return this._actualValue;
}
get actualValue() {
return this._actualValue;
}
set actualValue(value) {
if (!value)
return;
this._visited = true;
this._actualValue = value;
this._typeDecoder.reset();
this._timestampDecoder.reset();
this._payloadDecoder.reset();
}
}
exports.DefaultClientIssueDecoder = DefaultClientIssueDecoder;