speaker-calibration 2.2.218 → 2.2.219

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.
@@ -45,6 +45,7 @@ class Speaker extends AudioPeer {
45
45
  this.deviceId = params?.micrpohoneIdFromWebAudioApi ?? '';
46
46
  this.buttonsContainer = params?.buttonsContainer ?? document.createElement('div');
47
47
  this.phrases = params?.phrases ?? {};
48
+ this.permissionStatus = 'pending';
48
49
 
49
50
  /* Set up callbacks that handle any events related to our peer object. */
50
51
  }
@@ -138,10 +139,19 @@ class Speaker extends AudioPeer {
138
139
  await speaker.initPeer();
139
140
  // wrap the calibration process in a promise so we can await it
140
141
  return new Promise((resolve, reject) => {
142
+ // Add a permission check handler
143
+ const permissionCheckInterval = setInterval(() => {
144
+ if (speaker.permissionStatus === 'error' || speaker.permissionStatus === 'denied') {
145
+ clearInterval(permissionCheckInterval);
146
+ speaker.#removeUIElems();
147
+ resolve('permission denied');
148
+ }
149
+ }, 100);
150
+
141
151
  // when a call is received
142
152
  speaker.peer.on('call', async call => {
143
- // Answer the call (one way)
144
-
153
+ clearInterval(permissionCheckInterval); // Clear interval when call is received
154
+ // Rest of the existing call handling code...
145
155
  call.answer();
146
156
  speaker.#removeUIElems();
147
157
  speaker.#showSpinner();
@@ -218,6 +228,7 @@ class Speaker extends AudioPeer {
218
228
  });
219
229
  // if we do not receive a result within the timeout, reject
220
230
  setTimeout(() => {
231
+ clearInterval(permissionCheckInterval);
221
232
  reject(
222
233
  new CalibrationTimedOutError(
223
234
  `Calibration failed to produce a result after ${
@@ -657,6 +668,20 @@ class Speaker extends AudioPeer {
657
668
  this.ac.setDeviceInfo(data.payload);
658
669
  console.log('Received device info from listener: ', data.payload);
659
670
  break;
671
+ case 'permissionStatus':
672
+ console.log('Received permission status from listener: ', data.payload);
673
+ if (data.payload.type === 'error') {
674
+ this.permissionStatus = 'error';
675
+ this.ac.setPermissionStatus('error');
676
+ } else if (data.payload.type === 'denied') {
677
+ this.permissionStatus = 'denied';
678
+ this.ac.setPermissionStatus('denied');
679
+ } else if (data.payload.type === 'granted') {
680
+ this.permissionStatus = 'granted';
681
+ this.ac.setPermissionStatus('granted');
682
+ console.log('Permission granted');
683
+ }
684
+ break;
660
685
  case UnsupportedDeviceError.name:
661
686
  case MissingSpeakerIdError.name:
662
687
  throw data.payload;
@@ -700,59 +725,77 @@ class Speaker extends AudioPeer {
700
725
 
701
726
  console.log('This is a repeat');
702
727
  // wrap the calibration process in a promise so we can await it
703
- return new Promise(async (resolve, reject) => {
704
- const result = await this.ac.startCalibration(
705
- stream,
706
- params.gainValues,
707
- params.ICalib,
708
- params.knownIR,
709
- params.microphoneName,
710
- params.calibrateSoundCheck,
711
- params.isSmartPhone,
712
- params.calibrateSoundBurstDb,
713
- params.calibrateSoundBurstFilteredExtraDb,
714
- params.calibrateSoundBurstLevelReTBool,
715
- params.calibrateSoundBurstUses1000HzGainBool,
716
- params.calibrateSoundBurstRepeats,
717
- params.calibrateSoundBurstSec,
718
- params._calibrateSoundBurstPreSec,
719
- params._calibrateSoundBurstPostSec,
720
- params.calibrateSoundHz,
721
- params.calibrateSoundIRSec,
722
- params.calibrateSoundIIRSec,
723
- params.calibrateSoundIIRPhase,
724
- params.calibrateSound1000HzPreSec,
725
- params.calibrateSound1000HzSec,
726
- params.calibrateSound1000HzPostSec,
727
- params.calibrateSoundBackgroundSecs,
728
- params.calibrateSoundSmoothOctaves,
729
- params.calibrateSoundSmoothMinBandwidthHz,
730
- params.calibrateSoundPowerBinDesiredSec,
731
- params.calibrateSoundPowerDbSDToleratedDb,
732
- params.calibrateSoundTaperSec,
733
- params.micManufacturer,
734
- params.micSerialNumber,
735
- params.micModelNumber,
736
- params.micModelName,
737
- params.calibrateMicrophonesBool,
738
- params.authorEmails,
739
- params.webAudioDeviceNames,
740
- params.IDsToSaveInSoundProfileLibrary,
741
- params.restartButton,
742
- params.reminder,
743
- params.calibrateSoundLimit,
744
- params.calibrateSoundBurstNormalizeBy1000HzGainBool,
745
- params.calibrateSoundBurstScalarDB,
746
- params.calibrateSound1000HzMaxSD_dB,
747
- params._calibrateSoundBurstMaxSD_dB,
748
- params.calibrateSoundSamplingDesiredBits,
749
- params.language,
750
- params.loudspeakerModelName,
751
- params.phrases,
752
- params.soundSubtitleId
753
- );
754
- this.#removeUIElems();
755
- resolve(result);
728
+ return new Promise((resolve, reject) => {
729
+ // Add a permission check handler
730
+ const permissionCheckInterval = setInterval(() => {
731
+ if (this.permissionStatus === 'error' || this.permissionStatus === 'denied') {
732
+ clearInterval(permissionCheckInterval);
733
+ this.#removeUIElems();
734
+ resolve('permission denied');
735
+ }
736
+ }, 100);
737
+
738
+ // Start calibration process
739
+ (async () => {
740
+ try {
741
+ const result = await this.ac.startCalibration(
742
+ stream,
743
+ params.gainValues,
744
+ params.ICalib,
745
+ params.knownIR,
746
+ params.microphoneName,
747
+ params.calibrateSoundCheck,
748
+ params.isSmartPhone,
749
+ params.calibrateSoundBurstDb,
750
+ params.calibrateSoundBurstFilteredExtraDb,
751
+ params.calibrateSoundBurstLevelReTBool,
752
+ params.calibrateSoundBurstUses1000HzGainBool,
753
+ params.calibrateSoundBurstRepeats,
754
+ params.calibrateSoundBurstSec,
755
+ params._calibrateSoundBurstPreSec,
756
+ params._calibrateSoundBurstPostSec,
757
+ params.calibrateSoundHz,
758
+ params.calibrateSoundIRSec,
759
+ params.calibrateSoundIIRSec,
760
+ params.calibrateSoundIIRPhase,
761
+ params.calibrateSound1000HzPreSec,
762
+ params.calibrateSound1000HzSec,
763
+ params.calibrateSound1000HzPostSec,
764
+ params.calibrateSoundBackgroundSecs,
765
+ params.calibrateSoundSmoothOctaves,
766
+ params.calibrateSoundSmoothMinBandwidthHz,
767
+ params.calibrateSoundPowerBinDesiredSec,
768
+ params.calibrateSoundPowerDbSDToleratedDb,
769
+ params.calibrateSoundTaperSec,
770
+ params.micManufacturer,
771
+ params.micSerialNumber,
772
+ params.micModelNumber,
773
+ params.micModelName,
774
+ params.calibrateMicrophonesBool,
775
+ params.authorEmails,
776
+ params.webAudioDeviceNames,
777
+ params.IDsToSaveInSoundProfileLibrary,
778
+ params.restartButton,
779
+ params.reminder,
780
+ params.calibrateSoundLimit,
781
+ params.calibrateSoundBurstNormalizeBy1000HzGainBool,
782
+ params.calibrateSoundBurstScalarDB,
783
+ params.calibrateSound1000HzMaxSD_dB,
784
+ params._calibrateSoundBurstMaxSD_dB,
785
+ params.calibrateSoundSamplingDesiredBits,
786
+ params.language,
787
+ params.loudspeakerModelName,
788
+ params.phrases,
789
+ params.soundSubtitleId
790
+ );
791
+ clearInterval(permissionCheckInterval);
792
+ this.#removeUIElems();
793
+ resolve(result);
794
+ } catch (error) {
795
+ clearInterval(permissionCheckInterval);
796
+ reject(error);
797
+ }
798
+ })();
756
799
  });
757
800
  };
758
801
  }
@@ -296,6 +296,8 @@ class Combination extends AudioCalibrator {
296
296
  fs2;
297
297
  icapture = 0;
298
298
 
299
+ permissionStatus = null;
300
+
299
301
  /**generate string template that gets reevaluated as variable increases */
300
302
  generateTemplate = status => {
301
303
  if (this.isCalibrating) {
@@ -362,6 +364,10 @@ class Combination extends AudioCalibrator {
362
364
  this.deviceInfo = deviceInfo;
363
365
  };
364
366
 
367
+ setPermissionStatus = permissionStatus => {
368
+ this.permissionStatus = permissionStatus;
369
+ };
370
+
365
371
  /** .
366
372
  * .
367
373
  * .
@@ -3147,6 +3153,7 @@ class Combination extends AudioCalibrator {
3147
3153
  total_results['system']['phase'] = this.systemIRPhase;
3148
3154
  total_results['qualityMetrics'] = this.SDofFilteredRange;
3149
3155
  total_results['flags'] = this.flags;
3156
+ total_results['permissionStatus'] = this.permissionStatus;
3150
3157
  console.log('total results');
3151
3158
  console.log(total_results);
3152
3159
  console.log('Time Stamps');