jam-cloud/web/app/assets/javascripts/react-components/stores/SessionStatsStore.js.coffee

206 lines
6.5 KiB
CoffeeScript
Raw Permalink Normal View History

2015-12-09 17:32:24 +00:00
$ = jQuery
context = window
logger = context.JK.logger
rest = context.JK.Rest()
EVENTS = context.JK.EVENTS
MIX_MODES = context.JK.MIX_MODES
SessionActions = @SessionActions
2016-10-27 23:24:54 +00:00
MixerActions = @MixerActions
2015-12-09 17:32:24 +00:00
SessionStatThresholds = gon.session_stat_thresholds
NetworkThresholds = SessionStatThresholds.network
SystemThresholds = SessionStatThresholds.system
AudioThresholds = SessionStatThresholds.audio
2015-12-12 03:14:00 +00:00
AggregateThresholds = SessionStatThresholds.aggregate
2015-12-09 17:32:24 +00:00
@SessionStatsStore = Reflux.createStore(
2015-12-10 11:21:59 +00:00
{
listenables: @SessionStatsActions
2016-10-27 23:24:54 +00:00
rawStats: null,
parentStats: null
clientsWithAudio: null
2015-12-10 11:21:59 +00:00
2015-12-12 03:14:00 +00:00
init: ->
# Register with the app store to get @app
this.listenTo(context.AppStore, this.onAppInit)
onAppInit: (@app) ->
2016-10-27 23:24:54 +00:00
onPushStats: (stats, parentStats) ->
2015-12-10 11:21:59 +00:00
@rawStats = stats
2016-10-27 23:24:54 +00:00
@parentStats = parentStats
2015-12-10 11:21:59 +00:00
@changed()
classify: (holder, field, threshold) ->
value = holder[field]
fieldLevel = field + '_level'
fieldThreshold = threshold[field]
2015-12-12 03:14:00 +00:00
2015-12-10 11:21:59 +00:00
if value? && fieldThreshold?
if fieldThreshold.inverse
2015-12-12 03:14:00 +00:00
if fieldThreshold.zero_is_good
holder[fieldLevel] = 'good'
else if value <= fieldThreshold.poor
2015-12-10 11:21:59 +00:00
holder[fieldLevel] = 'poor'
@participantClassification = 3
else if value <= fieldThreshold.warn
holder[fieldLevel] = 'warn'
@participantClassification = 2 if @participantClassification == 1
else
holder[fieldLevel] = 'good'
else if fieldThreshold.eql
if value == fieldThreshold.poor
holder[fieldLevel] = 'poor'
@participantClassification = 3
else if value == fieldThreshold.warn
holder[fieldLevel] = 'warn'
@participantClassification = 2 if @participantClassification == 1
else
holder[fieldLevel] = 'good'
2015-12-09 17:32:24 +00:00
else
2015-12-10 11:21:59 +00:00
if value >= fieldThreshold.poor
holder[fieldLevel] = 'poor'
@participantClassification = 3
else if value >= fieldThreshold.warn
holder[fieldLevel] = 'warn'
@participantClassification = 2 if @participantClassification == 1
else
holder[fieldLevel] = 'good'
2016-10-27 23:24:54 +00:00
classifyStats: (statBag) ->
container = {}
2015-12-12 03:14:00 +00:00
self = null
2016-10-27 23:24:54 +00:00
for participant in statBag
2015-12-12 03:14:00 +00:00
if participant.id == @app.clientId
self = participant
break
2016-10-27 23:24:54 +00:00
for participant in statBag
2015-12-10 11:21:59 +00:00
aggregate = {}
2015-12-10 11:21:59 +00:00
@participantClassification = 1 # 1=good, 2=warn, 3=poor
2015-12-12 03:14:00 +00:00
total_latency = 0
2015-12-10 11:21:59 +00:00
if participant.cpu?
system = {cpu: participant.cpu}
@classify(system, 'cpu', SystemThresholds)
participant.system = system
network = participant.network
if network?
2016-10-27 23:24:54 +00:00
if network.audio_bitrate_rx > 0 && network.audio_bitrate_tx > 0
@clientsWithAudio[participant.id] = true
2015-12-11 02:52:13 +00:00
@classify(network, 'audiojq_median', NetworkThresholds)
2015-12-12 03:14:00 +00:00
@classify(network, 'jitter_var', NetworkThresholds)
@classify(network, 'audio_bitrate_rx', NetworkThresholds)
@classify(network, 'audio_bitrate_tx', NetworkThresholds)
@classify(network, 'video_rtpbw_tx', NetworkThresholds)
@classify(network, 'video_rtpbw_rx', NetworkThresholds)
2015-12-10 11:21:59 +00:00
@classify(network, 'ping', NetworkThresholds)
@classify(network, 'pkt_loss', NetworkThresholds)
@classify(network, 'wifi', NetworkThresholds)
2015-12-12 03:14:00 +00:00
total_latency += network.ping / 2
total_latency += network.audiojq_median * 2.5
aggregate.one_way = network.ping / 2
aggregate.jq = network.audiojq_median * 2.5
2021-02-08 04:08:51 +00:00
# ARS TX/RX Determination
#console.log("NETWORK", network)
if network.ars_path_used == 0
network.rx_ars_vs_p2p = 'P2P'
if network.preferred_path == 'p2p'
2021-02-08 04:08:51 +00:00
network.rx_ars_vs_p2p_level = 'good'
else
2021-02-08 04:08:51 +00:00
network.rx_ars_vs_p2p_level = 'warn'
else
2021-02-08 04:08:51 +00:00
network.rx_ars_vs_p2p = 'ARS'
if network.preferred_path == 'p2p'
2021-02-08 04:08:51 +00:00
network.rx_ars_vs_p2p_level = 'warn'
else
2021-02-08 04:08:51 +00:00
network.rx_ars_vs_p2p_level = 'good'
if network.ars_con_active == 0
network.tx_ars_vs_p2p = 'P2P'
if network.preferred_path == 'p2p'
network.tx_ars_vs_p2p_level = 'good'
else
network.tx_ars_vs_p2p_level = 'warn'
else
network.tx_ars_vs_p2p = 'ARS'
if network.preferred_path == 'p2p'
network.tx_ars_vs_p2p_level = 'warn'
else
network.tx_ars_vs_p2p_level = 'good'
2015-12-12 03:14:00 +00:00
else
total_latency = null
2015-12-10 11:21:59 +00:00
audio = participant.audio
if audio?
if audio.cpu?
system = {cpu: audio.cpu}
@classify(system, 'cpu', SystemThresholds)
participant.system = system
if audio.in_latency? and audio.out_latency?
audio.latency = audio.in_latency + audio.out_latency
@classify(audio, 'framesize', AudioThresholds)
@classify(audio, 'latency', AudioThresholds)
@classify(audio, 'input_jitter', AudioThresholds)
@classify(audio, 'output_jitter', AudioThresholds)
2015-12-11 04:07:56 +00:00
@classify(audio, 'audio_in_type', AudioThresholds)
2015-12-10 11:21:59 +00:00
2015-12-12 03:14:00 +00:00
if total_latency != null
total_latency += audio.out_latency
total_latency += self.audio.in_latency
aggregate.their_out_latency = audio.out_latency
aggregate.your_in_latency = self.audio.in_latency
2015-12-12 03:14:00 +00:00
else
total_latency = null
if participant.id != @app.clientId
aggregate.latency = total_latency
2015-12-12 03:14:00 +00:00
@classify(aggregate, 'latency', AggregateThresholds)
participant.aggregate = aggregate
2015-12-10 11:21:59 +00:00
switch @participantClassification
when 1 then participant.classification = 'good'
when 2 then participant.classification = 'warn'
when 3 then participant.classification = 'poor'
else
participant.classification = 'unknown'
2016-10-27 23:24:54 +00:00
container[participant.id] = participant
2016-11-04 16:18:58 +00:00
return container
2016-10-27 23:24:54 +00:00
changed: () ->
@clientsWithAudio = {}
@stats = {}
@stats = @classifyStats(@rawStats)
if @parentStats
@stats.parent = @classifyStats(@parentStats)
else
@stats.parent = null
MixerActions.clientsWithAudio(@clientsWithAudio)
2015-12-10 11:21:59 +00:00
2016-10-27 23:24:54 +00:00
# see if we can reset noAudio
2015-12-10 11:21:59 +00:00
@trigger(@stats)
}
2015-12-09 17:32:24 +00:00
)