web-audio-recorder-ts 1.0.1 → 1.0.2

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/index.cjs.js CHANGED
@@ -702,35 +702,43 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
702
702
  });
703
703
  return;
704
704
  }
705
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
706
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
705
+ // Verificar se o arquivo existe e é JavaScript válido
706
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
707
707
  .then(response => {
708
708
  if (!response.ok) {
709
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
709
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
710
710
  }
711
- // Criar e carregar novo script
712
- const script = document.createElement('script');
713
- script.src = scriptUrl;
714
- script.async = false; // Carregar de forma síncrona para garantir ordem
715
- script.type = 'text/javascript';
716
- script.onload = () => {
717
- // Aguardar um pouco para garantir que o objeto global foi criado
718
- setTimeout(() => {
719
- if (typeof window.OggVorbisEncoder !== 'undefined') {
720
- resolve();
721
- }
722
- else {
723
- reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
724
- }
725
- }, 200);
726
- };
727
- script.onerror = (event) => {
728
- const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
729
- console.error('Script load error:', event);
730
- console.error('Script URL:', scriptUrl);
731
- reject(error);
732
- };
733
- document.head.appendChild(script);
711
+ // Verificar se o conteúdo é JavaScript (não HTML)
712
+ return response.text().then(text => {
713
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
714
+ if (text.trim().startsWith('<')) {
715
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
716
+ }
717
+ // Criar e carregar novo script
718
+ const script = document.createElement('script');
719
+ script.src = scriptUrl;
720
+ script.async = false; // Carregar de forma síncrona para garantir ordem
721
+ script.type = 'text/javascript';
722
+ script.onload = () => {
723
+ // Aguardar um pouco para garantir que o objeto global foi criado
724
+ setTimeout(() => {
725
+ if (typeof window.OggVorbisEncoder !== 'undefined') {
726
+ resolve();
727
+ }
728
+ else {
729
+ reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
730
+ }
731
+ }, 200);
732
+ };
733
+ script.onerror = (event) => {
734
+ const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
735
+ console.error('Script load error:', event);
736
+ console.error('Script URL:', scriptUrl);
737
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
738
+ reject(error);
739
+ };
740
+ document.head.appendChild(script);
741
+ });
734
742
  })
735
743
  .catch(error => {
736
744
  reject(new Error(`Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}`));
@@ -861,35 +869,43 @@ function loadMp3LameEncoderInternal(scriptUrl) {
861
869
  });
862
870
  return;
863
871
  }
864
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
865
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
872
+ // Verificar se o arquivo existe e é JavaScript válido
873
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
866
874
  .then(response => {
867
875
  if (!response.ok) {
868
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
876
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
869
877
  }
870
- // Criar e carregar novo script
871
- const script = document.createElement('script');
872
- script.src = scriptUrl;
873
- script.async = false; // Carregar de forma síncrona para garantir ordem
874
- script.type = 'text/javascript';
875
- script.onload = () => {
876
- // Aguardar um pouco para garantir que o objeto global foi criado
877
- setTimeout(() => {
878
- if (typeof window.Mp3LameEncoder !== 'undefined') {
879
- resolve();
880
- }
881
- else {
882
- reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
883
- }
884
- }, 200);
885
- };
886
- script.onerror = (event) => {
887
- const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
888
- console.error('Script load error:', event);
889
- console.error('Script URL:', scriptUrl);
890
- reject(error);
891
- };
892
- document.head.appendChild(script);
878
+ // Verificar se o conteúdo é JavaScript (não HTML)
879
+ return response.text().then(text => {
880
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
881
+ if (text.trim().startsWith('<')) {
882
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
883
+ }
884
+ // Criar e carregar novo script
885
+ const script = document.createElement('script');
886
+ script.src = scriptUrl;
887
+ script.async = false; // Carregar de forma síncrona para garantir ordem
888
+ script.type = 'text/javascript';
889
+ script.onload = () => {
890
+ // Aguardar um pouco para garantir que o objeto global foi criado
891
+ setTimeout(() => {
892
+ if (typeof window.Mp3LameEncoder !== 'undefined') {
893
+ resolve();
894
+ }
895
+ else {
896
+ reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
897
+ }
898
+ }, 200);
899
+ };
900
+ script.onerror = (event) => {
901
+ const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
902
+ console.error('Script load error:', event);
903
+ console.error('Script URL:', scriptUrl);
904
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
905
+ reject(error);
906
+ };
907
+ document.head.appendChild(script);
908
+ });
893
909
  })
894
910
  .catch(error => {
895
911
  reject(new Error(`Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}`));
package/dist/index.esm.js CHANGED
@@ -699,35 +699,43 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
699
699
  });
700
700
  return;
701
701
  }
702
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
703
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
702
+ // Verificar se o arquivo existe e é JavaScript válido
703
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
704
704
  .then(response => {
705
705
  if (!response.ok) {
706
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
706
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
707
707
  }
708
- // Criar e carregar novo script
709
- const script = document.createElement('script');
710
- script.src = scriptUrl;
711
- script.async = false; // Carregar de forma síncrona para garantir ordem
712
- script.type = 'text/javascript';
713
- script.onload = () => {
714
- // Aguardar um pouco para garantir que o objeto global foi criado
715
- setTimeout(() => {
716
- if (typeof window.OggVorbisEncoder !== 'undefined') {
717
- resolve();
718
- }
719
- else {
720
- reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
721
- }
722
- }, 200);
723
- };
724
- script.onerror = (event) => {
725
- const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
726
- console.error('Script load error:', event);
727
- console.error('Script URL:', scriptUrl);
728
- reject(error);
729
- };
730
- document.head.appendChild(script);
708
+ // Verificar se o conteúdo é JavaScript (não HTML)
709
+ return response.text().then(text => {
710
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
711
+ if (text.trim().startsWith('<')) {
712
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
713
+ }
714
+ // Criar e carregar novo script
715
+ const script = document.createElement('script');
716
+ script.src = scriptUrl;
717
+ script.async = false; // Carregar de forma síncrona para garantir ordem
718
+ script.type = 'text/javascript';
719
+ script.onload = () => {
720
+ // Aguardar um pouco para garantir que o objeto global foi criado
721
+ setTimeout(() => {
722
+ if (typeof window.OggVorbisEncoder !== 'undefined') {
723
+ resolve();
724
+ }
725
+ else {
726
+ reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
727
+ }
728
+ }, 200);
729
+ };
730
+ script.onerror = (event) => {
731
+ const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
732
+ console.error('Script load error:', event);
733
+ console.error('Script URL:', scriptUrl);
734
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
735
+ reject(error);
736
+ };
737
+ document.head.appendChild(script);
738
+ });
731
739
  })
732
740
  .catch(error => {
733
741
  reject(new Error(`Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}`));
@@ -858,35 +866,43 @@ function loadMp3LameEncoderInternal(scriptUrl) {
858
866
  });
859
867
  return;
860
868
  }
861
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
862
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
869
+ // Verificar se o arquivo existe e é JavaScript válido
870
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
863
871
  .then(response => {
864
872
  if (!response.ok) {
865
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
873
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
866
874
  }
867
- // Criar e carregar novo script
868
- const script = document.createElement('script');
869
- script.src = scriptUrl;
870
- script.async = false; // Carregar de forma síncrona para garantir ordem
871
- script.type = 'text/javascript';
872
- script.onload = () => {
873
- // Aguardar um pouco para garantir que o objeto global foi criado
874
- setTimeout(() => {
875
- if (typeof window.Mp3LameEncoder !== 'undefined') {
876
- resolve();
877
- }
878
- else {
879
- reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
880
- }
881
- }, 200);
882
- };
883
- script.onerror = (event) => {
884
- const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
885
- console.error('Script load error:', event);
886
- console.error('Script URL:', scriptUrl);
887
- reject(error);
888
- };
889
- document.head.appendChild(script);
875
+ // Verificar se o conteúdo é JavaScript (não HTML)
876
+ return response.text().then(text => {
877
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
878
+ if (text.trim().startsWith('<')) {
879
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
880
+ }
881
+ // Criar e carregar novo script
882
+ const script = document.createElement('script');
883
+ script.src = scriptUrl;
884
+ script.async = false; // Carregar de forma síncrona para garantir ordem
885
+ script.type = 'text/javascript';
886
+ script.onload = () => {
887
+ // Aguardar um pouco para garantir que o objeto global foi criado
888
+ setTimeout(() => {
889
+ if (typeof window.Mp3LameEncoder !== 'undefined') {
890
+ resolve();
891
+ }
892
+ else {
893
+ reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
894
+ }
895
+ }, 200);
896
+ };
897
+ script.onerror = (event) => {
898
+ const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
899
+ console.error('Script load error:', event);
900
+ console.error('Script URL:', scriptUrl);
901
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
902
+ reject(error);
903
+ };
904
+ document.head.appendChild(script);
905
+ });
890
906
  })
891
907
  .catch(error => {
892
908
  reject(new Error(`Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}`));
package/dist/index.umd.js CHANGED
@@ -706,35 +706,43 @@
706
706
  });
707
707
  return;
708
708
  }
709
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
710
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
709
+ // Verificar se o arquivo existe e é JavaScript válido
710
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
711
711
  .then(response => {
712
712
  if (!response.ok) {
713
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
713
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
714
714
  }
715
- // Criar e carregar novo script
716
- const script = document.createElement('script');
717
- script.src = scriptUrl;
718
- script.async = false; // Carregar de forma síncrona para garantir ordem
719
- script.type = 'text/javascript';
720
- script.onload = () => {
721
- // Aguardar um pouco para garantir que o objeto global foi criado
722
- setTimeout(() => {
723
- if (typeof window.OggVorbisEncoder !== 'undefined') {
724
- resolve();
725
- }
726
- else {
727
- reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
728
- }
729
- }, 200);
730
- };
731
- script.onerror = (event) => {
732
- const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
733
- console.error('Script load error:', event);
734
- console.error('Script URL:', scriptUrl);
735
- reject(error);
736
- };
737
- document.head.appendChild(script);
715
+ // Verificar se o conteúdo é JavaScript (não HTML)
716
+ return response.text().then(text => {
717
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
718
+ if (text.trim().startsWith('<')) {
719
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
720
+ }
721
+ // Criar e carregar novo script
722
+ const script = document.createElement('script');
723
+ script.src = scriptUrl;
724
+ script.async = false; // Carregar de forma síncrona para garantir ordem
725
+ script.type = 'text/javascript';
726
+ script.onload = () => {
727
+ // Aguardar um pouco para garantir que o objeto global foi criado
728
+ setTimeout(() => {
729
+ if (typeof window.OggVorbisEncoder !== 'undefined') {
730
+ resolve();
731
+ }
732
+ else {
733
+ reject(new Error('OggVorbisEncoder object not found after script load. The script may not have exported the global correctly.'));
734
+ }
735
+ }, 200);
736
+ };
737
+ script.onerror = (event) => {
738
+ const error = new Error(`Failed to load OggVorbisEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
739
+ console.error('Script load error:', event);
740
+ console.error('Script URL:', scriptUrl);
741
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
742
+ reject(error);
743
+ };
744
+ document.head.appendChild(script);
745
+ });
738
746
  })
739
747
  .catch(error => {
740
748
  reject(new Error(`Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}`));
@@ -865,35 +873,43 @@
865
873
  });
866
874
  return;
867
875
  }
868
- // Primeiro, verificar se o arquivo existe fazendo uma requisição HEAD
869
- fetch(scriptUrl, { method: 'HEAD', cache: 'no-cache' })
876
+ // Verificar se o arquivo existe e é JavaScript válido
877
+ fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
870
878
  .then(response => {
871
879
  if (!response.ok) {
872
- throw new Error(`File not found: ${scriptUrl} (${response.status})`);
880
+ throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})`);
873
881
  }
874
- // Criar e carregar novo script
875
- const script = document.createElement('script');
876
- script.src = scriptUrl;
877
- script.async = false; // Carregar de forma síncrona para garantir ordem
878
- script.type = 'text/javascript';
879
- script.onload = () => {
880
- // Aguardar um pouco para garantir que o objeto global foi criado
881
- setTimeout(() => {
882
- if (typeof window.Mp3LameEncoder !== 'undefined') {
883
- resolve();
884
- }
885
- else {
886
- reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
887
- }
888
- }, 200);
889
- };
890
- script.onerror = (event) => {
891
- const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors.`);
892
- console.error('Script load error:', event);
893
- console.error('Script URL:', scriptUrl);
894
- reject(error);
895
- };
896
- document.head.appendChild(script);
882
+ // Verificar se o conteúdo é JavaScript (não HTML)
883
+ return response.text().then(text => {
884
+ // Se começar com '<', provavelmente é HTML (erro 404, etc)
885
+ if (text.trim().startsWith('<')) {
886
+ throw new Error(`Invalid response from ${scriptUrl}. Expected JavaScript but received HTML. This usually means the file was not found (404).`);
887
+ }
888
+ // Criar e carregar novo script
889
+ const script = document.createElement('script');
890
+ script.src = scriptUrl;
891
+ script.async = false; // Carregar de forma síncrona para garantir ordem
892
+ script.type = 'text/javascript';
893
+ script.onload = () => {
894
+ // Aguardar um pouco para garantir que o objeto global foi criado
895
+ setTimeout(() => {
896
+ if (typeof window.Mp3LameEncoder !== 'undefined') {
897
+ resolve();
898
+ }
899
+ else {
900
+ reject(new Error('Mp3LameEncoder object not found after script load. The script may not have exported the global correctly.'));
901
+ }
902
+ }, 200);
903
+ };
904
+ script.onerror = (event) => {
905
+ const error = new Error(`Failed to load Mp3LameEncoder script from ${scriptUrl}. Check browser console for CORS or network errors. Make sure the file exists and is accessible.`);
906
+ console.error('Script load error:', event);
907
+ console.error('Script URL:', scriptUrl);
908
+ console.error('Try accessing the URL directly in your browser to verify it exists.');
909
+ reject(error);
910
+ };
911
+ document.head.appendChild(script);
912
+ });
897
913
  })
898
914
  .catch(error => {
899
915
  reject(new Error(`Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-audio-recorder-ts",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "TypeScript port of web-audio-recorder-js with full type support for WAV, OGG Vorbis, and MP3 audio recording",
6
6
  "main": "dist/index.cjs.js",