@rtcstats/rtcstats-shared 2.3.0 → 2.4.0

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.
Files changed (3) hide show
  1. package/anonymize.js +39 -0
  2. package/dump.js +1 -0
  3. package/package.json +1 -1
package/anonymize.js ADDED
@@ -0,0 +1,39 @@
1
+ import {decompressMethod} from './compression.js';
2
+ import {obfuscateAddress, obfuscateIpOrAddress} from './address-obfuscator.js';
3
+
4
+ // Anonymize addresses in either an rtcstats dump or a webrtc-internals JSON
5
+ // dump (passed as text). Returns a Blob with the anonymized contents in the
6
+ // same format, or undefined if the format is not recognized.
7
+ export function anonymizeBlob(textBlob) {
8
+ if (textBlob.startsWith('RTCStatsDump\n')) {
9
+ const lines = textBlob.split('\n').map(line => {
10
+ if (line.startsWith('RTCStatsDump') || line === '') {
11
+ return line;
12
+ }
13
+ const data = JSON.parse(line);
14
+ obfuscateAddress(decompressMethod(data[0]), data);
15
+ return JSON.stringify(data);
16
+ });
17
+ return new Blob([lines.join('\n')]);
18
+ } else if (textBlob.startsWith('{')) {
19
+ const json = JSON.parse(textBlob);
20
+ Object.keys(json.PeerConnections).forEach(id => {
21
+ const pc = json.PeerConnections[id];
22
+ Object.keys(pc.stats).forEach(statsId => {
23
+ const stats = pc.stats[statsId];
24
+ const parts = statsId.split('-');
25
+ const type = parts[parts.length - 1];
26
+ if (!['address', 'ip', 'relatedAddress'].includes(type)) return;
27
+ const values = JSON.parse(stats.values);
28
+ stats.values = JSON.stringify(values.map(obfuscateIpOrAddress));
29
+ });
30
+ pc.updateLog.forEach(traceEvent => {
31
+ if (!traceEvent.value) return;
32
+ const value = JSON.parse(traceEvent.value);
33
+ obfuscateAddress(traceEvent.type, [,, value]);
34
+ traceEvent.value = JSON.stringify(value);
35
+ });
36
+ });
37
+ return new Blob([JSON.stringify(json, null, ' ')]);
38
+ }
39
+ }
package/dump.js CHANGED
@@ -312,3 +312,4 @@ export async function extractTracks(peerConnectionTrace) {
312
312
  }
313
313
  return tracks;
314
314
  }
315
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-shared",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "main": "index.js",
5
5
  "description": "gather WebRTC API traces and statistics",
6
6
  "type": "module",