speaker-calibration 2.2.173 → 2.2.174
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/dist/example/i18n.js +1057 -1057
- package/dist/example/listener.js +1 -1
- package/dist/main.js +3 -3
- package/package.json +1 -1
- package/src/peer-connection/listener.js +7 -5
- package/src/peer-connection/speaker.js +75 -7
package/package.json
CHANGED
|
@@ -26,13 +26,15 @@ class Listener extends AudioPeer {
|
|
|
26
26
|
|
|
27
27
|
const urlParameters = this.parseURLSearchParams();
|
|
28
28
|
this.calibrateSoundHz =
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// previous calibrateSoundHz
|
|
30
|
+
urlParameters.hz !== null && urlParameters.hz !== undefined
|
|
31
|
+
? urlParameters.hz
|
|
31
32
|
: 48000;
|
|
32
33
|
this.calibrateSoundSamplingDesiredBits =
|
|
33
|
-
|
|
34
|
-
urlParameters.
|
|
35
|
-
|
|
34
|
+
// previous calibrateSoundSamplingDesiredBits
|
|
35
|
+
urlParameters.bits !== null &&
|
|
36
|
+
urlParameters.bits !== undefined
|
|
37
|
+
? urlParameters.bits
|
|
36
38
|
: 24;
|
|
37
39
|
this.speakerPeerId = urlParameters.speakerPeerId;
|
|
38
40
|
|
|
@@ -44,15 +44,83 @@ class Speaker extends AudioPeer {
|
|
|
44
44
|
this.buttonsContainer = params?.buttonsContainer ?? document.createElement('div');
|
|
45
45
|
|
|
46
46
|
/* Set up callbacks that handle any events related to our peer object. */
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
uri = '';
|
|
50
|
+
qrImage;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
initPeer = async () => {
|
|
54
|
+
const id = await this.generateTimeBasedPeerID();
|
|
55
|
+
this.peer = new Peer(id, {
|
|
56
|
+
secure: true,
|
|
57
|
+
host: 'easyeyes-peer-server.herokuapp.com',
|
|
58
|
+
port: 443,
|
|
59
|
+
config: {
|
|
60
|
+
iceServers: [
|
|
61
|
+
{
|
|
62
|
+
urls: "stun:stun.relay.metered.ca:80",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
urls: "turn:global.relay.metered.ca:80",
|
|
66
|
+
username: "de884cfc34189cdf1a5dd616",
|
|
67
|
+
credential: "IcOpouU9/TYBmpHU",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
urls: "turn:global.relay.metered.ca:80?transport=tcp",
|
|
71
|
+
username: "de884cfc34189cdf1a5dd616",
|
|
72
|
+
credential: "IcOpouU9/TYBmpHU",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
urls: "turn:global.relay.metered.ca:443",
|
|
76
|
+
username: "de884cfc34189cdf1a5dd616",
|
|
77
|
+
credential: "IcOpouU9/TYBmpHU",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
urls: "turns:global.relay.metered.ca:443?transport=tcp",
|
|
81
|
+
username: "de884cfc34189cdf1a5dd616",
|
|
82
|
+
credential: "IcOpouU9/TYBmpHU",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
47
87
|
this.peer.on('open', this.#onPeerOpen);
|
|
48
88
|
this.peer.on('connection', this.#onPeerConnection);
|
|
49
89
|
this.peer.on('close', this.onPeerClose);
|
|
50
90
|
this.peer.on('disconnected', this.#onPeerDisconnected);
|
|
51
91
|
this.peer.on('error', this.#onPeerError);
|
|
52
92
|
}
|
|
93
|
+
generateTimeBasedPeerID = async () => {
|
|
94
|
+
const now = new Date().getTime();
|
|
95
|
+
const randomBuffer = new Uint8Array(10);
|
|
96
|
+
crypto.getRandomValues(randomBuffer);
|
|
97
|
+
const randomPart = Array.from(randomBuffer)
|
|
98
|
+
.map((b) => b.toString(36))
|
|
99
|
+
.join("");
|
|
100
|
+
const toHash = `${now}-${randomPart}`;
|
|
101
|
+
const encoder = new TextEncoder();
|
|
102
|
+
const data = encoder.encode(toHash);
|
|
103
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
104
|
+
const hashArray = Array.from(new Uint8Array(hash)); // Convert buffer to byte array
|
|
105
|
+
const hashString = hashArray
|
|
106
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
107
|
+
.join("");
|
|
108
|
+
const shortHash = hashString.substring(0, 12); // Use more of the hash for a longer ID
|
|
109
|
+
// return shortHash; // Consider converting this to Base62
|
|
110
|
+
return this.encodeBase62(parseInt(shortHash, 16));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
encodeBase62 = (num) => {
|
|
114
|
+
const base = 36;
|
|
115
|
+
const characters = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
116
|
+
let result = "";
|
|
117
|
+
while (num > 0) {
|
|
118
|
+
result = characters[num % base] + result;
|
|
119
|
+
num = Math.floor(num / base);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
53
123
|
|
|
54
|
-
uri = '';
|
|
55
|
-
qrImage;
|
|
56
124
|
/**
|
|
57
125
|
* Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.
|
|
58
126
|
*
|
|
@@ -66,7 +134,7 @@ class Speaker extends AudioPeer {
|
|
|
66
134
|
static startCalibration = async (params, CalibratorInstance, timeOut = 180000) => {
|
|
67
135
|
window.speaker = new Speaker(params, CalibratorInstance);
|
|
68
136
|
const {speaker} = window;
|
|
69
|
-
|
|
137
|
+
await speaker.initPeer();
|
|
70
138
|
// wrap the calibration process in a promise so we can await it
|
|
71
139
|
return new Promise((resolve, reject) => {
|
|
72
140
|
// when a call is received
|
|
@@ -153,7 +221,7 @@ class Speaker extends AudioPeer {
|
|
|
153
221
|
static testIIR = async (params, CalibratorInstance, IIR, timeOut = 180000) => {
|
|
154
222
|
window.speaker = new Speaker(params, CalibratorInstance);
|
|
155
223
|
const {speaker} = window;
|
|
156
|
-
|
|
224
|
+
speaker.initPeer();
|
|
157
225
|
// wrap the calibration process in a promise so we can await it
|
|
158
226
|
return new Promise((resolve, reject) => {
|
|
159
227
|
// when a call is received
|
|
@@ -205,9 +273,9 @@ class Speaker extends AudioPeer {
|
|
|
205
273
|
// Get query string, the URL parameters to specify a Listener
|
|
206
274
|
const queryStringParameters = {
|
|
207
275
|
speakerPeerId: this.peer.id,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
276
|
+
sp: this.isSmartPhone,
|
|
277
|
+
hz: this.calibrateSoundHz,
|
|
278
|
+
bits: this.calibrateSoundSamplingDesiredBits,
|
|
211
279
|
lang: this.language,
|
|
212
280
|
};
|
|
213
281
|
const queryString = this.queryStringFromObject(queryStringParameters);
|