@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
105 lines (104 loc) • 4.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IceCandidateDecoder = void 0;
const utils_1 = require("./utils");
const utils_2 = require("./utils");
const Logger_1 = require("./Logger");
class IceCandidateDecoder {
constructor(id, _attachmentsDecoder) {
this.id = id;
this._attachmentsDecoder = _attachmentsDecoder;
this._visited = false;
this._actualValue = undefined;
this._timestampDecoder = new utils_2.NumberToNumberDecoder();
this._idDecoder = new utils_2.StringToStringDecoder();
this._transportIdDecoder = new utils_2.StringToStringDecoder();
this._addressDecoder = new utils_2.StringToStringDecoder();
this._portDecoder = new utils_2.NumberToNumberDecoder();
this._protocolDecoder = new utils_2.StringToStringDecoder();
this._candidateTypeDecoder = new utils_2.StringToStringDecoder();
this._priorityDecoder = new utils_1.BigIntToNumberDecoder();
this._urlDecoder = new utils_2.StringToStringDecoder();
this._relayProtocolDecoder = new utils_2.StringToStringDecoder();
this._foundationDecoder = new utils_2.StringToStringDecoder();
this._relatedAddressDecoder = new utils_2.StringToStringDecoder();
this._relatedPortDecoder = new utils_2.NumberToNumberDecoder();
this._usernameFragmentDecoder = new utils_2.StringToStringDecoder();
this._tcpTypeDecoder = new utils_2.StringToStringDecoder();
}
get visited() {
const result = this._visited;
this._visited = false;
return result;
}
reset() {
this._timestampDecoder.reset();
this._idDecoder.reset();
this._transportIdDecoder.reset();
this._addressDecoder.reset();
this._portDecoder.reset();
this._protocolDecoder.reset();
this._candidateTypeDecoder.reset();
this._priorityDecoder.reset();
this._urlDecoder.reset();
this._relayProtocolDecoder.reset();
this._foundationDecoder.reset();
this._relatedAddressDecoder.reset();
this._relatedPortDecoder.reset();
this._usernameFragmentDecoder.reset();
this._tcpTypeDecoder.reset();
this._attachmentsDecoder.reset();
}
decode(input) {
this._visited = true;
const timestamp = this._timestampDecoder.decode(input.timestamp);
if (!timestamp) {
Logger_1.logger.warn("Invalid ICE candidate sample: missing timestamp or id");
return undefined;
}
this._actualValue = {
timestamp,
id: this.id,
transportId: this._transportIdDecoder.decode(input.transportId),
address: this._addressDecoder.decode(input.address),
port: this._portDecoder.decode(input.port),
protocol: this._protocolDecoder.decode(input.protocol),
candidateType: this._candidateTypeDecoder.decode(input.candidateType),
priority: this._priorityDecoder.decode(input.priority),
url: this._urlDecoder.decode(input.url),
relayProtocol: this._relayProtocolDecoder.decode(input.relayProtocol),
foundation: this._foundationDecoder.decode(input.foundation),
relatedAddress: this._relatedAddressDecoder.decode(input.relatedAddress),
relatedPort: this._relatedPortDecoder.decode(input.relatedPort),
usernameFragment: this._usernameFragmentDecoder.decode(input.usernameFragment),
tcpType: this._tcpTypeDecoder.decode(input.tcpType),
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._transportIdDecoder.actualValue = sample.transportId;
this._addressDecoder.actualValue = sample.address;
this._portDecoder.actualValue = sample.port;
this._protocolDecoder.actualValue = sample.protocol;
this._candidateTypeDecoder.actualValue = sample.candidateType;
this._priorityDecoder.actualValue = sample.priority;
this._urlDecoder.actualValue = sample.url;
this._relayProtocolDecoder.actualValue = sample.relayProtocol;
this._foundationDecoder.actualValue = sample.foundation;
this._relatedAddressDecoder.actualValue = sample.relatedAddress;
this._relatedPortDecoder.actualValue = sample.relatedPort;
this._usernameFragmentDecoder.actualValue = sample.usernameFragment;
this._tcpTypeDecoder.actualValue = sample.tcpType;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.IceCandidateDecoder = IceCandidateDecoder;