UNPKG

@observertc/observer-js

Version:

Server Side NodeJS Library for processing ObserveRTC Samples

60 lines (59 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObservedTurnServer = void 0; class ObservedTurnServer { url; observedTURN; totalBytesSent = 0; totalBytesReceived = 0; totalPacketsSent = 0; totalPacketsReceived = 0; packetsSentPerSecond = 0; packetsReceivedPerSecond = 0; outboundBitrate = 0; inboundBitrate = 0; deltaBytesSent = 0; deltaBytesReceived = 0; deltaPacketsSent = 0; deltaPacketsReceived = 0; observedPeerConnections = new Map(); updated = Date.now(); constructor(url, observedTURN) { this.url = url; this.observedTURN = observedTURN; } updateTurnUsage(...selectedcandidatepairs) { for (const selectedcandidatepair of selectedcandidatepairs) { this.deltaBytesReceived += selectedcandidatepair.deltaBytesReceived; this.deltaBytesSent += selectedcandidatepair.deltaBytesSent; this.deltaPacketsReceived += selectedcandidatepair.deltaPacketsReceived; this.deltaPacketsSent += selectedcandidatepair.deltaPacketsSent; } } update() { const now = Date.now(); const deltaInS = (now - this.updated) / 1000; this.packetsSentPerSecond = this.deltaPacketsSent / deltaInS; this.packetsReceivedPerSecond = this.deltaPacketsReceived / deltaInS; this.outboundBitrate = (this.deltaBytesReceived * 8) / deltaInS; this.inboundBitrate = (this.deltaBytesSent * 8) / deltaInS; this.totalBytesSent += this.deltaBytesSent; this.totalBytesReceived += this.deltaBytesReceived; this.totalPacketsSent += this.deltaPacketsSent; this.totalPacketsReceived += this.deltaPacketsReceived; this.observedTURN.totalBytesSent += this.deltaBytesSent; this.observedTURN.totalBytesReceived += this.deltaBytesReceived; this.observedTURN.totalPacketsSent += this.deltaPacketsSent; this.observedTURN.totalPacketsReceived += this.deltaPacketsReceived; this.observedTURN.inboundBitrate += this.inboundBitrate; this.observedTURN.outboundBitrate += this.outboundBitrate; this.observedTURN.packetsReceivedPerSecond += this.packetsReceivedPerSecond; this.observedTURN.packetsSentPerSecond += this.packetsSentPerSecond; this.deltaBytesSent = 0; this.deltaBytesReceived = 0; this.deltaPacketsSent = 0; this.deltaPacketsReceived = 0; this.updated = now; } } exports.ObservedTurnServer = ObservedTurnServer;