Skip to content

Commit ff8503b

Browse files
author
arthur
committed
feat: 'dev/bound-rtp.js'
1 parent cf37736 commit ff8503b

File tree

7 files changed

+1659
-21
lines changed

7 files changed

+1659
-21
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = function(grunt) {
5151
'dev/remote-candidate.js',
5252
'dev/dataSentReceived.js',
5353
'dev/ssrc.js',
54-
'dev/tail.js'
54+
'dev/bound-rtp.js',
55+
'dev/tail.js',
5556
],
5657
dest: 'getStats.js',
5758
},

dev/bound-rtp.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
* @param {*} result
99
*/
1010
getStatsParser.boundRtp = function(result) {
11-
12-
if (result.type == 'inbound-rtp') {
13-
creatVideoCounter('nackCount', 'recv', '+', 1, 'googNacksReceived');
14-
creatVideoCounter('pliCount', 'recv', '+', 1, 'googPlisReceived');
15-
creatVideoCounter('firCount', 'recv', '+', 1, 'googFirsReceived');
16-
}
1711

18-
if (result.type == 'outbound-rtp') {
19-
creatVideoCounter('nackCount', 'send', '+', 1, 'googNacksSent');
20-
creatVideoCounter('pliCount', 'send', '+', 1, 'googPlisSent');
21-
creatVideoCounter('firCount', 'send', '+', 1, 'googFirsSent');
22-
}
23-
}
12+
if (result.type == 'inbound-rtp') {
13+
creatVideoCounter('nackCount', 'recv', '+', 1, 'googNacksReceived');
14+
creatVideoCounter('pliCount', 'recv', '+', 1, 'googPlisReceived');
15+
creatVideoCounter('firCount', 'recv', '+', 1, 'googFirsReceived');
16+
}
17+
18+
if (result.type == 'outbound-rtp') {
19+
creatVideoCounter('nackCount', 'send', '+', 1, 'googNacksSent');
20+
creatVideoCounter('pliCount', 'send', '+', 1, 'googPlisSent');
21+
creatVideoCounter('firCount', 'send', '+', 1, 'googFirsSent');
22+
}
23+
}

dev/globals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function creatVideoCounter(paramName, type, op, scale, userFiled) {
132132
// 当参数合并后,根据 googNacksSent 来判断recv/send Kb Mb Gb
133133
if (!!result[paramName] && result[paramName] !== '0') {
134134
var Count = 0;
135-
if (!getStatsResult.internal.video[type]['prev' + paramName] || getStatsResult.internal.video[type]['prev' + paramName]> result[paramName]) {
135+
if (!getStatsResult.internal.video[type]['prev' + paramName] || getStatsResult.internal.video[type]['prev' + paramName] > result[paramName]) {
136136
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
137137
}
138138
if ((op || '+') === '+') {

getStats.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
// Last time updated: 2018-11-26 6:19:49 AM UTC
3+
// Last time updated: 2018-12-10 7:33:37 AM UTC
44

55
// _______________
66
// getStats v1.0.10
@@ -45,13 +45,19 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
4545
tracks: [],
4646
codecs: [],
4747
availableBandwidth: 0,
48-
streams: 0
48+
streams: 0,
49+
googNacksSent: 0,
50+
googPlisSent: 0,
51+
googFirsReceived: 0
4952
},
5053
recv: {
5154
tracks: [],
5255
codecs: [],
5356
availableBandwidth: 0,
54-
streams: 0
57+
streams: 0,
58+
googNacksReceived: 0,
59+
googPlisReceived: 0,
60+
googFirsReceived: 0
5561
},
5662
bytesSent: 0,
5763
bytesReceived: 0
@@ -130,6 +136,32 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
130136
}
131137
};
132138

139+
/**
140+
* Video Counter helper function
141+
* @param {*} paramName
142+
* @param {*} op - default `+`
143+
* @param {*} scale - default 1
144+
* @param {*} userFiled - default paramName
145+
* @returns {NULL}
146+
*/
147+
function creatVideoCounter(paramName, type, op, scale, userFiled) {
148+
// 当参数合并后,根据 googNacksSent 来判断recv/send Kb Mb Gb
149+
if (!!result[paramName] && result[paramName] !== '0') {
150+
var Count = 0;
151+
if (!getStatsResult.internal.video[type]['prev' + paramName] || getStatsResult.internal.video[type]['prev' + paramName] > result[paramName]) {
152+
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
153+
}
154+
if ((op || '+') === '+') {
155+
Count = result[paramName] + getStatsResult.internal.video[type]['prev' + paramName];
156+
} else {
157+
Count = result[paramName] - getStatsResult.internal.video[type]['prev' + paramName];
158+
}
159+
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
160+
return getStatsResult.video[type][userFiled || paramName] = Count * (scale || 1);
161+
}
162+
return;
163+
}
164+
133165
function preHandler(result) {
134166
// 根据codeId\trackId映射 - 处理关联关系
135167
var idMap = result.reduce(function(map, item) {
@@ -649,10 +681,30 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
649681
if (SSRC[result.mediaType][sendrecvType].indexOf(result.ssrc) === -1) {
650682
SSRC[result.mediaType][sendrecvType].push(result.ssrc)
651683
}
652-
684+
creatVideoCounter('googNacksSent', 'send');
685+
creatVideoCounter('googPlisSent', 'send');
686+
creatVideoCounter('googFirsSent', 'send');
687+
creatVideoCounter('googNacksReceived', 'recv');
688+
creatVideoCounter('googPlisReceived', 'recv');
689+
creatVideoCounter('googFirsReceived', 'recv');
653690
getStatsResult[result.mediaType][sendrecvType].streams = SSRC[result.mediaType][sendrecvType].length;
654691
};
655692

693+
getStatsParser.boundRtp = function(result) {
694+
695+
if (result.type == 'inbound-rtp') {
696+
creatVideoCounter('nackCount', 'recv', '+', 1, 'googNacksReceived');
697+
creatVideoCounter('pliCount', 'recv', '+', 1, 'googPlisReceived');
698+
creatVideoCounter('firCount', 'recv', '+', 1, 'googFirsReceived');
699+
}
700+
701+
if (result.type == 'outbound-rtp') {
702+
creatVideoCounter('nackCount', 'send', '+', 1, 'googNacksSent');
703+
creatVideoCounter('pliCount', 'send', '+', 1, 'googPlisSent');
704+
creatVideoCounter('firCount', 'send', '+', 1, 'googFirsSent');
705+
}
706+
}
707+
656708
getStatsLooper();
657709

658710
};

0 commit comments

Comments
 (0)