@rtcstats/rtcstats-js 2.2.1 → 2.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/trace-websocket.js +20 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtcstats/rtcstats-js",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "gather WebRTC API traces and statistics",
5
5
  "main": "rtcstats.js",
6
6
  "type": "module",
@@ -6,9 +6,8 @@ const RELOAD_COUNT_KEY = 'rtcstatsReloadCount';
6
6
  export function WebSocketTrace(config = {}) {
7
7
  let buffer = [];
8
8
  let connection;
9
- let lastTime = Date.now();
9
+ let lastTime = 0;
10
10
  let connectionStartTime = 0;
11
- const createTime = Date.now();
12
11
 
13
12
  // This counts the number of times the trace itself has been initialized.
14
13
  // Typically this is done once per session and counting (re)loads based
@@ -56,12 +55,31 @@ export function WebSocketTrace(config = {}) {
56
55
  }
57
56
  if (connection) {
58
57
  connection.close();
58
+ connection = null;
59
59
  }
60
+ // New traces need to get an absolute timestamp.
61
+ lastTime = 0;
60
62
  };
61
63
  trace.connect = (wsURL) => {
62
64
  if (connection) {
63
65
  connection.close();
66
+ lastTime = 0;
64
67
  }
68
+ trace('create', null, {
69
+ hardwareConcurrency: navigator.hardwareConcurrency,
70
+ userAgentData: navigator.userAgentData,
71
+ deviceMemory: navigator.deviceMemory,
72
+ screen: {
73
+ width: window.screen.availWidth,
74
+ height: window.screen.availHeight,
75
+ devicePixelRatio: window.devicePixelRatio,
76
+ },
77
+ window: {
78
+ width: window.innerWidth,
79
+ height: window.innerHeight,
80
+ },
81
+ reloadCount,
82
+ });
65
83
  connectionStartTime = Date.now();
66
84
  connection = new WebSocket(wsURL, 'rtcstats#' + PROTOCOL_VERSION);
67
85
  connection.addEventListener('error', (e) => {
@@ -80,23 +98,6 @@ export function WebSocketTrace(config = {}) {
80
98
  // Note: open is called while the socket is still authenticating.
81
99
  // This can lead to messages being send and dropped when the token
82
100
  // is not valid.
83
-
84
- // Note: this does not use trace so avoids the buffer.
85
- connection.send(JSON.stringify([compressMethod('create'), null, {
86
- hardwareConcurrency: navigator.hardwareConcurrency,
87
- userAgentData: navigator.userAgentData,
88
- deviceMemory: navigator.deviceMemory,
89
- screen: {
90
- width: window.screen.availWidth,
91
- height: window.screen.availHeight,
92
- devicePixelRatio: window.devicePixelRatio,
93
- },
94
- window: {
95
- width: window.innerWidth,
96
- height: window.innerHeight,
97
- },
98
- reloadCount,
99
- }, createTime]));
100
101
  const connectionTime = Date.now() - connectionStartTime;
101
102
  setTimeout(function flush() {
102
103
  if (!buffer.length) {