web-audio-recorder-ts 1.0.2 → 1.0.3
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 +100 -27
- package/dist/index.esm.js +100 -27
- package/dist/index.umd.js +100 -27
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -438,12 +438,20 @@ function getEncoderBaseUrl() {
|
|
|
438
438
|
const parts = __dirname.split('node_modules/');
|
|
439
439
|
if (parts.length > 1) {
|
|
440
440
|
const packageName = parts[1].split('/')[0];
|
|
441
|
+
// Retornar caminho absoluto se possível
|
|
442
|
+
if (typeof window !== 'undefined') {
|
|
443
|
+
return `${window.location.origin}/node_modules/${packageName}/lib`;
|
|
444
|
+
}
|
|
441
445
|
return `/node_modules/${packageName}/lib`;
|
|
442
446
|
}
|
|
443
447
|
}
|
|
444
448
|
// If in dist, go to lib
|
|
445
449
|
if (__dirname.includes('dist')) {
|
|
446
|
-
|
|
450
|
+
const libPath = __dirname.replace('dist', 'lib');
|
|
451
|
+
if (typeof window !== 'undefined') {
|
|
452
|
+
return `${window.location.origin}${libPath}`;
|
|
453
|
+
}
|
|
454
|
+
return libPath;
|
|
447
455
|
}
|
|
448
456
|
}
|
|
449
457
|
catch (e) {
|
|
@@ -472,6 +480,7 @@ function getEncoderBaseUrl() {
|
|
|
472
480
|
if (url.pathname.includes('node_modules')) {
|
|
473
481
|
const packagePath = url.pathname.split('node_modules/')[1];
|
|
474
482
|
const packageName = packagePath.split('/')[0];
|
|
483
|
+
// Retornar caminho absoluto para node_modules
|
|
475
484
|
return `${url.origin}/node_modules/${packageName}/lib`;
|
|
476
485
|
}
|
|
477
486
|
// If from dist, go to lib
|
|
@@ -485,11 +494,10 @@ function getEncoderBaseUrl() {
|
|
|
485
494
|
}
|
|
486
495
|
}
|
|
487
496
|
}
|
|
488
|
-
// Default fallback: try
|
|
489
|
-
// In browser, try root first (for Vite public/), then node_modules, then lib
|
|
497
|
+
// Default fallback: try node_modules first, then root
|
|
490
498
|
if (typeof window !== 'undefined') {
|
|
491
|
-
//
|
|
492
|
-
return '/';
|
|
499
|
+
// Priorizar node_modules
|
|
500
|
+
return '/node_modules/web-audio-recorder-ts/lib';
|
|
493
501
|
}
|
|
494
502
|
return '/lib';
|
|
495
503
|
}
|
|
@@ -541,22 +549,24 @@ function configureEncoderPaths(baseUrl) {
|
|
|
541
549
|
* Useful when auto-detection fails
|
|
542
550
|
*/
|
|
543
551
|
async function findEncoderPath(filename) {
|
|
552
|
+
// Priorizar caminhos do node_modules primeiro
|
|
544
553
|
const possiblePaths = [
|
|
545
|
-
//
|
|
546
|
-
`/${filename}`,
|
|
547
|
-
// Direct lib paths (for development or custom setups)
|
|
548
|
-
`/lib/${filename}`,
|
|
549
|
-
`./lib/${filename}`,
|
|
550
|
-
`../lib/${filename}`,
|
|
551
|
-
// Auto-detected path
|
|
552
|
-
getEncoderScriptUrl(filename),
|
|
553
|
-
// Common npm package paths (from node_modules) - only works if server is configured
|
|
554
|
+
// Primeiro: tentar node_modules (prioridade máxima)
|
|
554
555
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
555
556
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
556
557
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
557
|
-
|
|
558
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
559
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
558
560
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
559
561
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
562
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
563
|
+
getEncoderScriptUrl(filename),
|
|
564
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
565
|
+
`/${filename}`,
|
|
566
|
+
// Direct lib paths (for development or custom setups)
|
|
567
|
+
`/lib/${filename}`,
|
|
568
|
+
`./lib/${filename}`,
|
|
569
|
+
`../lib/${filename}`,
|
|
560
570
|
// CDN or absolute paths (if configured)
|
|
561
571
|
filename.startsWith('http') ? filename : null
|
|
562
572
|
].filter((path) => path !== null);
|
|
@@ -566,9 +576,22 @@ async function findEncoderPath(filename) {
|
|
|
566
576
|
const testUrl = path.startsWith('http')
|
|
567
577
|
? path
|
|
568
578
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
569
|
-
|
|
579
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
580
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
570
581
|
if (response.ok) {
|
|
571
|
-
|
|
582
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
583
|
+
const text = await response.text();
|
|
584
|
+
const trimmedText = text.trim();
|
|
585
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
586
|
+
if (trimmedText.startsWith('<')) {
|
|
587
|
+
console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
// Se parece JavaScript, retornar este caminho
|
|
591
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
592
|
+
console.log(`✅ Found encoder file at: ${path}`);
|
|
593
|
+
return path;
|
|
594
|
+
}
|
|
572
595
|
}
|
|
573
596
|
}
|
|
574
597
|
catch (e) {
|
|
@@ -706,13 +729,31 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
706
729
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
707
730
|
.then(response => {
|
|
708
731
|
if (!response.ok) {
|
|
709
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
732
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
733
|
+
}
|
|
734
|
+
// Verificar Content-Type
|
|
735
|
+
const contentType = response.headers.get('content-type') || '';
|
|
736
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
737
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
710
738
|
}
|
|
711
739
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
712
740
|
return response.text().then(text => {
|
|
741
|
+
const trimmedText = text.trim();
|
|
713
742
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
714
|
-
if (
|
|
715
|
-
|
|
743
|
+
if (trimmedText.startsWith('<')) {
|
|
744
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
745
|
+
`The file was not found at this path. Please:\n` +
|
|
746
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
747
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
748
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
749
|
+
`4. Try accessing the URL directly in your browser`;
|
|
750
|
+
console.error(errorMsg);
|
|
751
|
+
reject(new Error(errorMsg));
|
|
752
|
+
return; // Não continuar se for HTML
|
|
753
|
+
}
|
|
754
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
755
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
756
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
716
757
|
}
|
|
717
758
|
// Criar e carregar novo script
|
|
718
759
|
const script = document.createElement('script');
|
|
@@ -726,7 +767,7 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
726
767
|
resolve();
|
|
727
768
|
}
|
|
728
769
|
else {
|
|
729
|
-
reject(new Error(
|
|
770
|
+
reject(new Error(`OggVorbisEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
730
771
|
}
|
|
731
772
|
}, 200);
|
|
732
773
|
};
|
|
@@ -741,7 +782,14 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
741
782
|
});
|
|
742
783
|
})
|
|
743
784
|
.catch(error => {
|
|
744
|
-
|
|
785
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
786
|
+
`Troubleshooting:\n` +
|
|
787
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
788
|
+
`2. Check browser console for CORS errors\n` +
|
|
789
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
790
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
791
|
+
console.error(errorMsg);
|
|
792
|
+
reject(new Error(errorMsg));
|
|
745
793
|
});
|
|
746
794
|
});
|
|
747
795
|
}
|
|
@@ -873,13 +921,31 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
873
921
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
874
922
|
.then(response => {
|
|
875
923
|
if (!response.ok) {
|
|
876
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
924
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
925
|
+
}
|
|
926
|
+
// Verificar Content-Type
|
|
927
|
+
const contentType = response.headers.get('content-type') || '';
|
|
928
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
929
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
877
930
|
}
|
|
878
931
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
879
932
|
return response.text().then(text => {
|
|
933
|
+
const trimmedText = text.trim();
|
|
880
934
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
881
|
-
if (
|
|
882
|
-
|
|
935
|
+
if (trimmedText.startsWith('<')) {
|
|
936
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
937
|
+
`The file was not found at this path. Please:\n` +
|
|
938
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
939
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
940
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
941
|
+
`4. Try accessing the URL directly in your browser`;
|
|
942
|
+
console.error(errorMsg);
|
|
943
|
+
reject(new Error(errorMsg));
|
|
944
|
+
return; // Não continuar se for HTML
|
|
945
|
+
}
|
|
946
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
947
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
948
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
883
949
|
}
|
|
884
950
|
// Criar e carregar novo script
|
|
885
951
|
const script = document.createElement('script');
|
|
@@ -893,7 +959,7 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
893
959
|
resolve();
|
|
894
960
|
}
|
|
895
961
|
else {
|
|
896
|
-
reject(new Error(
|
|
962
|
+
reject(new Error(`Mp3LameEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
897
963
|
}
|
|
898
964
|
}, 200);
|
|
899
965
|
};
|
|
@@ -908,7 +974,14 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
908
974
|
});
|
|
909
975
|
})
|
|
910
976
|
.catch(error => {
|
|
911
|
-
|
|
977
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
978
|
+
`Troubleshooting:\n` +
|
|
979
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
980
|
+
`2. Check browser console for CORS errors\n` +
|
|
981
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
982
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
983
|
+
console.error(errorMsg);
|
|
984
|
+
reject(new Error(errorMsg));
|
|
912
985
|
});
|
|
913
986
|
});
|
|
914
987
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -435,12 +435,20 @@ function getEncoderBaseUrl() {
|
|
|
435
435
|
const parts = __dirname.split('node_modules/');
|
|
436
436
|
if (parts.length > 1) {
|
|
437
437
|
const packageName = parts[1].split('/')[0];
|
|
438
|
+
// Retornar caminho absoluto se possível
|
|
439
|
+
if (typeof window !== 'undefined') {
|
|
440
|
+
return `${window.location.origin}/node_modules/${packageName}/lib`;
|
|
441
|
+
}
|
|
438
442
|
return `/node_modules/${packageName}/lib`;
|
|
439
443
|
}
|
|
440
444
|
}
|
|
441
445
|
// If in dist, go to lib
|
|
442
446
|
if (__dirname.includes('dist')) {
|
|
443
|
-
|
|
447
|
+
const libPath = __dirname.replace('dist', 'lib');
|
|
448
|
+
if (typeof window !== 'undefined') {
|
|
449
|
+
return `${window.location.origin}${libPath}`;
|
|
450
|
+
}
|
|
451
|
+
return libPath;
|
|
444
452
|
}
|
|
445
453
|
}
|
|
446
454
|
catch (e) {
|
|
@@ -469,6 +477,7 @@ function getEncoderBaseUrl() {
|
|
|
469
477
|
if (url.pathname.includes('node_modules')) {
|
|
470
478
|
const packagePath = url.pathname.split('node_modules/')[1];
|
|
471
479
|
const packageName = packagePath.split('/')[0];
|
|
480
|
+
// Retornar caminho absoluto para node_modules
|
|
472
481
|
return `${url.origin}/node_modules/${packageName}/lib`;
|
|
473
482
|
}
|
|
474
483
|
// If from dist, go to lib
|
|
@@ -482,11 +491,10 @@ function getEncoderBaseUrl() {
|
|
|
482
491
|
}
|
|
483
492
|
}
|
|
484
493
|
}
|
|
485
|
-
// Default fallback: try
|
|
486
|
-
// In browser, try root first (for Vite public/), then node_modules, then lib
|
|
494
|
+
// Default fallback: try node_modules first, then root
|
|
487
495
|
if (typeof window !== 'undefined') {
|
|
488
|
-
//
|
|
489
|
-
return '/';
|
|
496
|
+
// Priorizar node_modules
|
|
497
|
+
return '/node_modules/web-audio-recorder-ts/lib';
|
|
490
498
|
}
|
|
491
499
|
return '/lib';
|
|
492
500
|
}
|
|
@@ -538,22 +546,24 @@ function configureEncoderPaths(baseUrl) {
|
|
|
538
546
|
* Useful when auto-detection fails
|
|
539
547
|
*/
|
|
540
548
|
async function findEncoderPath(filename) {
|
|
549
|
+
// Priorizar caminhos do node_modules primeiro
|
|
541
550
|
const possiblePaths = [
|
|
542
|
-
//
|
|
543
|
-
`/${filename}`,
|
|
544
|
-
// Direct lib paths (for development or custom setups)
|
|
545
|
-
`/lib/${filename}`,
|
|
546
|
-
`./lib/${filename}`,
|
|
547
|
-
`../lib/${filename}`,
|
|
548
|
-
// Auto-detected path
|
|
549
|
-
getEncoderScriptUrl(filename),
|
|
550
|
-
// Common npm package paths (from node_modules) - only works if server is configured
|
|
551
|
+
// Primeiro: tentar node_modules (prioridade máxima)
|
|
551
552
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
552
553
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
553
554
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
554
|
-
|
|
555
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
556
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
555
557
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
556
558
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
559
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
560
|
+
getEncoderScriptUrl(filename),
|
|
561
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
562
|
+
`/${filename}`,
|
|
563
|
+
// Direct lib paths (for development or custom setups)
|
|
564
|
+
`/lib/${filename}`,
|
|
565
|
+
`./lib/${filename}`,
|
|
566
|
+
`../lib/${filename}`,
|
|
557
567
|
// CDN or absolute paths (if configured)
|
|
558
568
|
filename.startsWith('http') ? filename : null
|
|
559
569
|
].filter((path) => path !== null);
|
|
@@ -563,9 +573,22 @@ async function findEncoderPath(filename) {
|
|
|
563
573
|
const testUrl = path.startsWith('http')
|
|
564
574
|
? path
|
|
565
575
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
566
|
-
|
|
576
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
577
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
567
578
|
if (response.ok) {
|
|
568
|
-
|
|
579
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
580
|
+
const text = await response.text();
|
|
581
|
+
const trimmedText = text.trim();
|
|
582
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
583
|
+
if (trimmedText.startsWith('<')) {
|
|
584
|
+
console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
// Se parece JavaScript, retornar este caminho
|
|
588
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
589
|
+
console.log(`✅ Found encoder file at: ${path}`);
|
|
590
|
+
return path;
|
|
591
|
+
}
|
|
569
592
|
}
|
|
570
593
|
}
|
|
571
594
|
catch (e) {
|
|
@@ -703,13 +726,31 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
703
726
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
704
727
|
.then(response => {
|
|
705
728
|
if (!response.ok) {
|
|
706
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
729
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
730
|
+
}
|
|
731
|
+
// Verificar Content-Type
|
|
732
|
+
const contentType = response.headers.get('content-type') || '';
|
|
733
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
734
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
707
735
|
}
|
|
708
736
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
709
737
|
return response.text().then(text => {
|
|
738
|
+
const trimmedText = text.trim();
|
|
710
739
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
711
|
-
if (
|
|
712
|
-
|
|
740
|
+
if (trimmedText.startsWith('<')) {
|
|
741
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
742
|
+
`The file was not found at this path. Please:\n` +
|
|
743
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
744
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
745
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
746
|
+
`4. Try accessing the URL directly in your browser`;
|
|
747
|
+
console.error(errorMsg);
|
|
748
|
+
reject(new Error(errorMsg));
|
|
749
|
+
return; // Não continuar se for HTML
|
|
750
|
+
}
|
|
751
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
752
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
753
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
713
754
|
}
|
|
714
755
|
// Criar e carregar novo script
|
|
715
756
|
const script = document.createElement('script');
|
|
@@ -723,7 +764,7 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
723
764
|
resolve();
|
|
724
765
|
}
|
|
725
766
|
else {
|
|
726
|
-
reject(new Error(
|
|
767
|
+
reject(new Error(`OggVorbisEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
727
768
|
}
|
|
728
769
|
}, 200);
|
|
729
770
|
};
|
|
@@ -738,7 +779,14 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
738
779
|
});
|
|
739
780
|
})
|
|
740
781
|
.catch(error => {
|
|
741
|
-
|
|
782
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
783
|
+
`Troubleshooting:\n` +
|
|
784
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
785
|
+
`2. Check browser console for CORS errors\n` +
|
|
786
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
787
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
788
|
+
console.error(errorMsg);
|
|
789
|
+
reject(new Error(errorMsg));
|
|
742
790
|
});
|
|
743
791
|
});
|
|
744
792
|
}
|
|
@@ -870,13 +918,31 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
870
918
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
871
919
|
.then(response => {
|
|
872
920
|
if (!response.ok) {
|
|
873
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
921
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
922
|
+
}
|
|
923
|
+
// Verificar Content-Type
|
|
924
|
+
const contentType = response.headers.get('content-type') || '';
|
|
925
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
926
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
874
927
|
}
|
|
875
928
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
876
929
|
return response.text().then(text => {
|
|
930
|
+
const trimmedText = text.trim();
|
|
877
931
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
878
|
-
if (
|
|
879
|
-
|
|
932
|
+
if (trimmedText.startsWith('<')) {
|
|
933
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
934
|
+
`The file was not found at this path. Please:\n` +
|
|
935
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
936
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
937
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
938
|
+
`4. Try accessing the URL directly in your browser`;
|
|
939
|
+
console.error(errorMsg);
|
|
940
|
+
reject(new Error(errorMsg));
|
|
941
|
+
return; // Não continuar se for HTML
|
|
942
|
+
}
|
|
943
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
944
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
945
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
880
946
|
}
|
|
881
947
|
// Criar e carregar novo script
|
|
882
948
|
const script = document.createElement('script');
|
|
@@ -890,7 +956,7 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
890
956
|
resolve();
|
|
891
957
|
}
|
|
892
958
|
else {
|
|
893
|
-
reject(new Error(
|
|
959
|
+
reject(new Error(`Mp3LameEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
894
960
|
}
|
|
895
961
|
}, 200);
|
|
896
962
|
};
|
|
@@ -905,7 +971,14 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
905
971
|
});
|
|
906
972
|
})
|
|
907
973
|
.catch(error => {
|
|
908
|
-
|
|
974
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
975
|
+
`Troubleshooting:\n` +
|
|
976
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
977
|
+
`2. Check browser console for CORS errors\n` +
|
|
978
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
979
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
980
|
+
console.error(errorMsg);
|
|
981
|
+
reject(new Error(errorMsg));
|
|
909
982
|
});
|
|
910
983
|
});
|
|
911
984
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -442,12 +442,20 @@
|
|
|
442
442
|
const parts = __dirname.split('node_modules/');
|
|
443
443
|
if (parts.length > 1) {
|
|
444
444
|
const packageName = parts[1].split('/')[0];
|
|
445
|
+
// Retornar caminho absoluto se possível
|
|
446
|
+
if (typeof window !== 'undefined') {
|
|
447
|
+
return `${window.location.origin}/node_modules/${packageName}/lib`;
|
|
448
|
+
}
|
|
445
449
|
return `/node_modules/${packageName}/lib`;
|
|
446
450
|
}
|
|
447
451
|
}
|
|
448
452
|
// If in dist, go to lib
|
|
449
453
|
if (__dirname.includes('dist')) {
|
|
450
|
-
|
|
454
|
+
const libPath = __dirname.replace('dist', 'lib');
|
|
455
|
+
if (typeof window !== 'undefined') {
|
|
456
|
+
return `${window.location.origin}${libPath}`;
|
|
457
|
+
}
|
|
458
|
+
return libPath;
|
|
451
459
|
}
|
|
452
460
|
}
|
|
453
461
|
catch (e) {
|
|
@@ -476,6 +484,7 @@
|
|
|
476
484
|
if (url.pathname.includes('node_modules')) {
|
|
477
485
|
const packagePath = url.pathname.split('node_modules/')[1];
|
|
478
486
|
const packageName = packagePath.split('/')[0];
|
|
487
|
+
// Retornar caminho absoluto para node_modules
|
|
479
488
|
return `${url.origin}/node_modules/${packageName}/lib`;
|
|
480
489
|
}
|
|
481
490
|
// If from dist, go to lib
|
|
@@ -489,11 +498,10 @@
|
|
|
489
498
|
}
|
|
490
499
|
}
|
|
491
500
|
}
|
|
492
|
-
// Default fallback: try
|
|
493
|
-
// In browser, try root first (for Vite public/), then node_modules, then lib
|
|
501
|
+
// Default fallback: try node_modules first, then root
|
|
494
502
|
if (typeof window !== 'undefined') {
|
|
495
|
-
//
|
|
496
|
-
return '/';
|
|
503
|
+
// Priorizar node_modules
|
|
504
|
+
return '/node_modules/web-audio-recorder-ts/lib';
|
|
497
505
|
}
|
|
498
506
|
return '/lib';
|
|
499
507
|
}
|
|
@@ -545,22 +553,24 @@
|
|
|
545
553
|
* Useful when auto-detection fails
|
|
546
554
|
*/
|
|
547
555
|
async function findEncoderPath(filename) {
|
|
556
|
+
// Priorizar caminhos do node_modules primeiro
|
|
548
557
|
const possiblePaths = [
|
|
549
|
-
//
|
|
550
|
-
`/${filename}`,
|
|
551
|
-
// Direct lib paths (for development or custom setups)
|
|
552
|
-
`/lib/${filename}`,
|
|
553
|
-
`./lib/${filename}`,
|
|
554
|
-
`../lib/${filename}`,
|
|
555
|
-
// Auto-detected path
|
|
556
|
-
getEncoderScriptUrl(filename),
|
|
557
|
-
// Common npm package paths (from node_modules) - only works if server is configured
|
|
558
|
+
// Primeiro: tentar node_modules (prioridade máxima)
|
|
558
559
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
559
560
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
560
561
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
561
|
-
|
|
562
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
563
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
562
564
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
563
565
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
566
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
567
|
+
getEncoderScriptUrl(filename),
|
|
568
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
569
|
+
`/${filename}`,
|
|
570
|
+
// Direct lib paths (for development or custom setups)
|
|
571
|
+
`/lib/${filename}`,
|
|
572
|
+
`./lib/${filename}`,
|
|
573
|
+
`../lib/${filename}`,
|
|
564
574
|
// CDN or absolute paths (if configured)
|
|
565
575
|
filename.startsWith('http') ? filename : null
|
|
566
576
|
].filter((path) => path !== null);
|
|
@@ -570,9 +580,22 @@
|
|
|
570
580
|
const testUrl = path.startsWith('http')
|
|
571
581
|
? path
|
|
572
582
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
573
|
-
|
|
583
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
584
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
574
585
|
if (response.ok) {
|
|
575
|
-
|
|
586
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
587
|
+
const text = await response.text();
|
|
588
|
+
const trimmedText = text.trim();
|
|
589
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
590
|
+
if (trimmedText.startsWith('<')) {
|
|
591
|
+
console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
// Se parece JavaScript, retornar este caminho
|
|
595
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
596
|
+
console.log(`✅ Found encoder file at: ${path}`);
|
|
597
|
+
return path;
|
|
598
|
+
}
|
|
576
599
|
}
|
|
577
600
|
}
|
|
578
601
|
catch (e) {
|
|
@@ -710,13 +733,31 @@
|
|
|
710
733
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
711
734
|
.then(response => {
|
|
712
735
|
if (!response.ok) {
|
|
713
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
736
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
737
|
+
}
|
|
738
|
+
// Verificar Content-Type
|
|
739
|
+
const contentType = response.headers.get('content-type') || '';
|
|
740
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
741
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
714
742
|
}
|
|
715
743
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
716
744
|
return response.text().then(text => {
|
|
745
|
+
const trimmedText = text.trim();
|
|
717
746
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
718
|
-
if (
|
|
719
|
-
|
|
747
|
+
if (trimmedText.startsWith('<')) {
|
|
748
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
749
|
+
`The file was not found at this path. Please:\n` +
|
|
750
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
751
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
752
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
753
|
+
`4. Try accessing the URL directly in your browser`;
|
|
754
|
+
console.error(errorMsg);
|
|
755
|
+
reject(new Error(errorMsg));
|
|
756
|
+
return; // Não continuar se for HTML
|
|
757
|
+
}
|
|
758
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
759
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
760
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
720
761
|
}
|
|
721
762
|
// Criar e carregar novo script
|
|
722
763
|
const script = document.createElement('script');
|
|
@@ -730,7 +771,7 @@
|
|
|
730
771
|
resolve();
|
|
731
772
|
}
|
|
732
773
|
else {
|
|
733
|
-
reject(new Error(
|
|
774
|
+
reject(new Error(`OggVorbisEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
734
775
|
}
|
|
735
776
|
}, 200);
|
|
736
777
|
};
|
|
@@ -745,7 +786,14 @@
|
|
|
745
786
|
});
|
|
746
787
|
})
|
|
747
788
|
.catch(error => {
|
|
748
|
-
|
|
789
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
790
|
+
`Troubleshooting:\n` +
|
|
791
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
792
|
+
`2. Check browser console for CORS errors\n` +
|
|
793
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
794
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
795
|
+
console.error(errorMsg);
|
|
796
|
+
reject(new Error(errorMsg));
|
|
749
797
|
});
|
|
750
798
|
});
|
|
751
799
|
}
|
|
@@ -877,13 +925,31 @@
|
|
|
877
925
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
878
926
|
.then(response => {
|
|
879
927
|
if (!response.ok) {
|
|
880
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
928
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
929
|
+
}
|
|
930
|
+
// Verificar Content-Type
|
|
931
|
+
const contentType = response.headers.get('content-type') || '';
|
|
932
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
933
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
881
934
|
}
|
|
882
935
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
883
936
|
return response.text().then(text => {
|
|
937
|
+
const trimmedText = text.trim();
|
|
884
938
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
885
|
-
if (
|
|
886
|
-
|
|
939
|
+
if (trimmedText.startsWith('<')) {
|
|
940
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
941
|
+
`The file was not found at this path. Please:\n` +
|
|
942
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
943
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
944
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
945
|
+
`4. Try accessing the URL directly in your browser`;
|
|
946
|
+
console.error(errorMsg);
|
|
947
|
+
reject(new Error(errorMsg));
|
|
948
|
+
return; // Não continuar se for HTML
|
|
949
|
+
}
|
|
950
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
951
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
952
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
887
953
|
}
|
|
888
954
|
// Criar e carregar novo script
|
|
889
955
|
const script = document.createElement('script');
|
|
@@ -897,7 +963,7 @@
|
|
|
897
963
|
resolve();
|
|
898
964
|
}
|
|
899
965
|
else {
|
|
900
|
-
reject(new Error(
|
|
966
|
+
reject(new Error(`Mp3LameEncoder object not found after script load from ${scriptUrl}. The script may not have exported the global correctly, or the file may be corrupted.`));
|
|
901
967
|
}
|
|
902
968
|
}, 200);
|
|
903
969
|
};
|
|
@@ -912,7 +978,14 @@
|
|
|
912
978
|
});
|
|
913
979
|
})
|
|
914
980
|
.catch(error => {
|
|
915
|
-
|
|
981
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
982
|
+
`Troubleshooting:\n` +
|
|
983
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
984
|
+
`2. Check browser console for CORS errors\n` +
|
|
985
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
986
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
987
|
+
console.error(errorMsg);
|
|
988
|
+
reject(new Error(errorMsg));
|
|
916
989
|
});
|
|
917
990
|
});
|
|
918
991
|
}
|
package/package.json
CHANGED