|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -// Last time updated: 2018-11-26 6:19:49 AM UTC |
| 3 | +// Last time updated: 2018-12-10 9:49:44 AM UTC |
4 | 4 |
|
5 | 5 | // _______________
|
6 | 6 | // getStats v1.0.10
|
@@ -45,13 +45,19 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
|
45 | 45 | tracks: [],
|
46 | 46 | codecs: [],
|
47 | 47 | availableBandwidth: 0,
|
48 |
| - streams: 0 |
| 48 | + streams: 0, |
| 49 | + googNacksSent: 0, |
| 50 | + googPlisSent: 0, |
| 51 | + googFirsReceived: 0 |
49 | 52 | },
|
50 | 53 | recv: {
|
51 | 54 | tracks: [],
|
52 | 55 | codecs: [],
|
53 | 56 | availableBandwidth: 0,
|
54 |
| - streams: 0 |
| 57 | + streams: 0, |
| 58 | + googNacksReceived: 0, |
| 59 | + googPlisReceived: 0, |
| 60 | + googFirsReceived: 0 |
55 | 61 | },
|
56 | 62 | bytesSent: 0,
|
57 | 63 | bytesReceived: 0
|
@@ -130,6 +136,32 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
|
130 | 136 | }
|
131 | 137 | };
|
132 | 138 |
|
| 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(result, 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 | + |
133 | 165 | function preHandler(result) {
|
134 | 166 | // 根据codeId\trackId映射 - 处理关联关系
|
135 | 167 | var idMap = result.reduce(function(map, item) {
|
@@ -649,10 +681,30 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
|
649 | 681 | if (SSRC[result.mediaType][sendrecvType].indexOf(result.ssrc) === -1) {
|
650 | 682 | SSRC[result.mediaType][sendrecvType].push(result.ssrc)
|
651 | 683 | }
|
652 |
| - |
| 684 | + creatVideoCounter(result, 'googNacksSent', 'send'); |
| 685 | + creatVideoCounter(result, 'googPlisSent', 'send'); |
| 686 | + creatVideoCounter(result, 'googFirsSent', 'send'); |
| 687 | + creatVideoCounter(result, 'googNacksReceived', 'recv'); |
| 688 | + creatVideoCounter(result, 'googPlisReceived', 'recv'); |
| 689 | + creatVideoCounter(result, 'googFirsReceived', 'recv'); |
653 | 690 | getStatsResult[result.mediaType][sendrecvType].streams = SSRC[result.mediaType][sendrecvType].length;
|
654 | 691 | };
|
655 | 692 |
|
| 693 | + getStatsParser.boundRtp = function(result) { |
| 694 | + |
| 695 | + if (result.type == 'inbound-rtp') { |
| 696 | + creatVideoCounter(result, 'nackCount', 'recv', '+', 1, 'googNacksReceived'); |
| 697 | + creatVideoCounter(result, 'pliCount', 'recv', '+', 1, 'googPlisReceived'); |
| 698 | + creatVideoCounter(result, 'firCount', 'recv', '+', 1, 'googFirsReceived'); |
| 699 | + } |
| 700 | + |
| 701 | + if (result.type == 'outbound-rtp') { |
| 702 | + creatVideoCounter(result, 'nackCount', 'send', '+', 1, 'googNacksSent'); |
| 703 | + creatVideoCounter(result, 'pliCount', 'send', '+', 1, 'googPlisSent'); |
| 704 | + creatVideoCounter(result, 'firCount', 'send', '+', 1, 'googFirsSent'); |
| 705 | + } |
| 706 | + } |
| 707 | + |
656 | 708 | getStatsLooper();
|
657 | 709 |
|
658 | 710 | };
|
0 commit comments