Created
September 12, 2017 13:06
-
-
Save ggoldens/e2e3e26cd1b474bd5eb220b3c1f4b540 to your computer and use it in GitHub Desktop.
Sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MOSQuality = { | |
Excellent: 5, | |
Good: 4, | |
Fair: 3, | |
Poor: 2, | |
Bad: 1, | |
}; | |
const analyzeStats = (results, subscriber) => { | |
if (subscriber && subscriber.stream && subscriber.stream.hasVideo) { | |
const videoBw = results.video.bitsPerSecond / 1000; | |
const videoPLRatio = results.video.packetLossRatioPerSecond; | |
const frameRate = (subscriber.stream.frameRate && subscriber.stream.frameRate.toString()) || '30'; | |
const { width, height } = subscriber.stream.videoDimensions; | |
const resolution = `${width}x${height}`; | |
if (resolution === '1280x720') { | |
const aVideoLimits = { | |
'1280x720-30': [250, 350, 600, 1000], | |
'1280x720-15': [150, 250, 350, 800], | |
'1280x720-7': [120, 150, 250, 400], | |
}; | |
if (videoBw > aVideoLimits[3] && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > aVideoLimits[2] && videoBw <= aVideoLimits[3] && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > aVideoLimits[2] && videoBw <= aVideoLimits[3] && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > aVideoLimits[1] && videoBw <= aVideoLimits[2] && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > aVideoLimits[0] && videoPLRatio > 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw > aVideoLimits[0] && videoBw <= aVideoLimits[1] && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < aVideoLimits[0] || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
} else if (resolution === '640x480') { | |
switch (frameRate) { | |
case '30': | |
if (videoBw > 600 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 250 && videoBw <= 600 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 250 && videoBw <= 600 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 150 && videoBw <= 250 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 150) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 120 && videoBw <= 150 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 120 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
case '15': | |
if (videoBw > 400 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 200 && videoBw <= 400 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 150 && videoBw <= 200 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 120 && videoBw <= 150 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 120) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 75 && videoBw <= 120 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 75 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
case '7': | |
if (videoBw > 200 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 150 && videoBw <= 200 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 120 && videoBw <= 150 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 75 && videoBw <= 120 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 50) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 50 && videoBw <= 75 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 50 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
default: | |
return MOSQuality.Bad; | |
} | |
} else if (resolution === '320x240') { | |
switch (frameRate) { | |
case '30': | |
if (videoBw > 300 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 200 && videoBw <= 300 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 120 && videoBw <= 200 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 120 && videoBw <= 200 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 120) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 100 && videoBw <= 120 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 100 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
case '15': | |
if (videoBw > 200 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 150 && videoBw <= 200 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 120 && videoBw <= 150 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 120 && videoBw <= 150 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 120) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 100 && videoBw <= 120 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 100 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
case '7': | |
if (videoBw > 150 && videoPLRatio < 0.1) { | |
return MOSQuality.Excellent; | |
} else if (videoBw > 100 && videoBw <= 150 && videoPLRatio < 0.02) { | |
return MOSQuality.Good; | |
} else if (videoBw > 100 && videoBw <= 150 && videoPLRatio > 0.02 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoBw > 75 && videoBw <= 100 && videoPLRatio < 0.1) { | |
return MOSQuality.Fair; | |
} else if (videoPLRatio > 0.1 && videoBw > 75) { | |
return MOSQuality.Poor; | |
} else if (videoBw > 50 && videoBw <= 75 && videoPLRatio < 0.1) { | |
return MOSQuality.Poor; | |
} else if (videoBw < 50 || videoPLRatio > 0.1) { | |
return MOSQuality.Bad; | |
} | |
return MOSQuality.Bad; | |
default: | |
return MOSQuality.Bad; | |
} | |
} | |
return MOSQuality.Bad; | |
} | |
const audioBw = results.audio.bitsPerSecond / 1000; | |
const audioPLRadio = results.audio.packetLossRatioPerSecond; | |
if (audioBw > 30 && audioPLRadio < 0.5) { | |
return MOSQuality.Excellent; | |
} else if (audioBw > 25 && audioPLRadio < 5) { | |
return MOSQuality.Good; | |
} | |
return MOSQuality.Bad; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment