UNPKG

@observertc/observer-js

Version:

Server Side NodeJS Library for processing ObserveRTC Samples

128 lines (127 loc) 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObservedIceCandidatePair = void 0; class ObservedIceCandidatePair { timestamp; id; _peerConnection; _visited = false; appData; transportId; localCandidateId; remoteCandidateId; state; nominated; packetsSent; packetsReceived; bytesSent; bytesReceived; lastPacketSentTimestamp; lastPacketReceivedTimestamp; totalRoundTripTime; currentRoundTripTime; availableOutgoingBitrate; availableIncomingBitrate; requestsReceived; requestsSent; responsesReceived; responsesSent; consentRequestsSent; packetsDiscardedOnSend; bytesDiscardedOnSend; attachments; deltaBytesSent = 0; deltaBytesReceived = 0; deltaPacketsSent = 0; deltaPacketsReceived = 0; constructor(timestamp, id, _peerConnection) { this.timestamp = timestamp; this.id = id; this._peerConnection = _peerConnection; } get visited() { const visited = this._visited; this._visited = false; return visited; } getPeerConnection() { return this._peerConnection; } getIceTransport() { return this._peerConnection.observedIceTransports.get(this.transportId ?? ''); } getLocalCandidate() { return this._peerConnection.observedIceCandidates.get(this.localCandidateId ?? ''); } getRemoteCandidate() { return this._peerConnection.observedIceCandidates.get(this.remoteCandidateId ?? ''); } update(stats) { this._visited = true; if (this.packetsSent && stats.packetsSent && stats.packetsSent >= this.packetsSent) { this.deltaPacketsSent = stats.packetsSent - this.packetsSent; } else { this.deltaPacketsSent = 0; } if (this.packetsReceived && stats.packetsReceived && stats.packetsReceived >= this.packetsReceived) { this.deltaPacketsReceived = stats.packetsReceived - this.packetsReceived; } else { this.deltaPacketsReceived = 0; } if (this.bytesSent && stats.bytesSent && stats.bytesSent >= this.bytesSent) { this.deltaBytesSent = stats.bytesSent - this.bytesSent; } else { this.deltaBytesSent = 0; } if (this.bytesReceived && stats.bytesReceived && stats.bytesReceived >= this.bytesReceived) { this.deltaBytesReceived = stats.bytesReceived - this.bytesReceived; } else { this.deltaBytesReceived = 0; } this.timestamp = stats.timestamp; this.transportId = stats.transportId; this.localCandidateId = stats.localCandidateId; this.remoteCandidateId = stats.remoteCandidateId; this.state = this._convertState(stats.state); this.nominated = stats.nominated; this.packetsSent = stats.packetsSent; this.packetsReceived = stats.packetsReceived; this.bytesSent = stats.bytesSent; this.bytesReceived = stats.bytesReceived; this.lastPacketSentTimestamp = stats.lastPacketSentTimestamp; this.lastPacketReceivedTimestamp = stats.lastPacketReceivedTimestamp; this.totalRoundTripTime = stats.totalRoundTripTime; this.currentRoundTripTime = stats.currentRoundTripTime; this.availableOutgoingBitrate = stats.availableOutgoingBitrate; this.availableIncomingBitrate = stats.availableIncomingBitrate; this.requestsReceived = stats.requestsReceived; this.requestsSent = stats.requestsSent; this.responsesReceived = stats.responsesReceived; this.responsesSent = stats.responsesSent; this.consentRequestsSent = stats.consentRequestsSent; this.packetsDiscardedOnSend = stats.packetsDiscardedOnSend; this.bytesDiscardedOnSend = stats.bytesDiscardedOnSend; this.attachments = stats.attachments; } _convertState(state) { switch (state) { case 'new': case 'in-progress': case 'waiting': case 'failed': case 'succeeded': return state; case 'cancelled': return 'failed'; case 'inprogress': return 'in-progress'; default: return undefined; } } } exports.ObservedIceCandidatePair = ObservedIceCandidatePair;