UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

115 lines (114 loc) 6.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IceTransportDecoder = void 0; const utils_1 = require("./utils"); const utils_2 = require("./utils"); const Logger_1 = require("./Logger"); class IceTransportDecoder { constructor(id, _attachmentsDecoder) { this.id = id; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._timestampDecoder = new utils_2.NumberToNumberDecoder(); this._packetsSentDecoder = new utils_2.NumberToNumberDecoder(); this._packetsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._bytesSentDecoder = new utils_1.BigIntToNumberDecoder(); this._bytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._iceRoleDecoder = new utils_2.StringToStringDecoder(); this._iceLocalUsernameFragmentDecoder = new utils_2.StringToStringDecoder(); this._dtlsStateDecoder = new utils_2.StringToStringDecoder(); this._iceStateDecoder = new utils_2.StringToStringDecoder(); this._selectedCandidatePairIdDecoder = new utils_2.StringToStringDecoder(); this._localCertificateIdDecoder = new utils_2.StringToStringDecoder(); this._remoteCertificateIdDecoder = new utils_2.StringToStringDecoder(); this._tlsVersionDecoder = new utils_2.StringToStringDecoder(); this._dtlsCipherDecoder = new utils_2.StringToStringDecoder(); this._dtlsRoleDecoder = new utils_2.StringToStringDecoder(); this._srtpCipherDecoder = new utils_2.StringToStringDecoder(); this._selectedCandidatePairChangesDecoder = new utils_2.NumberToNumberDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._timestampDecoder.reset(); this._packetsSentDecoder.reset(); this._packetsReceivedDecoder.reset(); this._bytesSentDecoder.reset(); this._bytesReceivedDecoder.reset(); this._iceRoleDecoder.reset(); this._iceLocalUsernameFragmentDecoder.reset(); this._dtlsStateDecoder.reset(); this._iceStateDecoder.reset(); this._selectedCandidatePairIdDecoder.reset(); this._localCertificateIdDecoder.reset(); this._remoteCertificateIdDecoder.reset(); this._tlsVersionDecoder.reset(); this._dtlsCipherDecoder.reset(); this._dtlsRoleDecoder.reset(); this._srtpCipherDecoder.reset(); this._selectedCandidatePairChangesDecoder.reset(); this._attachmentsDecoder.reset(); } decode(input) { this._visited = true; const timestamp = this._timestampDecoder.decode(input.timestamp); if (!timestamp) { Logger_1.logger.warn("Invalid ICE transport sample: missing timestamp or id"); return undefined; } this._actualValue = { id: this.id, timestamp, packetsSent: this._packetsSentDecoder.decode(input.packetsSent), packetsReceived: this._packetsReceivedDecoder.decode(input.packetsReceived), bytesSent: this._bytesSentDecoder.decode(input.bytesSent), bytesReceived: this._bytesReceivedDecoder.decode(input.bytesReceived), iceRole: this._iceRoleDecoder.decode(input.iceRole), iceLocalUsernameFragment: this._iceLocalUsernameFragmentDecoder.decode(input.iceLocalUsernameFragment), dtlsState: this._dtlsStateDecoder.decode(input.dtlsState), iceState: this._iceStateDecoder.decode(input.iceState), selectedCandidatePairId: this._selectedCandidatePairIdDecoder.decode(input.selectedCandidatePairId), localCertificateId: this._localCertificateIdDecoder.decode(input.localCertificateId), remoteCertificateId: this._remoteCertificateIdDecoder.decode(input.remoteCertificateId), tlsVersion: this._tlsVersionDecoder.decode(input.tlsVersion), dtlsCipher: this._dtlsCipherDecoder.decode(input.dtlsCipher), dtlsRole: this._dtlsRoleDecoder.decode(input.dtlsRole), srtpCipher: this._srtpCipherDecoder.decode(input.srtpCipher), selectedCandidatePairChanges: this._selectedCandidatePairChangesDecoder.decode(input.selectedCandidatePairChanges), 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._packetsSentDecoder.actualValue = sample.packetsSent; this._packetsReceivedDecoder.actualValue = sample.packetsReceived; this._bytesSentDecoder.actualValue = sample.bytesSent; this._bytesReceivedDecoder.actualValue = sample.bytesReceived; this._iceRoleDecoder.actualValue = sample.iceRole; this._iceLocalUsernameFragmentDecoder.actualValue = sample.iceLocalUsernameFragment; this._dtlsStateDecoder.actualValue = sample.dtlsState; this._iceStateDecoder.actualValue = sample.iceState; this._selectedCandidatePairIdDecoder.actualValue = sample.selectedCandidatePairId; this._localCertificateIdDecoder.actualValue = sample.localCertificateId; this._remoteCertificateIdDecoder.actualValue = sample.remoteCertificateId; this._tlsVersionDecoder.actualValue = sample.tlsVersion; this._dtlsCipherDecoder.actualValue = sample.dtlsCipher; this._dtlsRoleDecoder.actualValue = sample.dtlsRole; this._srtpCipherDecoder.actualValue = sample.srtpCipher; this._selectedCandidatePairChangesDecoder.actualValue = sample.selectedCandidatePairChanges; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.IceTransportDecoder = IceTransportDecoder;