@livedigital/client 2.7.1 → 2.7.2-improve-network-issue-detector.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@livedigital/client",
3
3
  "author": "vlprojects",
4
4
  "license": "MIT",
5
- "version": "2.7.1",
5
+ "version": "2.7.2-improve-network-issue-detector.1",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -30,21 +30,30 @@ class NetworkIssueDetector implements IssueDetector {
30
30
 
31
31
  const rtpNetworkStats = inboundRTPStreamsStats.reduce((stats, currentStreamStats) => {
32
32
  const previousStreamStats = previousInboundStreamStats.find((stream) => stream.ssrc === currentStreamStats.ssrc);
33
+
33
34
  const lastJitterBufferDelay = previousStreamStats?.jitterBufferDelay || 0;
34
35
  const lastJitterBufferEmittedCount = previousStreamStats?.jitterBufferEmittedCount || 0;
35
36
  const delay = currentStreamStats.jitterBufferDelay - lastJitterBufferDelay;
36
37
  const emitted = currentStreamStats.jitterBufferEmittedCount - lastJitterBufferEmittedCount;
37
- const latency = delay && emitted ? (1e3 * delay) / emitted : 0;
38
+ const jitterBufferDelayMs = delay && emitted ? (1e3 * delay) / emitted : 0;
38
39
 
39
40
  return {
40
- maxLatency: latency > stats.maxLatency ? latency : stats.maxLatency,
41
+ sumJitter: stats.sumJitter + currentStreamStats.jitter,
42
+ sumJitterBufferDelayMs: stats.sumJitterBufferDelayMs + jitterBufferDelayMs,
41
43
  packetsLost: stats.packetsLost + currentStreamStats.packetsLost,
42
44
  lastPacketsLost: stats.lastPacketsLost + (previousStreamStats?.packetsLost || 0),
43
45
  };
44
- }, { maxLatency: 0, packetsLost: 0, lastPacketsLost: 0 });
46
+ }, {
47
+ sumJitter: 0,
48
+ sumJitterBufferDelayMs: 0,
49
+ packetsLost: 0,
50
+ lastPacketsLost: 0,
51
+ });
45
52
 
46
53
  const rtt = (1e3 * data.connection.currentRoundTripTime) || 0;
47
- const jitter = Math.round(rtt / 2 + rtpNetworkStats.maxLatency);
54
+ const { sumJitter, sumJitterBufferDelayMs } = rtpNetworkStats;
55
+ const avgJitter = sumJitter / inboundRTPStreamsStats.length;
56
+ const avgJitterBufferDelay = sumJitterBufferDelayMs / inboundRTPStreamsStats.length;
48
57
 
49
58
  const deltaPacketReceived = packetsReceived - lastPacketsReceived;
50
59
  const deltaPacketLost = rtpNetworkStats.packetsLost - rtpNetworkStats.lastPacketsLost;
@@ -54,19 +63,24 @@ class NetworkIssueDetector implements IssueDetector {
54
63
  : 0;
55
64
 
56
65
  const isHighPacketsLoss = packetsLoss > 5;
57
- const isHighJitter = jitter >= 200;
58
- const isHighRTT = rtt >= 200;
66
+ const isHighJitter = avgJitter >= 200;
67
+ const isHighRTT = rtt >= 250;
68
+ const isHighJitterBufferDelay = avgJitterBufferDelay > 500;
59
69
 
60
70
  const isNetworkIssue = (!isHighPacketsLoss && isHighJitter) || isHighJitter || isHighPacketsLoss;
61
71
  const isServerIssue = isHighRTT && !isHighJitter && !isHighPacketsLoss;
62
72
  const isNetworkMediaLatencyIssue = isHighPacketsLoss && isHighJitter;
73
+ const isNetworkMediaSyncIssue = isHighJitter && isHighJitterBufferDelay;
74
+
75
+ const debug = `packetLoss: ${packetsLoss}%, jitter: ${avgJitter}, rtt: ${rtt},`
76
+ + ` jitterBuffer: ${avgJitterBufferDelay}ms`;
63
77
 
64
78
  if (isNetworkIssue) {
65
79
  issues.push({
66
80
  type: IssueType.Network,
67
81
  reason: IssueReason.NetworkQuality,
68
82
  iceCandidate: data.connection.local.id,
69
- debug: `packetLoss: ${packetsLoss}%, jitter: ${jitter}`,
83
+ debug,
70
84
  });
71
85
  }
72
86
 
@@ -75,7 +89,7 @@ class NetworkIssueDetector implements IssueDetector {
75
89
  type: IssueType.Server,
76
90
  reason: IssueReason.ServerIssue,
77
91
  iceCandidate: data.connection.remote.id,
78
- debug: `packetLoss: ${packetsLoss}%,jitter: ${jitter}, rtt: ${rtt},`,
92
+ debug,
79
93
  });
80
94
  }
81
95
 
@@ -84,7 +98,16 @@ class NetworkIssueDetector implements IssueDetector {
84
98
  type: IssueType.Network,
85
99
  reason: IssueReason.NetworkMediaLatency,
86
100
  iceCandidate: data.connection.local.id,
87
- debug: `packetLoss: ${packetsLoss}%, jitter: ${jitter}`,
101
+ debug,
102
+ });
103
+ }
104
+
105
+ if (isNetworkMediaSyncIssue) {
106
+ issues.push({
107
+ type: IssueType.Network,
108
+ reason: IssueReason.NetworkMediaSyncFailure,
109
+ iceCandidate: data.connection.local.id,
110
+ debug,
88
111
  });
89
112
  }
90
113