speaker-calibration 2.2.162 → 2.2.164

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 (120) hide show
  1. package/.eslintignore +71 -71
  2. package/.eslintrc.json +40 -40
  3. package/.gitignore +81 -0
  4. package/.prettierignore +69 -69
  5. package/.prettierrc +14 -14
  6. package/LICENSE +20 -20
  7. package/README.md +133 -133
  8. package/__mocks__/fileMock.js +1 -1
  9. package/__mocks__/styleMock.js +1 -1
  10. package/babel.config.js +3 -3
  11. package/coverage/clover.xml +71 -71
  12. package/coverage/coverage-final.json +224 -224
  13. package/coverage/lcov-report/PythonServerInterface.js.html +265 -265
  14. package/coverage/lcov-report/base.css +354 -354
  15. package/coverage/lcov-report/block-navigation.js +82 -82
  16. package/coverage/lcov-report/index.html +123 -123
  17. package/coverage/lcov-report/prettify.css +101 -101
  18. package/coverage/lcov-report/prettify.js +937 -937
  19. package/coverage/lcov-report/sorter.js +189 -189
  20. package/coverage/lcov-report/src/index.html +121 -121
  21. package/coverage/lcov-report/src/server/PythonServerInterface.js.html +268 -268
  22. package/coverage/lcov-report/src/server/index.html +123 -123
  23. package/coverage/lcov-report/src/tasks/audioCalibrator.js.html +499 -499
  24. package/coverage/lcov-report/src/tasks/audioRecorder.js.html +412 -412
  25. package/coverage/lcov-report/src/tasks/index.html +143 -143
  26. package/coverage/lcov-report/src/tasks/volume/index.html +123 -123
  27. package/coverage/lcov-report/src/tasks/volume/volume.js.html +409 -409
  28. package/coverage/lcov-report/src/utils.js.html +172 -172
  29. package/coverage/lcov.info +91 -91
  30. package/dist/example/fetch-languages-sheets.js +77 -77
  31. package/dist/example/i18n.js +24203 -23984
  32. package/dist/example/index.html +47 -47
  33. package/dist/example/listener.html +69 -62
  34. package/dist/example/listener.js +149 -132
  35. package/dist/example/server.js +51 -51
  36. package/dist/example/speaker.html +145 -145
  37. package/dist/example/speakerUI.js +273 -273
  38. package/dist/example/styles.css +99 -96
  39. package/dist/main.js +17 -17
  40. package/dist/mlsGen.js +6814 -6814
  41. package/dist/mlsGen.wasm +0 -0
  42. package/dist/package-lock.json +1018 -1018
  43. package/dist/package.json +18 -18
  44. package/doc/AudioCalibrator.html +417 -417
  45. package/doc/AudioPeer.html +251 -251
  46. package/doc/AudioRecorder.html +195 -195
  47. package/doc/ImpulseResponse.html +215 -215
  48. package/doc/Listener.html +308 -308
  49. package/doc/MlsGenInterface.html +226 -226
  50. package/doc/MyEventEmitter.html +274 -274
  51. package/doc/PythonServerAPI.html +109 -109
  52. package/doc/Speaker.html +276 -276
  53. package/doc/Takes%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +128 -128
  54. package/doc/Takes%20the%20url%20of%20the%20current%20site%0Aand%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +138 -138
  55. package/doc/Takes%20the%20url%20of%20the%20current%20site%20and%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +137 -137
  56. package/doc/Volume.html +88 -88
  57. package/doc/audioCalibrator.js.html +179 -179
  58. package/doc/audioPeer.js.html +175 -175
  59. package/doc/audioRecorder.js.html +163 -163
  60. package/doc/creates%20a%20new%20AudioRecorder%20instance.%20%0ASets%20up%20the%20audio%20context%20and%20file%20reader..html +114 -114
  61. package/doc/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  62. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  63. package/doc/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  64. package/doc/fonts/OpenSans-Light-webfont.svg +1830 -1830
  65. package/doc/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  66. package/doc/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  67. package/doc/global.html +308 -308
  68. package/doc/index.html +58 -58
  69. package/doc/listener.js.html +170 -170
  70. package/doc/mlsGen_mlsGenInterface.js.html +117 -117
  71. package/doc/myEventEmitter.js.html +124 -124
  72. package/doc/peer-connection_audioPeer.js.html +188 -188
  73. package/doc/peer-connection_listener.js.html +311 -311
  74. package/doc/peer-connection_speaker.js.html +381 -381
  75. package/doc/scripts/linenumber.js +25 -25
  76. package/doc/scripts/prettify/Apache-License-2.0.txt +202 -202
  77. package/doc/scripts/prettify/lang-css.js +24 -24
  78. package/doc/scripts/prettify/prettify.js +640 -640
  79. package/doc/server_PythonServerAPI.js.html +160 -160
  80. package/doc/speaker.js.html +248 -248
  81. package/doc/styles/jsdoc-default.css +371 -371
  82. package/doc/styles/prettify-jsdoc.css +111 -111
  83. package/doc/styles/prettify-tomorrow.css +163 -163
  84. package/doc/tasks_audioCalibrator.js.html +207 -207
  85. package/doc/tasks_audioRecorder.js.html +190 -190
  86. package/doc/tasks_impulse-response_impulseResponse.js.html +442 -442
  87. package/doc/tasks_impulse-response_mlsGen_mlsGenInterface.js.html +175 -175
  88. package/doc/tasks_volume_volume.js.html +185 -185
  89. package/doc/utils.js.html +105 -105
  90. package/jest.config.js +173 -173
  91. package/netlify.toml +26 -26
  92. package/package.json +71 -71
  93. package/src/config/firebase.js +26 -26
  94. package/src/index.html +21 -21
  95. package/src/main.js +23 -23
  96. package/src/myEventEmitter.js +83 -83
  97. package/src/peer-connection/audioPeer.js +178 -178
  98. package/src/peer-connection/listener.js +338 -338
  99. package/src/peer-connection/peerErrors.js +25 -25
  100. package/src/peer-connection/speaker.js +573 -574
  101. package/src/server/PythonServerAPI.js +796 -796
  102. package/src/tasks/audioCalibrator.js +323 -323
  103. package/src/tasks/audioRecorder.js +315 -315
  104. package/src/tasks/combination/combination.js +2893 -2901
  105. package/src/tasks/combination/mlsGen/mlsGen.cpp +98 -98
  106. package/src/tasks/combination/mlsGen/mlsGen.hpp +303 -303
  107. package/src/tasks/combination/mlsGen/mlsGenInterface.js +131 -131
  108. package/src/tasks/combination/mlsGen/mlsGenTest.cpp +180 -180
  109. package/src/tasks/impulse-response/impulseResponse.js +610 -610
  110. package/src/tasks/impulse-response/mlsGen/mlsGen.cpp +98 -98
  111. package/src/tasks/impulse-response/mlsGen/mlsGen.hpp +303 -303
  112. package/src/tasks/impulse-response/mlsGen/mlsGenInterface.js +131 -131
  113. package/src/tasks/impulse-response/mlsGen/mlsGenTest.cpp +180 -180
  114. package/src/tasks/volume/volume.cpp +2 -2
  115. package/src/tasks/volume/volume.hpp +22 -22
  116. package/src/tasks/volume/volume.js +279 -279
  117. package/src/utils.js +135 -135
  118. package/webpack.config.js +37 -37
  119. package/.github/workflows/update-phrases.yml +0 -37
  120. package/makefile +0 -74
@@ -1,574 +1,573 @@
1
- import QRCode from 'qrcode';
2
- import AudioPeer from './audioPeer';
3
- import {sleep} from '../utils';
4
- import {
5
- UnsupportedDeviceError,
6
- MissingSpeakerIdError,
7
- CalibrationTimedOutError,
8
- } from './peerErrors';
9
-
10
- import {phrases} from '../../dist/example/i18n';
11
-
12
- /**
13
- * @class Handles the speaker's side of the connection. Responsible for initiating the connection,
14
- * rendering the QRCode, and answering the call.
15
- * @augments AudioPeer
16
- */
17
- class Speaker extends AudioPeer {
18
- /**
19
- * Takes the url of the current site and a target element where html elements will be appended.
20
- *
21
- * @param params - See type definition for initParameters.
22
- * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.
23
- * @param CalibratorInstance
24
- * @example
25
- */
26
- constructor(params, CalibratorInstance) {
27
- super(params);
28
- this.language = params?.language ?? 'en-US';
29
- this.siteUrl += '/listener?';
30
- this.ac = CalibratorInstance;
31
- this.result = null;
32
- this.debug = params?.debug ?? false;
33
- this.isSmartPhone = params?.isSmartPhone ?? false;
34
- this.calibrateSoundHz = params?.calibrateSoundHz ?? 48000;
35
- this.calibrateSoundSamplingDesiredBits = params?.calibrateSoundSamplingDesiredBits ?? 24;
36
- this.instructionDisplayId = params?.instructionDisplayId ?? '';
37
- this.soundSubtitleId = params?.soundSubtitleId ?? '';
38
- this.timeToCalibrateDisplay = params?.timeToCalibrateId ?? '';
39
- this.soundMessageId = params?.soundMessageId ?? '';
40
- this.titleDisplayId = params?.titleDisplayId ?? '';
41
- this.timeToCalibrate = params?.timeToCalibrate ?? 10;
42
- this.isParticipant = params?.isParticipant ?? false;
43
- this.isLoudspeakerCalibration = params?.isLoudspeakerCalibration ?? false;
44
-
45
- /* Set up callbacks that handle any events related to our peer object. */
46
- this.peer.on('open', this.#onPeerOpen);
47
- this.peer.on('connection', this.#onPeerConnection);
48
- this.peer.on('close', this.onPeerClose);
49
- this.peer.on('disconnected', this.#onPeerDisconnected);
50
- this.peer.on('error', this.#onPeerError);
51
- }
52
- /**
53
- * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.
54
- *
55
- * @param params - The parameters to be passed to the peer object.
56
- * @param Calibrator - The class that defines the calibration process.
57
- * @param CalibratorInstance
58
- * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).
59
- * @public
60
- * @example
61
- */
62
- static startCalibration = async (params, CalibratorInstance, timeOut = 180000) => {
63
- window.speaker = new Speaker(params, CalibratorInstance);
64
- const {speaker} = window;
65
-
66
- // wrap the calibration process in a promise so we can await it
67
- return new Promise((resolve, reject) => {
68
- // when a call is received
69
- speaker.peer.on('call', async call => {
70
- // Answer the call (one way)
71
-
72
- call.answer();
73
- speaker.#removeUIElems();
74
- speaker.#showSpinner();
75
- speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));
76
- // when we start receiving audio
77
- call.on('stream', async stream => {
78
- window.localStream = stream;
79
- window.localAudio.srcObject = stream;
80
- window.localAudio.autoplay = false;
81
-
82
- // if the sinkSamplingRate is not set sleep
83
- while (!speaker.ac.sampleRatesSet()) {
84
- console.log('SinkSamplingRate is undefined, sleeping');
85
- await sleep(1);
86
- }
87
-
88
- if (params.displayUpdate) {
89
- params.displayUpdate.style.display = '';
90
- }
91
-
92
- // resolve when we have a result
93
- console.log(params.calibrateSoundIRSec);
94
- console.log(params);
95
- speaker.result = await speaker.ac.startCalibration(
96
- stream,
97
- params.gainValues,
98
- params.ICalib,
99
- params.knownIR,
100
- params.microphoneName,
101
- params.calibrateSoundCheck,
102
- params.isSmartPhone,
103
- params.calibrateSoundBurstDb,
104
- params.calibrateSoundBurstFilteredExtraDb,
105
- params.calibrateSoundBurstLevelReTBool,
106
- params.calibrateSoundBurstUses1000HzGainBool,
107
- params.calibrateSoundBurstRepeats,
108
- params.calibrateSoundBurstSec,
109
- params.calibrateSoundBurstsWarmup,
110
- params.calibrateSoundHz,
111
- params.calibrateSoundIRSec,
112
- params.calibrateSoundIIRSec,
113
- params.calibrateSoundIIRPhase,
114
- params.calibrateSound1000HzPreSec,
115
- params.calibrateSound1000HzSec,
116
- params.calibrateSound1000HzPostSec,
117
- params.calibrateSoundBackgroundSecs,
118
- params.calibrateSoundSmoothOctaves,
119
- params.calibrateSoundPowerBinDesiredSec,
120
- params.calibrateSoundPowerDbSDToleratedDb,
121
- params.micManufacturer,
122
- params.micSerialNumber,
123
- params.micModelNumber,
124
- params.micModelName,
125
- params.calibrateMicrophonesBool,
126
- params.authorEmails,
127
- params.webAudioDeviceNames,
128
- params.IDsToSaveInSoundProfileLibrary,
129
- params.restartButton,
130
- params.reminder,
131
- params.calibrateSoundLimit
132
- );
133
- speaker.#removeUIElems();
134
- resolve(speaker.result);
135
- });
136
- // if we do not receive a result within the timeout, reject
137
- setTimeout(() => {
138
- reject(
139
- new CalibrationTimedOutError(
140
- `Calibration failed to produce a result after ${
141
- timeOut / 1000
142
- } seconds. Please try again.`
143
- )
144
- );
145
- }, timeOut);
146
- });
147
- });
148
- };
149
-
150
- static testIIR = async (params, CalibratorInstance, IIR, timeOut = 180000) => {
151
- window.speaker = new Speaker(params, CalibratorInstance);
152
- const {speaker} = window;
153
-
154
- // wrap the calibration process in a promise so we can await it
155
- return new Promise((resolve, reject) => {
156
- // when a call is received
157
- speaker.peer.on('call', async call => {
158
- // Answer the call (one way)
159
- call.answer();
160
- speaker.#removeUIElems();
161
- speaker.#showSpinner();
162
- speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));
163
- // when we start receiving audio
164
- call.on('stream', async stream => {
165
- window.localStream = stream;
166
- window.localAudio.srcObject = stream;
167
- window.localAudio.autoplay = false;
168
-
169
- // if the sinkSamplingRate is not set sleep
170
- while (!speaker.ac.sampleRatesSet()) {
171
- console.log('SinkSamplingRate is undefined, sleeping');
172
- await sleep(1);
173
- }
174
- // resolve when we have a result
175
- speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);
176
- speaker.#removeUIElems();
177
- resolve(speaker.result);
178
- });
179
- // if we do not receive a result within the timeout, reject
180
- setTimeout(() => {
181
- reject(
182
- new CalibrationTimedOutError(
183
- `Calibration failed to produce a result after ${
184
- timeOut / 1000
185
- } seconds. Please try again.`
186
- )
187
- );
188
- }, timeOut);
189
- });
190
- });
191
- };
192
-
193
- /**
194
- * Called after the peer conncection has been opened.
195
- * Generates a QR code for the connection and displays it.
196
- *
197
- * @private
198
- * @example
199
- */
200
- #showQRCode = () => {
201
- // Get query string, the URL parameters to specify a Listener
202
- const queryStringParameters = {
203
- speakerPeerId: this.peer.id,
204
- isSmartPhone: this.isSmartPhone,
205
- calibrateSoundHz: this.calibrateSoundHz,
206
- calibrateSoundSamplingDesiredBits: this.calibrateSoundSamplingDesiredBits,
207
- lang: this.language,
208
- };
209
- const queryString = this.queryStringFromObject(queryStringParameters);
210
- const uri = this.siteUrl + queryString;
211
- if (this.isSmartPhone) {
212
- // Display QR code for the participant to scan
213
- const qrCanvas = document.createElement('canvas');
214
- qrCanvas.setAttribute('id', 'qrCanvas');
215
- console.log(uri);
216
- QRCode.toCanvas(qrCanvas, uri, error => {
217
- if (error) console.error(error);
218
- });
219
- const qrImage = new Image(400, 400);
220
- qrImage.setAttribute('id', 'compatibilityCheckQRImage');
221
- qrImage.style.zIndex = Infinity;
222
- qrImage.style.width = 400;
223
- qrImage.style.height = 400;
224
- qrImage.style.aspectRatio = 1;
225
- qrImage.src = qrCanvas.toDataURL();
226
- qrImage.style.maxHeight = '150px';
227
- qrImage.style.maxWidth = '150px';
228
- document.getElementById(this.targetElement).appendChild(qrImage);
229
- } else {
230
- // show the link to the user
231
- // If specified HTML Id is available, show QR code there
232
- if (document.getElementById(this.targetElement)) {
233
- // const linkTag = document.createElement('a');
234
- // linkTag.setAttribute('href', uri);
235
- // linkTag.innerHTML = 'Click here to start the calibration';
236
- // linkTag.target = '_blank';
237
- // document.getElementById(this.targetElement).appendChild(linkTag);
238
- // document.getElementById(this.targetElement).appendChild(qrCanvas);
239
-
240
- const proceedButton = document.createElement('button');
241
- proceedButton.setAttribute('id', 'calibrationProceedButton');
242
- proceedButton.setAttribute('class', 'btn btn-success');
243
- proceedButton.innerHTML = 'Proceed';
244
- proceedButton.onclick = () => {
245
- // open the link in a new tab
246
- window.open(uri, '_blank');
247
- // remove the button
248
- document.getElementById('calibrationProceedButton').remove();
249
- };
250
- document.getElementById(this.targetElement).appendChild(proceedButton);
251
- }
252
- }
253
- // or just print it to console
254
- console.log('TEST: Peer reachable at: ', uri);
255
- };
256
-
257
- #showSpinner = () => {
258
- const spinner = document.createElement('div');
259
- spinner.className = 'spinner-border ml-auto';
260
- spinner.role = 'status';
261
- spinner.ariaHidden = 'true';
262
- document.getElementById(this.targetElement).appendChild(spinner);
263
-
264
- // clear instructionDisplay
265
- const soundMessage = document.getElementById(this.soundMessageId);
266
- soundMessage.innerHTML = '';
267
- soundMessage.style.display = 'none';
268
- const instructionDisplay = document.getElementById(this.instructionDisplayId);
269
- const background = document.getElementById('background'); // todo: get background id from params
270
- const subtitle = document.getElementById(this.soundSubtitleId);
271
- if (subtitle) {
272
- subtitle.innerHTML = '';
273
- }
274
- if (instructionDisplay) {
275
- instructionDisplay.innerHTML = '';
276
- instructionDisplay.style.whiteSpace = 'nowrap';
277
- instructionDisplay.style.fontWeight = 'bold';
278
- instructionDisplay.style.width = 'fit-content';
279
- instructionDisplay.innerHTML = phrases.RC_soundRecording[this.language];
280
- let fontSize = 100;
281
- instructionDisplay.style.fontSize = fontSize + 'px';
282
- while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {
283
- fontSize--;
284
- instructionDisplay.style.fontSize = fontSize + 'px';
285
- }
286
- // const p = document.createElement('p');
287
- // // font size
288
- // p.style.fontSize = '1.1rem';
289
- // p.style.fontWeight = 'normal';
290
- // p.style.paddingTop = '20px';
291
- // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];
292
- // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);
293
- // instructionDisplay.appendChild(p);
294
- }
295
-
296
- const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);
297
- if (timeToCalibrateDisplay) {
298
- const timeToCalibrateText = phrases.RC_howLongToCalibrate[this.language];
299
- timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);
300
- timeToCalibrateDisplay.style.fontWeight = 'normal';
301
- timeToCalibrateDisplay.style.fontSize = '1rem';
302
- // timeToCalibrateDisplay.style.paddingTop = '20px';
303
- }
304
-
305
- // Update title - titleDisplayId
306
- const titleDisplay = document.getElementById(this.titleDisplayId);
307
- if (titleDisplay) {
308
- // if (this.isParticipant) {
309
- // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');
310
- // } else if (this.isSmartPhone) {
311
- // if (this.isLoudspeakerCalibration) {
312
- // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');
313
- // } else {
314
- // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
315
- // }
316
- // } else {
317
- // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
318
- // }
319
- if (this.isLoudspeakerCalibration) {
320
- if (this.isParticipant) {
321
- titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');
322
- } else if (this.isSmartPhone) {
323
- titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');
324
- } else {
325
- titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
326
- }
327
- } else {
328
- if (this.isSmartPhone) {
329
- titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
330
- } else {
331
- titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');
332
- }
333
- }
334
- }
335
- };
336
-
337
- #removeUIElems = () => {
338
- const parent = document.getElementById(this.targetElement);
339
- while (parent.firstChild) {
340
- parent.firstChild.remove();
341
- }
342
- };
343
-
344
- /**
345
- * Called when the peer connection is opened.
346
- * Saves the peer id and calls the QR code generator.
347
- *
348
- * @param peerId - The peer id of the peer connection.
349
- * @param id
350
- * @private
351
- * @example
352
- */
353
- #onPeerOpen = id => {
354
- // Workaround for peer.reconnect deleting previous id
355
- if (id === null) {
356
- console.error('Received null id from peer open');
357
- this.peer.id = this.lastPeerId;
358
- } else {
359
- this.lastPeerId = this.peer.id;
360
- }
361
-
362
- if (id !== this.peer.id) {
363
- console.warn('DEBUG Check you assumption that id === this.peer.id');
364
- }
365
-
366
- this.#showQRCode();
367
- };
368
-
369
- /**
370
- * Called when the peer connection is established.
371
- * Enforces a single connection.
372
- *
373
- * @param connection - The connection object.
374
- * @private
375
- * @example
376
- */
377
- #onPeerConnection = connection => {
378
- // Allow only a single connection
379
- if (this.conn && this.conn.open) {
380
- connection.on('open', () => {
381
- connection.send('Already connected to another client');
382
- setTimeout(() => {
383
- connection.close();
384
- }, 500);
385
- });
386
- return;
387
- }
388
-
389
- this.conn = connection;
390
- console.log('Connected to: ', this.conn.peer);
391
- this.#ready();
392
- };
393
-
394
- /**
395
- * Called when the peer connection is closed.
396
- *
397
- * @private
398
- * @example
399
- */
400
- onPeerClose = () => {
401
- this.conn = null;
402
- console.log('Connection destroyed');
403
- };
404
-
405
- static closeConnection = () => {
406
- this.conn = null;
407
- console.log('Connection destroyed');
408
- };
409
-
410
- /**
411
- * Called when the peer connection is disconnected.
412
- * Attempts to reconnect.
413
- *
414
- * @private
415
- * @example
416
- */
417
- #onPeerDisconnected = () => {
418
- console.log('Connection lost. Please reconnect');
419
-
420
- // Workaround for peer.reconnect deleting previous id
421
- this.peer.id = this.lastPeerId;
422
- // eslint-disable-next-line no-underscore-dangle
423
- this.peer._lastServerId = this.lastPeerId;
424
- this.peer.reconnect();
425
- };
426
-
427
- /**
428
- * Called when the peer connection encounters an error.
429
- *
430
- * @param error
431
- * @private
432
- * @example
433
- */
434
- #onPeerError = error => {
435
- // TODO: check if this function is needed or not
436
- console.error(error);
437
- };
438
-
439
- /**
440
- * Called when data is received from the peer connection.
441
- *
442
- * @param data
443
- * @private
444
- * @example
445
- */
446
- #onIncomingData = data => {
447
- // enforce object type
448
- if (
449
- !Object.prototype.hasOwnProperty.call(data, 'name') ||
450
- !Object.prototype.hasOwnProperty.call(data, 'payload')
451
- ) {
452
- console.error('Received malformed data: ', data);
453
- return;
454
- }
455
-
456
- switch (data.name) {
457
- case 'samplingRate':
458
- this.ac.setSamplingRates(data.payload);
459
- break;
460
- case 'sampleSize':
461
- this.ac.setSampleSize(data.payload);
462
- break;
463
- case 'deviceType':
464
- this.ac.setDeviceType(data.payload);
465
- break;
466
- case 'deviceName':
467
- this.ac.setDeviceName(data.payload);
468
- break;
469
- case 'flags':
470
- //this.ac.setDeviceName(data.payload);
471
- console.log('FLAGS');
472
- console.log(data.payload);
473
- this.ac.setFlags(data.payload);
474
- break;
475
- case 'deviceInfo':
476
- this.ac.setDeviceInfo(data.payload);
477
- console.log('Received device info from listener: ', data.payload);
478
- break;
479
- case UnsupportedDeviceError.name:
480
- case MissingSpeakerIdError.name:
481
- throw data.payload;
482
- break;
483
- default:
484
- break;
485
- }
486
- };
487
-
488
- /**
489
- * Called when the peer connection is #ready.
490
- *
491
- * @private
492
- * @example
493
- */
494
- #ready = () => {
495
- // Perform callback with data
496
- this.conn.on('data', this.#onIncomingData);
497
- this.conn.on('close', () => {
498
- console.log('Connection reset<br>Awaiting connection...');
499
- this.conn = null;
500
- });
501
- };
502
-
503
- /** .
504
- * .
505
- * .
506
- * Debug method for downloading the recorded audio
507
- *
508
- * @public
509
- * @example
510
- */
511
- downloadData = () => {
512
- this.ac.downloadData();
513
- };
514
-
515
- repeatCalibration = async (params, stream, CalibratorInstance) => {
516
- this.ac = CalibratorInstance;
517
- this.#removeUIElems();
518
- this.#showSpinner();
519
-
520
- console.log('This is a repeat');
521
- // wrap the calibration process in a promise so we can await it
522
- return new Promise(async (resolve, reject) => {
523
- const result = await this.ac.startCalibration(
524
- stream,
525
- params.gainValues,
526
- params.ICalib,
527
- params.knownIR,
528
- params.microphoneName,
529
- params.calibrateSoundCheck,
530
- params.isSmartPhone,
531
- params.calibrateSoundBurstDb,
532
- params.calibrateSoundBurstFilteredExtraDb,
533
- params.calibrateSoundBurstLevelReTBool,
534
- params.calibrateSoundBurstUses1000HzGainBool,
535
- params.calibrateSoundBurstRepeats,
536
- params.calibrateSoundBurstSec,
537
- params.calibrateSoundBurstsWarmup,
538
- params.calibrateSoundHz,
539
- params.calibrateSoundIRSec,
540
- params.calibrateSoundIIRSec,
541
- params.params.calibrateSoundIIRPhase,
542
- params.calibrateSound1000HzPreSec,
543
- params.calibrateSound1000HzSec,
544
- params.calibrateSound1000HzPostSec,
545
- params.calibrateSoundBackgroundSecs,
546
- params.calibrateSoundSmoothOctaves,
547
- params.calibrateSoundPowerBinDesiredSec,
548
- params.calibrateSoundPowerDbSDToleratedDb,
549
- params.micManufacturer,
550
- params.micSerialNumber,
551
- params.micModelNumber,
552
- params.micModelName,
553
- params.calibrateMicrophonesBool,
554
- params.authorEmails,
555
- params.webAudioDeviceNames,
556
- params.IDsToSaveInSoundProfileLibrary,
557
- params.restartButton,
558
- params.reminder,
559
- params.calibrateSoundLimit
560
- );
561
- this.#removeUIElems();
562
- resolve(result);
563
- });
564
- };
565
- }
566
-
567
- /*
568
- Referenced links:
569
- https://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676
570
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
571
- https://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]
572
- */
573
-
574
- export default Speaker;
1
+ import QRCode from 'qrcode';
2
+ import AudioPeer from './audioPeer';
3
+ import {sleep} from '../utils';
4
+ import {
5
+ UnsupportedDeviceError,
6
+ MissingSpeakerIdError,
7
+ CalibrationTimedOutError,
8
+ } from './peerErrors';
9
+
10
+ import {phrases} from '../../dist/example/i18n';
11
+
12
+ /**
13
+ * @class Handles the speaker's side of the connection. Responsible for initiating the connection,
14
+ * rendering the QRCode, and answering the call.
15
+ * @augments AudioPeer
16
+ */
17
+ class Speaker extends AudioPeer {
18
+ /**
19
+ * Takes the url of the current site and a target element where html elements will be appended.
20
+ *
21
+ * @param params - See type definition for initParameters.
22
+ * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.
23
+ * @param CalibratorInstance
24
+ * @example
25
+ */
26
+ constructor(params, CalibratorInstance) {
27
+ super(params);
28
+ this.language = params?.language ?? 'en-US';
29
+ this.siteUrl += '/listener?';
30
+ this.ac = CalibratorInstance;
31
+ this.result = null;
32
+ this.debug = params?.debug ?? false;
33
+ this.isSmartPhone = params?.isSmartPhone ?? false;
34
+ this.calibrateSoundHz = params?.calibrateSoundHz ?? 48000;
35
+ this.calibrateSoundSamplingDesiredBits = params?.calibrateSoundSamplingDesiredBits ?? 24;
36
+ this.instructionDisplayId = params?.instructionDisplayId ?? '';
37
+ this.soundSubtitleId = params?.soundSubtitleId ?? '';
38
+ this.timeToCalibrateDisplay = params?.timeToCalibrateId ?? '';
39
+ this.soundMessageId = params?.soundMessageId ?? '';
40
+ this.titleDisplayId = params?.titleDisplayId ?? '';
41
+ this.timeToCalibrate = params?.timeToCalibrate ?? 10;
42
+ this.isParticipant = params?.isParticipant ?? false;
43
+ this.isLoudspeakerCalibration = params?.isLoudspeakerCalibration ?? false;
44
+
45
+ /* Set up callbacks that handle any events related to our peer object. */
46
+ this.peer.on('open', this.#onPeerOpen);
47
+ this.peer.on('connection', this.#onPeerConnection);
48
+ this.peer.on('close', this.onPeerClose);
49
+ this.peer.on('disconnected', this.#onPeerDisconnected);
50
+ this.peer.on('error', this.#onPeerError);
51
+ }
52
+ /**
53
+ * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.
54
+ *
55
+ * @param params - The parameters to be passed to the peer object.
56
+ * @param Calibrator - The class that defines the calibration process.
57
+ * @param CalibratorInstance
58
+ * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).
59
+ * @public
60
+ * @example
61
+ */
62
+ static startCalibration = async (params, CalibratorInstance, timeOut = 180000) => {
63
+ window.speaker = new Speaker(params, CalibratorInstance);
64
+ const {speaker} = window;
65
+
66
+ // wrap the calibration process in a promise so we can await it
67
+ return new Promise((resolve, reject) => {
68
+ // when a call is received
69
+ speaker.peer.on('call', async call => {
70
+ // Answer the call (one way)
71
+
72
+ call.answer();
73
+ speaker.#removeUIElems();
74
+ speaker.#showSpinner();
75
+ speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));
76
+ // when we start receiving audio
77
+ call.on('stream', async stream => {
78
+ window.localStream = stream;
79
+ window.localAudio.srcObject = stream;
80
+ window.localAudio.autoplay = false;
81
+
82
+ // if the sinkSamplingRate is not set sleep
83
+ while (!speaker.ac.sampleRatesSet()) {
84
+ console.log('SinkSamplingRate is undefined, sleeping');
85
+ await sleep(1);
86
+ }
87
+
88
+ if (params.displayUpdate) {
89
+ params.displayUpdate.style.display = '';
90
+ }
91
+
92
+ // resolve when we have a result
93
+ console.log(params);
94
+ speaker.result = await speaker.ac.startCalibration(
95
+ stream,
96
+ params.gainValues,
97
+ params.ICalib,
98
+ params.knownIR,
99
+ params.microphoneName,
100
+ params.calibrateSoundCheck,
101
+ params.isSmartPhone,
102
+ params.calibrateSoundBurstDb,
103
+ params.calibrateSoundBurstFilteredExtraDb,
104
+ params.calibrateSoundBurstLevelReTBool,
105
+ params.calibrateSoundBurstUses1000HzGainBool,
106
+ params.calibrateSoundBurstRepeats,
107
+ params.calibrateSoundBurstSec,
108
+ params.calibrateSoundBurstsWarmup,
109
+ params.calibrateSoundHz,
110
+ params.calibrateSoundIRSec,
111
+ params.calibrateSoundIIRSec,
112
+ params.calibrateSoundIIRPhase,
113
+ params.calibrateSound1000HzPreSec,
114
+ params.calibrateSound1000HzSec,
115
+ params.calibrateSound1000HzPostSec,
116
+ params.calibrateSoundBackgroundSecs,
117
+ params.calibrateSoundSmoothOctaves,
118
+ params.calibrateSoundPowerBinDesiredSec,
119
+ params.calibrateSoundPowerDbSDToleratedDb,
120
+ params.micManufacturer,
121
+ params.micSerialNumber,
122
+ params.micModelNumber,
123
+ params.micModelName,
124
+ params.calibrateMicrophonesBool,
125
+ params.authorEmails,
126
+ params.webAudioDeviceNames,
127
+ params.IDsToSaveInSoundProfileLibrary,
128
+ params.restartButton,
129
+ params.reminder,
130
+ params.calibrateSoundLimit
131
+ );
132
+ speaker.#removeUIElems();
133
+ resolve(speaker.result);
134
+ });
135
+ // if we do not receive a result within the timeout, reject
136
+ setTimeout(() => {
137
+ reject(
138
+ new CalibrationTimedOutError(
139
+ `Calibration failed to produce a result after ${
140
+ timeOut / 1000
141
+ } seconds. Please try again.`
142
+ )
143
+ );
144
+ }, timeOut);
145
+ });
146
+ });
147
+ };
148
+
149
+ static testIIR = async (params, CalibratorInstance, IIR, timeOut = 180000) => {
150
+ window.speaker = new Speaker(params, CalibratorInstance);
151
+ const {speaker} = window;
152
+
153
+ // wrap the calibration process in a promise so we can await it
154
+ return new Promise((resolve, reject) => {
155
+ // when a call is received
156
+ speaker.peer.on('call', async call => {
157
+ // Answer the call (one way)
158
+ call.answer();
159
+ speaker.#removeUIElems();
160
+ speaker.#showSpinner();
161
+ speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));
162
+ // when we start receiving audio
163
+ call.on('stream', async stream => {
164
+ window.localStream = stream;
165
+ window.localAudio.srcObject = stream;
166
+ window.localAudio.autoplay = false;
167
+
168
+ // if the sinkSamplingRate is not set sleep
169
+ while (!speaker.ac.sampleRatesSet()) {
170
+ console.log('SinkSamplingRate is undefined, sleeping');
171
+ await sleep(1);
172
+ }
173
+ // resolve when we have a result
174
+ speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);
175
+ speaker.#removeUIElems();
176
+ resolve(speaker.result);
177
+ });
178
+ // if we do not receive a result within the timeout, reject
179
+ setTimeout(() => {
180
+ reject(
181
+ new CalibrationTimedOutError(
182
+ `Calibration failed to produce a result after ${
183
+ timeOut / 1000
184
+ } seconds. Please try again.`
185
+ )
186
+ );
187
+ }, timeOut);
188
+ });
189
+ });
190
+ };
191
+
192
+ /**
193
+ * Called after the peer conncection has been opened.
194
+ * Generates a QR code for the connection and displays it.
195
+ *
196
+ * @private
197
+ * @example
198
+ */
199
+ #showQRCode = () => {
200
+ // Get query string, the URL parameters to specify a Listener
201
+ const queryStringParameters = {
202
+ speakerPeerId: this.peer.id,
203
+ isSmartPhone: this.isSmartPhone,
204
+ calibrateSoundHz: this.calibrateSoundHz,
205
+ calibrateSoundSamplingDesiredBits: this.calibrateSoundSamplingDesiredBits,
206
+ lang: this.language,
207
+ };
208
+ const queryString = this.queryStringFromObject(queryStringParameters);
209
+ const uri = this.siteUrl + queryString;
210
+ if (this.isSmartPhone) {
211
+ // Display QR code for the participant to scan
212
+ const qrCanvas = document.createElement('canvas');
213
+ qrCanvas.setAttribute('id', 'qrCanvas');
214
+ console.log(uri);
215
+ QRCode.toCanvas(qrCanvas, uri, error => {
216
+ if (error) console.error(error);
217
+ });
218
+ const qrImage = new Image(400, 400);
219
+ qrImage.setAttribute('id', 'compatibilityCheckQRImage');
220
+ qrImage.style.zIndex = Infinity;
221
+ qrImage.style.width = 400;
222
+ qrImage.style.height = 400;
223
+ qrImage.style.aspectRatio = 1;
224
+ qrImage.src = qrCanvas.toDataURL();
225
+ qrImage.style.maxHeight = '150px';
226
+ qrImage.style.maxWidth = '150px';
227
+ document.getElementById(this.targetElement).appendChild(qrImage);
228
+ } else {
229
+ // show the link to the user
230
+ // If specified HTML Id is available, show QR code there
231
+ if (document.getElementById(this.targetElement)) {
232
+ // const linkTag = document.createElement('a');
233
+ // linkTag.setAttribute('href', uri);
234
+ // linkTag.innerHTML = 'Click here to start the calibration';
235
+ // linkTag.target = '_blank';
236
+ // document.getElementById(this.targetElement).appendChild(linkTag);
237
+ // document.getElementById(this.targetElement).appendChild(qrCanvas);
238
+
239
+ const proceedButton = document.createElement('button');
240
+ proceedButton.setAttribute('id', 'calibrationProceedButton');
241
+ proceedButton.setAttribute('class', 'btn btn-success');
242
+ proceedButton.innerHTML = 'Proceed';
243
+ proceedButton.onclick = () => {
244
+ // open the link in a new tab
245
+ window.open(uri, '_blank');
246
+ // remove the button
247
+ document.getElementById('calibrationProceedButton').remove();
248
+ };
249
+ document.getElementById(this.targetElement).appendChild(proceedButton);
250
+ }
251
+ }
252
+ // or just print it to console
253
+ console.log('TEST: Peer reachable at: ', uri);
254
+ };
255
+
256
+ #showSpinner = () => {
257
+ const spinner = document.createElement('div');
258
+ spinner.className = 'spinner-border ml-auto';
259
+ spinner.role = 'status';
260
+ spinner.ariaHidden = 'true';
261
+ document.getElementById(this.targetElement).appendChild(spinner);
262
+
263
+ // clear instructionDisplay
264
+ const soundMessage = document.getElementById(this.soundMessageId);
265
+ soundMessage.innerHTML = '';
266
+ soundMessage.style.display = 'none';
267
+ const instructionDisplay = document.getElementById(this.instructionDisplayId);
268
+ const background = document.getElementById('background'); // todo: get background id from params
269
+ const subtitle = document.getElementById(this.soundSubtitleId);
270
+ if (subtitle) {
271
+ subtitle.innerHTML = '';
272
+ }
273
+ if (instructionDisplay) {
274
+ instructionDisplay.innerHTML = '';
275
+ instructionDisplay.style.whiteSpace = 'nowrap';
276
+ instructionDisplay.style.fontWeight = 'bold';
277
+ instructionDisplay.style.width = 'fit-content';
278
+ instructionDisplay.innerHTML = phrases.RC_soundRecording[this.language];
279
+ let fontSize = 100;
280
+ instructionDisplay.style.fontSize = fontSize + 'px';
281
+ while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {
282
+ fontSize--;
283
+ instructionDisplay.style.fontSize = fontSize + 'px';
284
+ }
285
+ // const p = document.createElement('p');
286
+ // // font size
287
+ // p.style.fontSize = '1.1rem';
288
+ // p.style.fontWeight = 'normal';
289
+ // p.style.paddingTop = '20px';
290
+ // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];
291
+ // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);
292
+ // instructionDisplay.appendChild(p);
293
+ }
294
+
295
+ const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);
296
+ if (timeToCalibrateDisplay) {
297
+ const timeToCalibrateText = phrases.RC_howLongToCalibrate[this.language];
298
+ timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);
299
+ timeToCalibrateDisplay.style.fontWeight = 'normal';
300
+ timeToCalibrateDisplay.style.fontSize = '1rem';
301
+ // timeToCalibrateDisplay.style.paddingTop = '20px';
302
+ }
303
+
304
+ // Update title - titleDisplayId
305
+ const titleDisplay = document.getElementById(this.titleDisplayId);
306
+ if (titleDisplay) {
307
+ // if (this.isParticipant) {
308
+ // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');
309
+ // } else if (this.isSmartPhone) {
310
+ // if (this.isLoudspeakerCalibration) {
311
+ // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');
312
+ // } else {
313
+ // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
314
+ // }
315
+ // } else {
316
+ // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
317
+ // }
318
+ if (this.isLoudspeakerCalibration) {
319
+ if (this.isParticipant) {
320
+ titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');
321
+ } else if (this.isSmartPhone) {
322
+ titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');
323
+ } else {
324
+ titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
325
+ }
326
+ } else {
327
+ if (this.isSmartPhone) {
328
+ titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');
329
+ } else {
330
+ titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');
331
+ }
332
+ }
333
+ }
334
+ };
335
+
336
+ #removeUIElems = () => {
337
+ const parent = document.getElementById(this.targetElement);
338
+ while (parent.firstChild) {
339
+ parent.firstChild.remove();
340
+ }
341
+ };
342
+
343
+ /**
344
+ * Called when the peer connection is opened.
345
+ * Saves the peer id and calls the QR code generator.
346
+ *
347
+ * @param peerId - The peer id of the peer connection.
348
+ * @param id
349
+ * @private
350
+ * @example
351
+ */
352
+ #onPeerOpen = id => {
353
+ // Workaround for peer.reconnect deleting previous id
354
+ if (id === null) {
355
+ console.error('Received null id from peer open');
356
+ this.peer.id = this.lastPeerId;
357
+ } else {
358
+ this.lastPeerId = this.peer.id;
359
+ }
360
+
361
+ if (id !== this.peer.id) {
362
+ console.warn('DEBUG Check you assumption that id === this.peer.id');
363
+ }
364
+
365
+ this.#showQRCode();
366
+ };
367
+
368
+ /**
369
+ * Called when the peer connection is established.
370
+ * Enforces a single connection.
371
+ *
372
+ * @param connection - The connection object.
373
+ * @private
374
+ * @example
375
+ */
376
+ #onPeerConnection = connection => {
377
+ // Allow only a single connection
378
+ if (this.conn && this.conn.open) {
379
+ connection.on('open', () => {
380
+ connection.send('Already connected to another client');
381
+ setTimeout(() => {
382
+ connection.close();
383
+ }, 500);
384
+ });
385
+ return;
386
+ }
387
+
388
+ this.conn = connection;
389
+ console.log('Connected to: ', this.conn.peer);
390
+ this.#ready();
391
+ };
392
+
393
+ /**
394
+ * Called when the peer connection is closed.
395
+ *
396
+ * @private
397
+ * @example
398
+ */
399
+ onPeerClose = () => {
400
+ this.conn = null;
401
+ console.log('Connection destroyed');
402
+ };
403
+
404
+ static closeConnection = () => {
405
+ this.conn = null;
406
+ console.log('Connection destroyed');
407
+ };
408
+
409
+ /**
410
+ * Called when the peer connection is disconnected.
411
+ * Attempts to reconnect.
412
+ *
413
+ * @private
414
+ * @example
415
+ */
416
+ #onPeerDisconnected = () => {
417
+ console.log('Connection lost. Please reconnect');
418
+
419
+ // Workaround for peer.reconnect deleting previous id
420
+ this.peer.id = this.lastPeerId;
421
+ // eslint-disable-next-line no-underscore-dangle
422
+ this.peer._lastServerId = this.lastPeerId;
423
+ this.peer.reconnect();
424
+ };
425
+
426
+ /**
427
+ * Called when the peer connection encounters an error.
428
+ *
429
+ * @param error
430
+ * @private
431
+ * @example
432
+ */
433
+ #onPeerError = error => {
434
+ // TODO: check if this function is needed or not
435
+ console.error(error);
436
+ };
437
+
438
+ /**
439
+ * Called when data is received from the peer connection.
440
+ *
441
+ * @param data
442
+ * @private
443
+ * @example
444
+ */
445
+ #onIncomingData = data => {
446
+ // enforce object type
447
+ if (
448
+ !Object.prototype.hasOwnProperty.call(data, 'name') ||
449
+ !Object.prototype.hasOwnProperty.call(data, 'payload')
450
+ ) {
451
+ console.error('Received malformed data: ', data);
452
+ return;
453
+ }
454
+
455
+ switch (data.name) {
456
+ case 'samplingRate':
457
+ this.ac.setSamplingRates(data.payload);
458
+ break;
459
+ case 'sampleSize':
460
+ this.ac.setSampleSize(data.payload);
461
+ break;
462
+ case 'deviceType':
463
+ this.ac.setDeviceType(data.payload);
464
+ break;
465
+ case 'deviceName':
466
+ this.ac.setDeviceName(data.payload);
467
+ break;
468
+ case 'flags':
469
+ //this.ac.setDeviceName(data.payload);
470
+ console.log('FLAGS');
471
+ console.log(data.payload);
472
+ this.ac.setFlags(data.payload);
473
+ break;
474
+ case 'deviceInfo':
475
+ this.ac.setDeviceInfo(data.payload);
476
+ console.log('Received device info from listener: ', data.payload);
477
+ break;
478
+ case UnsupportedDeviceError.name:
479
+ case MissingSpeakerIdError.name:
480
+ throw data.payload;
481
+ break;
482
+ default:
483
+ break;
484
+ }
485
+ };
486
+
487
+ /**
488
+ * Called when the peer connection is #ready.
489
+ *
490
+ * @private
491
+ * @example
492
+ */
493
+ #ready = () => {
494
+ // Perform callback with data
495
+ this.conn.on('data', this.#onIncomingData);
496
+ this.conn.on('close', () => {
497
+ console.log('Connection reset<br>Awaiting connection...');
498
+ this.conn = null;
499
+ });
500
+ };
501
+
502
+ /** .
503
+ * .
504
+ * .
505
+ * Debug method for downloading the recorded audio
506
+ *
507
+ * @public
508
+ * @example
509
+ */
510
+ downloadData = () => {
511
+ this.ac.downloadData();
512
+ };
513
+
514
+ repeatCalibration = async (params, stream, CalibratorInstance) => {
515
+ this.ac = CalibratorInstance;
516
+ this.#removeUIElems();
517
+ this.#showSpinner();
518
+
519
+ console.log('This is a repeat');
520
+ // wrap the calibration process in a promise so we can await it
521
+ return new Promise(async (resolve, reject) => {
522
+ const result = await this.ac.startCalibration(
523
+ stream,
524
+ params.gainValues,
525
+ params.ICalib,
526
+ params.knownIR,
527
+ params.microphoneName,
528
+ params.calibrateSoundCheck,
529
+ params.isSmartPhone,
530
+ params.calibrateSoundBurstDb,
531
+ params.calibrateSoundBurstFilteredExtraDb,
532
+ params.calibrateSoundBurstLevelReTBool,
533
+ params.calibrateSoundBurstUses1000HzGainBool,
534
+ params.calibrateSoundBurstRepeats,
535
+ params.calibrateSoundBurstSec,
536
+ params.calibrateSoundBurstsWarmup,
537
+ params.calibrateSoundHz,
538
+ params.calibrateSoundIRSec,
539
+ params.calibrateSoundIIRSec,
540
+ params.params.calibrateSoundIIRPhase,
541
+ params.calibrateSound1000HzPreSec,
542
+ params.calibrateSound1000HzSec,
543
+ params.calibrateSound1000HzPostSec,
544
+ params.calibrateSoundBackgroundSecs,
545
+ params.calibrateSoundSmoothOctaves,
546
+ params.calibrateSoundPowerBinDesiredSec,
547
+ params.calibrateSoundPowerDbSDToleratedDb,
548
+ params.micManufacturer,
549
+ params.micSerialNumber,
550
+ params.micModelNumber,
551
+ params.micModelName,
552
+ params.calibrateMicrophonesBool,
553
+ params.authorEmails,
554
+ params.webAudioDeviceNames,
555
+ params.IDsToSaveInSoundProfileLibrary,
556
+ params.restartButton,
557
+ params.reminder,
558
+ params.calibrateSoundLimit
559
+ );
560
+ this.#removeUIElems();
561
+ resolve(result);
562
+ });
563
+ };
564
+ }
565
+
566
+ /*
567
+ Referenced links:
568
+ https://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676
569
+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
570
+ https://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]
571
+ */
572
+
573
+ export default Speaker;