@rtcstats/rtcstats-js 2.2.0 → 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.
- package/package.json +1 -1
- package/trace-websocket.js +19 -18
package/package.json
CHANGED
package/trace-websocket.js
CHANGED
|
@@ -8,7 +8,6 @@ export function WebSocketTrace(config = {}) {
|
|
|
8
8
|
let connection;
|
|
9
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(['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) {
|