UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

178 lines (177 loc) 10.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IceCandidatePairStatsEnumDecoder = exports.IceCandidatePairDecoder = void 0; const utils_1 = require("./utils"); const InputSamples_1 = require("./InputSamples"); // import { // IceCandidatePairStats as OutputIceCandidatePairStats, // ClientSample_PeerConnectionSample_IceCandidatePairStats as InputIceCandidatePairStats, // ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum as InputIceCandidatePairState // } from "./InputOutputSamples"; const utils_2 = require("./utils"); const Logger_1 = require("./Logger"); class IceCandidatePairDecoder { constructor(id, _attachmentsDecoder) { this.id = id; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._availableIncomingBitrateDecoder = new utils_2.NumberToNumberDecoder(); this._availableOutgoingBitrateDecoder = new utils_2.NumberToNumberDecoder(); this._bytesDiscardedOnSendDecoder = new utils_1.BigIntToNumberDecoder(); this._bytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._bytesSentDecoder = new utils_1.BigIntToNumberDecoder(); this._consentRequestsSentDecoder = new utils_2.NumberToNumberDecoder(); this._currentRoundTripTimeDecoder = new utils_2.NumberToNumberDecoder(); this._lastPacketReceivedTimestampDecoder = new utils_2.NumberToNumberDecoder(); this._lastPacketSentTimestampDecoder = new utils_2.NumberToNumberDecoder(); this._localCandidateIdDecoder = new utils_2.StringToStringDecoder(); this._nominatedDecoder = new utils_1.BooleanToBooleanDecoder(); this._packetsDiscardedOnSendDecoder = new utils_2.NumberToNumberDecoder(); this._packetsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._packetsSentDecoder = new utils_2.NumberToNumberDecoder(); this._remoteCandidateIdDecoder = new utils_2.StringToStringDecoder(); this._requestsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._requestsSentDecoder = new utils_2.NumberToNumberDecoder(); this._responsesReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._responsesSentDecoder = new utils_2.NumberToNumberDecoder(); this._timestampDecoder = new utils_2.NumberToNumberDecoder(); this._totalRoundTripTimeDecoder = new utils_2.NumberToNumberDecoder(); this._transportIdDecoder = new utils_2.StringToStringDecoder(); this._stateDecoder = new IceCandidatePairStatsEnumDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._availableIncomingBitrateDecoder.reset(); this._availableOutgoingBitrateDecoder.reset(); this._bytesDiscardedOnSendDecoder.reset(); this._bytesReceivedDecoder.reset(); this._bytesSentDecoder.reset(); this._consentRequestsSentDecoder.reset(); this._currentRoundTripTimeDecoder.reset(); this._lastPacketReceivedTimestampDecoder.reset(); this._lastPacketSentTimestampDecoder.reset(); this._localCandidateIdDecoder.reset(); this._nominatedDecoder.reset(); this._packetsDiscardedOnSendDecoder.reset(); this._packetsReceivedDecoder.reset(); this._packetsSentDecoder.reset(); this._remoteCandidateIdDecoder.reset(); this._requestsReceivedDecoder.reset(); this._requestsSentDecoder.reset(); this._responsesReceivedDecoder.reset(); this._responsesSentDecoder.reset(); this._timestampDecoder.reset(); this._totalRoundTripTimeDecoder.reset(); this._transportIdDecoder.reset(); this._attachmentsDecoder.reset(); this._stateDecoder.reset(); } decode(input) { this._visited = true; const timestamp = this._timestampDecoder.decode(input.timestamp); if (!timestamp) { Logger_1.logger.warn("Invalid ICE candidate pair sample: missing timestamp or id"); return undefined; } this._actualValue = { id: this.id, availableIncomingBitrate: this._availableIncomingBitrateDecoder.decode(input.availableIncomingBitrate), availableOutgoingBitrate: this._availableOutgoingBitrateDecoder.decode(input.availableOutgoingBitrate), bytesDiscardedOnSend: this._bytesDiscardedOnSendDecoder.decode(input.bytesDiscardedOnSend), bytesReceived: this._bytesReceivedDecoder.decode(input.bytesReceived), bytesSent: this._bytesSentDecoder.decode(input.bytesSent), consentRequestsSent: this._consentRequestsSentDecoder.decode(input.consentRequestsSent), currentRoundTripTime: this._currentRoundTripTimeDecoder.decode(input.currentRoundTripTime), lastPacketReceivedTimestamp: this._lastPacketReceivedTimestampDecoder.decode(input.lastPacketReceivedTimestamp), lastPacketSentTimestamp: this._lastPacketSentTimestampDecoder.decode(input.lastPacketSentTimestamp), localCandidateId: this._localCandidateIdDecoder.decode(input.localCandidateId), nominated: this._nominatedDecoder.decode(input.nominated), packetsDiscardedOnSend: this._packetsDiscardedOnSendDecoder.decode(input.packetsDiscardedOnSend), packetsReceived: this._packetsReceivedDecoder.decode(input.packetsReceived), packetsSent: this._packetsSentDecoder.decode(input.packetsSent), remoteCandidateId: this._remoteCandidateIdDecoder.decode(input.remoteCandidateId), requestsReceived: this._requestsReceivedDecoder.decode(input.requestsReceived), requestsSent: this._requestsSentDecoder.decode(input.requestsSent), responsesReceived: this._responsesReceivedDecoder.decode(input.responsesReceived), responsesSent: this._responsesSentDecoder.decode(input.responsesSent), timestamp, totalRoundTripTime: this._totalRoundTripTimeDecoder.decode(input.totalRoundTripTime), transportId: this._transportIdDecoder.decode(input.transportId), attachments: this._attachmentsDecoder.decode(input.attachments), state: this._stateDecoder.decode(input.state), }; return this._actualValue; } get actualValue() { return this._actualValue; } set actualValue(sample) { if (!sample) return; this._visited = true; this._actualValue = sample; this._availableIncomingBitrateDecoder.actualValue = sample.availableIncomingBitrate; this._availableOutgoingBitrateDecoder.actualValue = sample.availableOutgoingBitrate; this._bytesDiscardedOnSendDecoder.actualValue = sample.bytesDiscardedOnSend; this._bytesReceivedDecoder.actualValue = sample.bytesReceived; this._bytesSentDecoder.actualValue = sample.bytesSent; this._consentRequestsSentDecoder.actualValue = sample.consentRequestsSent; this._currentRoundTripTimeDecoder.actualValue = sample.currentRoundTripTime; this._lastPacketReceivedTimestampDecoder.actualValue = sample.lastPacketReceivedTimestamp; this._lastPacketSentTimestampDecoder.actualValue = sample.lastPacketSentTimestamp; this._localCandidateIdDecoder.actualValue = sample.localCandidateId; this._nominatedDecoder.actualValue = sample.nominated; this._packetsDiscardedOnSendDecoder.actualValue = sample.packetsDiscardedOnSend; this._packetsReceivedDecoder.actualValue = sample.packetsReceived; this._packetsSentDecoder.actualValue = sample.packetsSent; this._remoteCandidateIdDecoder.actualValue = sample.remoteCandidateId; this._requestsReceivedDecoder.actualValue = sample.requestsReceived; this._requestsSentDecoder.actualValue = sample.requestsSent; this._responsesReceivedDecoder.actualValue = sample.responsesReceived; this._responsesSentDecoder.actualValue = sample.responsesSent; this._timestampDecoder.actualValue = sample.timestamp; this._totalRoundTripTimeDecoder.actualValue = sample.totalRoundTripTime; this._transportIdDecoder.actualValue = sample.transportId; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.IceCandidatePairDecoder = IceCandidatePairDecoder; class IceCandidatePairStatsEnumDecoder { reset() { this.actualValue = undefined; } decode(state) { if (state === undefined) return this.actualValue; switch (state) { case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.NEW: this.actualValue = 'new'; break; case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.INPROGRESS: this.actualValue = 'in-progress'; break; case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.WAITING: this.actualValue = 'waiting'; break; case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.FAILED: this.actualValue = 'failed'; break; case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.SUCCEEDED: this.actualValue = 'succeeded'; break; case InputSamples_1.ClientSample_PeerConnectionSample_IceCandidatePairStats_IceCandidatePairStatsEnum.CANCELLED: this.actualValue = 'cancelled'; break; default: Logger_1.logger.warn(`Unknown IceCandidatePairStats state: ${state}`); return undefined; } return this.actualValue; } } exports.IceCandidatePairStatsEnumDecoder = IceCandidatePairStatsEnumDecoder;