speaker-calibration 2.2.215 → 2.2.216
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 +1515 -1512
- package/dist/listener.js +2 -2
- package/dist/main.js +2 -2
- package/package.json +1 -1
- package/src/peer-connection/listener.js +9 -6
- package/src/peer-connection/speaker.js +104 -83
|
@@ -286,7 +286,6 @@ class Speaker extends AudioPeer {
|
|
|
286
286
|
*/
|
|
287
287
|
|
|
288
288
|
#showQRCode = async () => {
|
|
289
|
-
// Get query string, the URL parameters to specify a Listener
|
|
290
289
|
const queryStringParameters = {
|
|
291
290
|
speakerPeerId: this.peer.id,
|
|
292
291
|
sp: this.isSmartPhone,
|
|
@@ -297,92 +296,106 @@ class Speaker extends AudioPeer {
|
|
|
297
296
|
};
|
|
298
297
|
const queryString = this.queryStringFromObject(queryStringParameters);
|
|
299
298
|
this.uri = this.siteUrl + queryString;
|
|
299
|
+
|
|
300
300
|
if (this.isSmartPhone) {
|
|
301
|
-
//
|
|
302
|
-
// Display QR code for the participant to scan
|
|
301
|
+
// Generate QR code
|
|
303
302
|
const qrCanvas = document.createElement('canvas');
|
|
304
303
|
qrCanvas.setAttribute('id', 'qrCanvas');
|
|
305
304
|
QRCode.toCanvas(qrCanvas, this.uri, error => {
|
|
306
305
|
if (error) console.error(error);
|
|
307
306
|
});
|
|
308
|
-
const explanation = document.createElement('h2');
|
|
309
|
-
explanation.id = 'skipQRExplanation';
|
|
310
|
-
explanation.style = `
|
|
311
|
-
user-select: text;
|
|
312
|
-
margin-top: 9px;
|
|
313
|
-
font-size: 1.1rem;
|
|
314
|
-
`;
|
|
315
|
-
// Define the URL and options for the request
|
|
316
|
-
const url = 'https://api.short.io/links/public';
|
|
317
|
-
const options = {
|
|
318
|
-
method: 'POST',
|
|
319
|
-
headers: {
|
|
320
|
-
Accept: 'application/json',
|
|
321
|
-
'Content-Type': 'application/json',
|
|
322
|
-
Authorization: 'pk_fysLKGj3legZz4XZ',
|
|
323
|
-
},
|
|
324
|
-
body: JSON.stringify({
|
|
325
|
-
domain: 'listeners.link', // Ensure this domain is valid for your account
|
|
326
|
-
originalURL: this.uri,
|
|
327
|
-
}),
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// Make the request using fetch
|
|
331
|
-
await fetch(url, options)
|
|
332
|
-
.then(response => {
|
|
333
|
-
if (!response.ok) {
|
|
334
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
335
|
-
}
|
|
336
|
-
return response.json(); // Parse the JSON response
|
|
337
|
-
})
|
|
338
|
-
.then(data => {
|
|
339
|
-
explanation.innerHTML = formatLineBreak(
|
|
340
|
-
this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language]
|
|
341
|
-
.replace('xxx', `<b style="user-select: text">${data.shortURL}</b>`)
|
|
342
|
-
.replace('XXX', `<b style="user-select: text">${data.shortURL}</b>`),
|
|
343
|
-
this.phrases.RC_checkInternetConnection[this.language]
|
|
344
|
-
);
|
|
345
|
-
const checkConnection = document.createElement('a');
|
|
346
|
-
checkConnection.id = 'check-connection';
|
|
347
|
-
checkConnection.href = '#';
|
|
348
|
-
checkConnection.innerHTML = "check the phone's internet connection";
|
|
349
|
-
const lang = this.language;
|
|
350
|
-
const phrases = this.phrases;
|
|
351
|
-
checkConnection.addEventListener('click', function (event) {
|
|
352
|
-
console.log('clicked');
|
|
353
|
-
event.preventDefault(); // Prevent the default link action
|
|
354
|
-
createAndShowPopup(lang, phrases);
|
|
355
|
-
});
|
|
356
|
-
explanation.querySelector('a#check-connection').replaceWith(checkConnection);
|
|
357
|
-
})
|
|
358
|
-
.catch(error => {
|
|
359
|
-
console.error('Error:', error.message); // Handle errors
|
|
360
|
-
});
|
|
361
307
|
|
|
362
|
-
|
|
308
|
+
// Create QR image
|
|
309
|
+
const qrImage = new Image();
|
|
363
310
|
qrImage.setAttribute('id', 'compatibilityCheckQRImage');
|
|
364
311
|
qrImage.style.zIndex = Infinity;
|
|
365
|
-
qrImage.style.
|
|
366
|
-
qrImage.style.
|
|
312
|
+
qrImage.style.height = '150px';
|
|
313
|
+
qrImage.style.width = '150px';
|
|
314
|
+
qrImage.style.margin = '-10px';
|
|
367
315
|
qrImage.style.aspectRatio = 1;
|
|
368
316
|
qrImage.src = qrCanvas.toDataURL();
|
|
369
|
-
qrImage.style.maxHeight = '150px';
|
|
370
|
-
qrImage.style.maxWidth = '150px';
|
|
371
|
-
|
|
372
317
|
this.qrImage = qrImage;
|
|
373
318
|
|
|
319
|
+
// Get shortened URL
|
|
320
|
+
let shortURL = '';
|
|
321
|
+
try {
|
|
322
|
+
const response = await fetch('https://api.short.io/links/public', {
|
|
323
|
+
method: 'POST',
|
|
324
|
+
headers: {
|
|
325
|
+
Accept: 'application/json',
|
|
326
|
+
'Content-Type': 'application/json',
|
|
327
|
+
Authorization: 'pk_fysLKGj3legZz4XZ',
|
|
328
|
+
},
|
|
329
|
+
body: JSON.stringify({
|
|
330
|
+
domain: 'listeners.link',
|
|
331
|
+
originalURL: this.uri,
|
|
332
|
+
}),
|
|
333
|
+
});
|
|
334
|
+
if (!response.ok) {
|
|
335
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
336
|
+
}
|
|
337
|
+
const data = await response.json();
|
|
338
|
+
shortURL = data.shortURL;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error('Error:', error.message);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Main container with 3 columns
|
|
374
344
|
const container = document.createElement('div');
|
|
375
345
|
container.style.display = 'flex';
|
|
376
|
-
container.style.
|
|
377
|
-
container.style.
|
|
346
|
+
container.style.alignItems = 'flex-start';
|
|
347
|
+
container.style.paddingTop = '0';
|
|
378
348
|
container.id = 'skipQRContainer';
|
|
379
|
-
container.appendChild(qrImage);
|
|
380
|
-
container.appendChild(explanation);
|
|
381
|
-
container.appendChild(this.buttonsContainer);
|
|
382
|
-
const qrContainer = document.createElement('div');
|
|
383
|
-
qrContainer.appendChild(container);
|
|
384
349
|
|
|
385
|
-
|
|
350
|
+
// Column 1: QR Code
|
|
351
|
+
const qrColumn = document.createElement('div');
|
|
352
|
+
qrColumn.style.flex = '0 0 auto';
|
|
353
|
+
qrColumn.appendChild(qrImage);
|
|
354
|
+
|
|
355
|
+
// Column 2: Explanation Text
|
|
356
|
+
const textColumn = document.createElement('div');
|
|
357
|
+
textColumn.style.flex = '1';
|
|
358
|
+
textColumn.style.padding = '0 20px';
|
|
359
|
+
textColumn.style.maxWidth = '560px';
|
|
360
|
+
|
|
361
|
+
const explanation = document.createElement('h2');
|
|
362
|
+
explanation.style.fontSize = '1.1rem';
|
|
363
|
+
explanation.id = 'skipQRExplanation';
|
|
364
|
+
explanation.style.margin = '0';
|
|
365
|
+
explanation.style.textAlign = 'left';
|
|
366
|
+
explanation.innerHTML = formatLineBreak(
|
|
367
|
+
this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language]
|
|
368
|
+
.replace('xxx', `<b style="user-select: text">${shortURL}</b>`)
|
|
369
|
+
.replace('XXX', `<b style="user-select: text">${shortURL}</b>`),
|
|
370
|
+
this.phrases.RC_checkInternetConnection[this.language]
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const checkConnection = document.createElement('a');
|
|
374
|
+
checkConnection.id = 'check-connection';
|
|
375
|
+
checkConnection.href = '#';
|
|
376
|
+
checkConnection.innerHTML = "check the phone's internet connection";
|
|
377
|
+
checkConnection.addEventListener('click', function (event) {
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
createAndShowPopup(this.language, this.phrases);
|
|
380
|
+
});
|
|
381
|
+
explanation.querySelector('a#check-connection').replaceWith(checkConnection);
|
|
382
|
+
textColumn.appendChild(explanation);
|
|
383
|
+
|
|
384
|
+
// Column 3: Buttons
|
|
385
|
+
const buttonColumn = document.createElement('div');
|
|
386
|
+
buttonColumn.style.display = 'flex';
|
|
387
|
+
buttonColumn.style.flexDirection = 'column';
|
|
388
|
+
buttonColumn.style.gap = '10px';
|
|
389
|
+
buttonColumn.style.flex = '0 0 auto';
|
|
390
|
+
buttonColumn.style.alignItems = 'flex-end';
|
|
391
|
+
buttonColumn.appendChild(this.buttonsContainer);
|
|
392
|
+
|
|
393
|
+
// Assemble the columns
|
|
394
|
+
container.appendChild(qrColumn);
|
|
395
|
+
container.appendChild(textColumn);
|
|
396
|
+
container.appendChild(buttonColumn);
|
|
397
|
+
|
|
398
|
+
document.getElementById(this.targetElement).appendChild(container);
|
|
386
399
|
} else {
|
|
387
400
|
// show the link to the user
|
|
388
401
|
// If specified HTML Id is available, show QR code there
|
|
@@ -510,15 +523,19 @@ class Speaker extends AudioPeer {
|
|
|
510
523
|
*/
|
|
511
524
|
#onPeerOpen = id => {
|
|
512
525
|
// Workaround for peer.reconnect deleting previous id
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
526
|
+
try {
|
|
527
|
+
if (id === null) {
|
|
528
|
+
console.error('Received null id from peer open');
|
|
529
|
+
this.peer.id = this.lastPeerId;
|
|
530
|
+
} else {
|
|
531
|
+
this.lastPeerId = this.peer.id;
|
|
532
|
+
}
|
|
519
533
|
|
|
520
|
-
|
|
521
|
-
|
|
534
|
+
if (id !== this.peer.id) {
|
|
535
|
+
console.warn('DEBUG Check you assumption that id === this.peer.id');
|
|
536
|
+
}
|
|
537
|
+
} catch (error) {
|
|
538
|
+
console.error('Error in #onPeerOpen: ', error);
|
|
522
539
|
}
|
|
523
540
|
|
|
524
541
|
this.#showQRCode();
|
|
@@ -575,11 +592,15 @@ class Speaker extends AudioPeer {
|
|
|
575
592
|
#onPeerDisconnected = () => {
|
|
576
593
|
console.log('Connection lost. Please reconnect');
|
|
577
594
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
595
|
+
try {
|
|
596
|
+
// Workaround for peer.reconnect deleting previous id
|
|
597
|
+
this.peer.id = this.lastPeerId;
|
|
598
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
599
|
+
this.peer._lastServerId = this.lastPeerId;
|
|
600
|
+
this.peer.reconnect();
|
|
601
|
+
} catch (error) {
|
|
602
|
+
console.error('Error in #onPeerDisconnected: ', error);
|
|
603
|
+
}
|
|
583
604
|
};
|
|
584
605
|
|
|
585
606
|
/**
|