speaker-calibration 2.2.178 → 2.2.180

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speaker-calibration",
3
- "version": "2.2.178",
3
+ "version": "2.2.180",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -40,6 +40,7 @@
40
40
  "peerjs": "^1.3.2",
41
41
  "qrcode": "^1.4.4",
42
42
  "socket.io-client": "^4.4.1",
43
+ "sweetalert2": "^11.14.0",
43
44
  "uuid": "^8.3.2",
44
45
  "xlsx": "^0.18.5"
45
46
  },
@@ -1,6 +1,10 @@
1
1
  import QRCode from 'qrcode';
2
2
  import AudioPeer from './audioPeer';
3
- import {sleep} from '../utils';
3
+ import {
4
+ sleep,
5
+ formatLineBreak,
6
+ createAndShowPopup
7
+ } from '../utils';
4
8
  import {
5
9
  UnsupportedDeviceError,
6
10
  MissingSpeakerIdError,
@@ -320,14 +324,30 @@ await fetch(url, options)
320
324
  return response.json(); // Parse the JSON response
321
325
  })
322
326
  .then(data => {
323
- explanation.innerHTML = phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language]
327
+ explanation.innerHTML =formatLineBreak(
328
+ phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language]
324
329
  .replace("xxx", `<b style="user-select: text">${data.shortURL}</b>`)
325
- .replace("XXX", `<b style="user-select: text">${data.shortURL}</b>`);
330
+ .replace("XXX", `<b style="user-select: text">${data.shortURL}</b>`),
331
+ phrases.RC_checkInternetConnection[this.language]
332
+ );
333
+ const checkConnection = document.createElement('a');
334
+ checkConnection.id = 'check-connection';
335
+ checkConnection.href = '#';
336
+ checkConnection.innerHTML = 'check the phone\'s internet connection';
337
+ const lang = this.language;
338
+ checkConnection.addEventListener('click', function(event,) {
339
+ console.log('clicked');
340
+ event.preventDefault(); // Prevent the default link action
341
+ createAndShowPopup(lang);
342
+ });
343
+ explanation.querySelector('a#check-connection').replaceWith(checkConnection);
326
344
  })
327
345
  .catch(error => {
328
346
  console.error('Error:', error.message); // Handle errors
329
347
  });
330
348
 
349
+
350
+
331
351
 
332
352
 
333
353
  const qrImage = new Image(400, 400);
package/src/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import Swal from "sweetalert2";
2
+ import {phrases} from '../dist/example/i18n.js';
1
3
  /** .
2
4
  * .
3
5
  * .
@@ -132,4 +134,72 @@ function interpolate(x, x0, x1, y0, y1) {
132
134
  return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
133
135
  }
134
136
 
137
+ export const formatLineBreak =(inputStr,checkInternetConnection) => {
138
+ let finalStr = inputStr
139
+ .replace(/\n/g, '<br>')
140
+ .replace('LLL',
141
+ `<a href="#" id="check-connection">${checkInternetConnection}</a>`);
142
+
143
+ console.log(finalStr);
144
+
145
+ return finalStr;
146
+ }
147
+
148
+
149
+
150
+ export const createAndShowPopup = (lang) => {
151
+ console.log(`
152
+ <div style="text-align: left;">
153
+ ${convertAsterisksToList(phrases.RC_NeedInternetConnectedPhone[lang].replace(/\n/g, '<br>'))}
154
+ </div>
155
+ <div class="col-3" style="margin-top:10px;">
156
+ <button id="okaybtn" class="btn btn-lg btn-dark">
157
+ ${phrases.EE_ok[lang]}
158
+ </button>
159
+ </div>`);
160
+ Swal.fire({
161
+ html: `
162
+ <div style="text-align: left;">
163
+ ${convertAsterisksToList(phrases.RC_NeedInternetConnectedPhone[lang].replace(/\n/g, '<br>'))}
164
+ </div>
165
+ <div class="col-3" style="margin-top:10px;">
166
+ <button id="okaybtn" class="btn btn-lg btn-dark">
167
+ ${phrases.EE_ok[lang]}
168
+ </button>
169
+ </div>`,
170
+ showConfirmButton: false,
171
+ position: 'bottom',
172
+ width: "40%",
173
+ customClass: {
174
+ container:'no-background',
175
+ },
176
+ showClass: {
177
+ popup: "fade-in",
178
+ },
179
+ hideClass: {
180
+ popup: "",
181
+ },
182
+ didOpen: () => {
183
+ const okayBtn = document.getElementById("okaybtn");
184
+ okayBtn.style.display = "flex";
185
+ okayBtn.addEventListener('click', () => {
186
+ Swal.close(); // Close the Swal popup
187
+ });
188
+ }
189
+ });
190
+ };
191
+
192
+ export function convertAsterisksToList(content) {
193
+ // Replace * with <li> and convert line breaks to </li><li>
194
+ console.log(content);
195
+ let result = content
196
+ .replace(/\* (.*?)(<br>|$)/g, '<li>$1</li>')
197
+ .replace(/(<li>)(<\/li>)\s*$/, '') // Remove trailing </li>
198
+ .replace('<li>', '<ul style="padding-left:40px"> <br> <li>');
199
+ result = result.replace('</li>5', '</li></ul>5');
200
+ return result;
201
+ }
202
+
203
+
204
+
135
205
  export {sleep, saveToCSV, saveToJSON, csvToArray,findMinValue,findMaxValue, standardDeviation, interpolate};