UNPKG

@observertc/samples-encoder

Version:

ObserveRTC Library for Encoding Samples

57 lines (56 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataChannelEncoder = void 0; const utils_1 = require("./utils"); const utils_2 = require("./utils"); // Assuming these are utility encoders for the various types const OutputSamples_1 = require("./OutputSamples"); // Assuming this is the output sample type class DataChannelEncoder { constructor(_attachmentsEncoder) { this._attachmentsEncoder = _attachmentsEncoder; this._visited = false; // Initialize encoders for each field based on their type this._timestampEncoder = new utils_2.NumberToNumberEncoder(); this._labelEncoder = new utils_2.StringToStringEncoder(); this._protocolEncoder = new utils_2.StringToStringEncoder(); this._dataChannelIdentifierEncoder = new utils_2.NumberToNumberEncoder(); this._stateEncoder = new utils_2.StringToStringEncoder(); this._messagesSentEncoder = new utils_2.NumberToNumberEncoder(); this._bytesSentEncoder = new utils_1.NumberToBigIntEncoder(); this._messagesReceivedEncoder = new utils_2.NumberToNumberEncoder(); this._bytesReceivedEncoder = new utils_1.NumberToBigIntEncoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { // Reset all encoders this._timestampEncoder.reset(); this._labelEncoder.reset(); this._protocolEncoder.reset(); this._dataChannelIdentifierEncoder.reset(); this._stateEncoder.reset(); this._messagesSentEncoder.reset(); this._bytesSentEncoder.reset(); this._messagesReceivedEncoder.reset(); this._bytesReceivedEncoder.reset(); } encode(sample) { this._visited = true; return new OutputSamples_1.ClientSample_PeerConnectionSample_DataChannelStats({ timestamp: this._timestampEncoder.encode(sample.timestamp), id: sample.id, label: this._labelEncoder.encode(sample.label), protocol: this._protocolEncoder.encode(sample.protocol), dataChannelIdentifier: this._dataChannelIdentifierEncoder.encode(sample.dataChannelIdentifier), state: this._stateEncoder.encode(sample.state), messagesSent: this._messagesSentEncoder.encode(sample.messagesSent), bytesSent: this._bytesSentEncoder.encode(sample.bytesSent), messagesReceived: this._messagesReceivedEncoder.encode(sample.messagesReceived), bytesReceived: this._bytesReceivedEncoder.encode(sample.bytesReceived), attachments: this._attachmentsEncoder.encode(sample.attachments), }); } } exports.DataChannelEncoder = DataChannelEncoder;