steamutils 1.3.83 → 1.3.84
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/utils.js +141 -131
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,131 +1,141 @@
|
|
|
1
|
-
const isBrowser = typeof window !==
|
|
2
|
-
|
|
3
|
-
export const sleep = (ms) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return object
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
1
|
+
const isBrowser = typeof window !== "undefined";
|
|
2
|
+
|
|
3
|
+
export const sleep = (ms) => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
setTimeout(resolve, ms);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const sleepRandom = async (startMs, endMs) => {
|
|
10
|
+
return await sleep(Math.random() * (endMs - startMs) + startMs);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* const audioTrack = stream.getAudioTracks()[0]
|
|
15
|
+
* const videoStream = UserMedia.createBlankVideoTrack()
|
|
16
|
+
* videoStream.addTrack(audioTrack)
|
|
17
|
+
* stream = videoStream
|
|
18
|
+
* **/
|
|
19
|
+
export const createBlankVideoTrack = (opts = {}) => {
|
|
20
|
+
const { width = 1920, height = 1080 } = opts;
|
|
21
|
+
|
|
22
|
+
const canvas = Object.assign(document.createElement("canvas"), {
|
|
23
|
+
width,
|
|
24
|
+
height,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
canvas.getContext("2d").fillRect(0, 0, width, height);
|
|
28
|
+
|
|
29
|
+
return canvas.captureStream();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const minDate = new Date(0),
|
|
33
|
+
maxDate = new Date(parseInt("ffffffff", 16) * 1000);
|
|
34
|
+
|
|
35
|
+
export function objectIdFromDate(date) {
|
|
36
|
+
if (date < minDate || date > maxDate) {
|
|
37
|
+
return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
|
|
38
|
+
}
|
|
39
|
+
var pad = "00000000";
|
|
40
|
+
var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
|
|
41
|
+
return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function dateFromObjectId(objectId) {
|
|
45
|
+
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function console_log(...args) {
|
|
49
|
+
const params = [];
|
|
50
|
+
params.push(new Date().toUTCString());
|
|
51
|
+
const errorStack = new Error().stack;
|
|
52
|
+
const fnName = errorStack
|
|
53
|
+
.split("\n")
|
|
54
|
+
.map((e) => e?.trim())
|
|
55
|
+
.filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
|
|
56
|
+
.substr(3);
|
|
57
|
+
params.push(fnName);
|
|
58
|
+
console.log(
|
|
59
|
+
params
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map((p) => `[${p.trim()}]`)
|
|
62
|
+
.join(" "),
|
|
63
|
+
...args,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function removeSpaceKeys(object) {
|
|
68
|
+
//mutate object
|
|
69
|
+
if (!object || Array.isArray(object)) {
|
|
70
|
+
return object;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
74
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
75
|
+
if (newKey !== key) {
|
|
76
|
+
delete object[key];
|
|
77
|
+
object[newKey] = value;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return object;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getCleanObject(object) {
|
|
84
|
+
//like removeSpaceKeys but not mutate object
|
|
85
|
+
if (!object || Array.isArray(object)) {
|
|
86
|
+
return object;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const newObject = {};
|
|
90
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
91
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
|
|
92
|
+
newObject[newKey] = value;
|
|
93
|
+
});
|
|
94
|
+
return newObject;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function JSON_parse(data) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(data);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function JSON_stringify(data) {
|
|
106
|
+
try {
|
|
107
|
+
return JSON.stringify(data);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function throttle(fn, delay) {
|
|
114
|
+
let canFire = true;
|
|
115
|
+
let queue = [];
|
|
116
|
+
|
|
117
|
+
async function pop() {
|
|
118
|
+
if (queue.length < 1) return;
|
|
119
|
+
|
|
120
|
+
const [that, args] = queue.pop();
|
|
121
|
+
await fn.apply(that, args);
|
|
122
|
+
canFire = false;
|
|
123
|
+
setTimeout(async () => {
|
|
124
|
+
canFire = true;
|
|
125
|
+
await pop();
|
|
126
|
+
}, delay);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function push() {
|
|
130
|
+
queue.push([this, arguments]);
|
|
131
|
+
if (canFire) {
|
|
132
|
+
await pop();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
push.cancel = () => {
|
|
137
|
+
queue = [];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return push;
|
|
141
|
+
}
|