@livedigital/client 2.7.1 → 2.7.2

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",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -1,5 +1,4 @@
1
1
  import { WebRTCStats, WebRTCStatsEventData } from '@peermetrics/webrtc-stats';
2
- import WIDRTCPeerConnection from './WIDRTCPeerConnection';
3
2
  import { WebRTCIssueEmitter } from './WebRTCIssueEmitter';
4
3
  import {
5
4
  WebRTCIssueDetectorConstructorParams,
@@ -38,9 +37,7 @@ class WebRTCIssueDetector {
38
37
  });
39
38
 
40
39
  (window as unknown as WIDWindow).wid = this;
41
- if (window.RTCPeerConnection) {
42
- window.RTCPeerConnection = WIDRTCPeerConnection;
43
- }
40
+ this.wrapRTCPeerConnection();
44
41
 
45
42
  this.detectors = [
46
43
  new QualityLimitationsIssueDetector(),
@@ -81,10 +78,6 @@ class WebRTCIssueDetector {
81
78
  return;
82
79
  }
83
80
 
84
- if (!(pc instanceof RTCPeerConnection)) {
85
- return;
86
- }
87
-
88
81
  this.webrtcStats.addConnection({
89
82
  pc,
90
83
  peerId: this.webrtcStatsPeerId,
@@ -105,6 +98,24 @@ class WebRTCIssueDetector {
105
98
  this.emitIssues(issues);
106
99
  }
107
100
  }
101
+
102
+ private wrapRTCPeerConnection(): void {
103
+ if (!window.RTCPeerConnection) {
104
+ return;
105
+ }
106
+
107
+ const OriginalRTCPeerConnection = window.RTCPeerConnection;
108
+ const onConnectionCreated = (pc: RTCPeerConnection) => this.handleNewPeerConnection(pc);
109
+
110
+ function WIDRTCPeerConnection(rtcConfig?: RTCConfiguration) {
111
+ const connection = new OriginalRTCPeerConnection(rtcConfig);
112
+ onConnectionCreated(connection);
113
+ return connection;
114
+ }
115
+
116
+ WIDRTCPeerConnection.prototype = OriginalRTCPeerConnection.prototype;
117
+ (window.RTCPeerConnection as unknown) = WIDRTCPeerConnection;
118
+ }
108
119
  }
109
120
 
110
121
  export default WebRTCIssueDetector;
@@ -18,10 +18,6 @@ class FramesDroppedIssueDetector implements IssueDetector {
18
18
  }
19
19
 
20
20
  private processData(data: WebRTCStatsEventData): IssueDetectorResult {
21
- if (!data.video?.inbound) {
22
- return [];
23
- }
24
-
25
21
  const streamsWithDroppedFrames = data.video.inbound.filter((stats) => stats.framesDropped > 0);
26
22
  const issues: IssueDetectorResult = [];
27
23
  const previousInboundRTPVideoStreamsStats = this.#lastProcessedStats[data.connection.id]?.video.inbound;
@@ -18,10 +18,6 @@ class FramesEncodedSentIssueDetector implements IssueDetector {
18
18
  }
19
19
 
20
20
  private processData(data: WebRTCStatsEventData): IssueDetectorResult {
21
- if (!data.video?.outbound) {
22
- return [];
23
- }
24
-
25
21
  const streamsWithEncodedFrames = data.video.outbound.filter((stats) => stats.framesEncoded > 0);
26
22
  const issues: IssueDetectorResult = [];
27
23
  const previousOutboundRTPVideoStreamsStats = this.#lastProcessedStats[data.connection.id]?.video.outbound;
@@ -18,13 +18,16 @@ class NetworkIssueDetector implements IssueDetector {
18
18
  private processData(data: WebRTCStatsEventData): IssueDetectorResult {
19
19
  const issues: IssueDetectorResult = [];
20
20
  const inboundRTPStreamsStats = [...data.audio?.inbound, ...data.video?.inbound];
21
- const previousStats = this.#lastProcessedStats[data.connection.id];
22
- const previousInboundStreamStats = [...previousStats.video?.inbound, ...previousStats.audio?.inbound];
21
+ if (!inboundRTPStreamsStats.length) {
22
+ return issues;
23
+ }
23
24
 
24
- if (!inboundRTPStreamsStats.length || !previousStats) {
25
+ const previousStats = this.#lastProcessedStats[data.connection.id];
26
+ if (!previousStats) {
25
27
  return issues;
26
28
  }
27
29
 
30
+ const previousInboundStreamStats = [...previousStats.video?.inbound, ...previousStats.audio?.inbound];
28
31
  const { packetsReceived } = data.connection;
29
32
  const lastPacketsReceived = previousStats.connection.packetsReceived;
30
33
 
@@ -16,10 +16,6 @@ class QualityLimitationsIssueDetector implements IssueDetector {
16
16
  }
17
17
 
18
18
  private processData(data: WebRTCStatsEventData): IssueDetectorResult {
19
- if (!data.video?.outbound) {
20
- return [];
21
- }
22
-
23
19
  const streamsWithLimitation = data.video.outbound.filter((stats) => stats.qualityLimitationReason !== 'none');
24
20
  const issues: IssueDetectorResult = [];
25
21
  const previousOutboundRTPVideoStreamsStats = this.#lastProcessedStats[data.connection.id]?.video.outbound;
@@ -1,4 +0,0 @@
1
- declare class WIDRTCPeerConnection extends RTCPeerConnection {
2
- constructor(configuration?: RTCConfiguration);
3
- }
4
- export default WIDRTCPeerConnection;
@@ -1,13 +0,0 @@
1
- import { WIDWindow } from './types';
2
-
3
- class WIDRTCPeerConnection extends RTCPeerConnection {
4
- constructor(configuration?: RTCConfiguration) {
5
- super(configuration);
6
- const { wid: webRTCIssueDetector } = (window as unknown as WIDWindow);
7
- if (webRTCIssueDetector) {
8
- webRTCIssueDetector.handleNewPeerConnection(this);
9
- }
10
- }
11
- }
12
-
13
- export default WIDRTCPeerConnection;