-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
54 lines (47 loc) · 1.09 KB
/
utils.js
1
2
3
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
import Peer from "peerjs";
/**
* @returns {Peer}
*/
export function wordBowlPeer() {
const signalingServerConfig = {
host: "peerjs-server.toteto.tech",
port: 9443,
secure: true
};
return new Peer({
...signalingServerConfig,
config: {
iceServers: [
{
url: "turn:numb.viagenie.ca",
username: "[email protected]",
credential: "LfeuhHqbto8JM+JwMYDbdjWdV"
}
]
},
debug: 2
});
}
/**
* @typedef {string} UUID
*/
/**
* @returns {UUID} - The generated {@link UUID}
*/
export function uuid() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
}
Array.prototype.elementAfter = function(from) {
const fromIndex = this.findIndex(e => e === from);
if (fromIndex > -1 && fromIndex < this.length) {
return this[fromIndex + 1];
} else {
return null;
}
};
Array.prototype.sample = function() {
return this[Math.floor(Math.random() * this.length)];
};
export default { uuid, wordBowlPeer };