web-audio-recorder-ts 1.0.2 → 1.0.4
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 +140 -32
- package/dist/index.esm.js +140 -32
- package/dist/index.umd.js +140 -32
- 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,41 +549,79 @@ function configureEncoderPaths(baseUrl) {
|
|
|
541
549
|
* Useful when auto-detection fails
|
|
542
550
|
*/
|
|
543
551
|
async function findEncoderPath(filename) {
|
|
552
|
+
// Obter base URL atual para construir caminhos relativos
|
|
553
|
+
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
554
|
+
const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
|
|
555
|
+
// Priorizar caminhos do node_modules primeiro
|
|
544
556
|
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
|
|
557
|
+
// Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
|
|
554
558
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
559
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
560
|
+
// Caminhos relativos do node_modules
|
|
555
561
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
556
562
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
557
|
-
|
|
563
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
564
|
+
`../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
565
|
+
// Com base no caminho atual
|
|
566
|
+
`${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
567
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
558
568
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
569
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
559
570
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
571
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
572
|
+
getEncoderScriptUrl(filename),
|
|
573
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
574
|
+
`/${filename}`,
|
|
575
|
+
`${currentOrigin}/${filename}`,
|
|
576
|
+
// Direct lib paths (for development or custom setups)
|
|
577
|
+
`/lib/${filename}`,
|
|
578
|
+
`${currentOrigin}/lib/${filename}`,
|
|
579
|
+
`./lib/${filename}`,
|
|
580
|
+
`../lib/${filename}`,
|
|
560
581
|
// CDN or absolute paths (if configured)
|
|
561
582
|
filename.startsWith('http') ? filename : null
|
|
562
583
|
].filter((path) => path !== null);
|
|
584
|
+
console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
|
|
563
585
|
// Try each path
|
|
564
|
-
for (
|
|
586
|
+
for (let i = 0; i < possiblePaths.length; i++) {
|
|
587
|
+
const path = possiblePaths[i];
|
|
565
588
|
try {
|
|
566
589
|
const testUrl = path.startsWith('http')
|
|
567
590
|
? path
|
|
568
591
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
569
|
-
|
|
592
|
+
console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
|
|
593
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
594
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
570
595
|
if (response.ok) {
|
|
571
|
-
|
|
596
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
597
|
+
const text = await response.text();
|
|
598
|
+
const trimmedText = text.trim();
|
|
599
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
600
|
+
if (trimmedText.startsWith('<')) {
|
|
601
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
// Se parece JavaScript, retornar este caminho
|
|
605
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
606
|
+
console.log(`[web-audio-recorder-ts] ✅ Found encoder file at: ${path}`);
|
|
607
|
+
return path;
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
|
|
572
615
|
}
|
|
573
616
|
}
|
|
574
617
|
catch (e) {
|
|
618
|
+
console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
|
|
575
619
|
// Continue to next path
|
|
576
620
|
continue;
|
|
577
621
|
}
|
|
578
622
|
}
|
|
623
|
+
console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
|
|
624
|
+
console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
|
|
579
625
|
return null;
|
|
580
626
|
}
|
|
581
627
|
|
|
@@ -657,8 +703,14 @@ async function loadOggVorbisEncoder(scriptUrl) {
|
|
|
657
703
|
// Tentar encontrar o arquivo automaticamente
|
|
658
704
|
const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
|
|
659
705
|
if (!foundPath) {
|
|
660
|
-
|
|
661
|
-
'Please
|
|
706
|
+
const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
|
|
707
|
+
'Please try one of the following:\n' +
|
|
708
|
+
'1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
|
|
709
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
710
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
711
|
+
'4. Check browser console for detailed path information';
|
|
712
|
+
console.error(errorMsg);
|
|
713
|
+
throw new Error(errorMsg);
|
|
662
714
|
}
|
|
663
715
|
scriptUrl = foundPath;
|
|
664
716
|
}
|
|
@@ -706,13 +758,31 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
706
758
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
707
759
|
.then(response => {
|
|
708
760
|
if (!response.ok) {
|
|
709
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
761
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
762
|
+
}
|
|
763
|
+
// Verificar Content-Type
|
|
764
|
+
const contentType = response.headers.get('content-type') || '';
|
|
765
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
766
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
710
767
|
}
|
|
711
768
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
712
769
|
return response.text().then(text => {
|
|
770
|
+
const trimmedText = text.trim();
|
|
713
771
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
714
|
-
if (
|
|
715
|
-
|
|
772
|
+
if (trimmedText.startsWith('<')) {
|
|
773
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
774
|
+
`The file was not found at this path. Please:\n` +
|
|
775
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
776
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
777
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
778
|
+
`4. Try accessing the URL directly in your browser`;
|
|
779
|
+
console.error(errorMsg);
|
|
780
|
+
reject(new Error(errorMsg));
|
|
781
|
+
return; // Não continuar se for HTML
|
|
782
|
+
}
|
|
783
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
784
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
785
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
716
786
|
}
|
|
717
787
|
// Criar e carregar novo script
|
|
718
788
|
const script = document.createElement('script');
|
|
@@ -726,7 +796,7 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
726
796
|
resolve();
|
|
727
797
|
}
|
|
728
798
|
else {
|
|
729
|
-
reject(new Error(
|
|
799
|
+
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
800
|
}
|
|
731
801
|
}, 200);
|
|
732
802
|
};
|
|
@@ -741,7 +811,14 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
741
811
|
});
|
|
742
812
|
})
|
|
743
813
|
.catch(error => {
|
|
744
|
-
|
|
814
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
815
|
+
`Troubleshooting:\n` +
|
|
816
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
817
|
+
`2. Check browser console for CORS errors\n` +
|
|
818
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
819
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
820
|
+
console.error(errorMsg);
|
|
821
|
+
reject(new Error(errorMsg));
|
|
745
822
|
});
|
|
746
823
|
});
|
|
747
824
|
}
|
|
@@ -824,8 +901,14 @@ async function loadMp3LameEncoder(scriptUrl) {
|
|
|
824
901
|
// Tentar encontrar o arquivo automaticamente
|
|
825
902
|
const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
|
|
826
903
|
if (!foundPath) {
|
|
827
|
-
|
|
828
|
-
'Please
|
|
904
|
+
const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
|
|
905
|
+
'Please try one of the following:\n' +
|
|
906
|
+
'1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
|
|
907
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
908
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
909
|
+
'4. Check browser console for detailed path information';
|
|
910
|
+
console.error(errorMsg);
|
|
911
|
+
throw new Error(errorMsg);
|
|
829
912
|
}
|
|
830
913
|
scriptUrl = foundPath;
|
|
831
914
|
}
|
|
@@ -873,13 +956,31 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
873
956
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
874
957
|
.then(response => {
|
|
875
958
|
if (!response.ok) {
|
|
876
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
959
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
960
|
+
}
|
|
961
|
+
// Verificar Content-Type
|
|
962
|
+
const contentType = response.headers.get('content-type') || '';
|
|
963
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
964
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
877
965
|
}
|
|
878
966
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
879
967
|
return response.text().then(text => {
|
|
968
|
+
const trimmedText = text.trim();
|
|
880
969
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
881
|
-
if (
|
|
882
|
-
|
|
970
|
+
if (trimmedText.startsWith('<')) {
|
|
971
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
972
|
+
`The file was not found at this path. Please:\n` +
|
|
973
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
974
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
975
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
976
|
+
`4. Try accessing the URL directly in your browser`;
|
|
977
|
+
console.error(errorMsg);
|
|
978
|
+
reject(new Error(errorMsg));
|
|
979
|
+
return; // Não continuar se for HTML
|
|
980
|
+
}
|
|
981
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
982
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
983
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
883
984
|
}
|
|
884
985
|
// Criar e carregar novo script
|
|
885
986
|
const script = document.createElement('script');
|
|
@@ -893,7 +994,7 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
893
994
|
resolve();
|
|
894
995
|
}
|
|
895
996
|
else {
|
|
896
|
-
reject(new Error(
|
|
997
|
+
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
998
|
}
|
|
898
999
|
}, 200);
|
|
899
1000
|
};
|
|
@@ -908,7 +1009,14 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
908
1009
|
});
|
|
909
1010
|
})
|
|
910
1011
|
.catch(error => {
|
|
911
|
-
|
|
1012
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
1013
|
+
`Troubleshooting:\n` +
|
|
1014
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
1015
|
+
`2. Check browser console for CORS errors\n` +
|
|
1016
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
1017
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
1018
|
+
console.error(errorMsg);
|
|
1019
|
+
reject(new Error(errorMsg));
|
|
912
1020
|
});
|
|
913
1021
|
});
|
|
914
1022
|
}
|
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,41 +546,79 @@ function configureEncoderPaths(baseUrl) {
|
|
|
538
546
|
* Useful when auto-detection fails
|
|
539
547
|
*/
|
|
540
548
|
async function findEncoderPath(filename) {
|
|
549
|
+
// Obter base URL atual para construir caminhos relativos
|
|
550
|
+
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
551
|
+
const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
|
|
552
|
+
// Priorizar caminhos do node_modules primeiro
|
|
541
553
|
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
|
|
554
|
+
// Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
|
|
551
555
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
556
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
557
|
+
// Caminhos relativos do node_modules
|
|
552
558
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
553
559
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
554
|
-
|
|
560
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
561
|
+
`../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
562
|
+
// Com base no caminho atual
|
|
563
|
+
`${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
564
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
555
565
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
566
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
556
567
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
568
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
569
|
+
getEncoderScriptUrl(filename),
|
|
570
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
571
|
+
`/${filename}`,
|
|
572
|
+
`${currentOrigin}/${filename}`,
|
|
573
|
+
// Direct lib paths (for development or custom setups)
|
|
574
|
+
`/lib/${filename}`,
|
|
575
|
+
`${currentOrigin}/lib/${filename}`,
|
|
576
|
+
`./lib/${filename}`,
|
|
577
|
+
`../lib/${filename}`,
|
|
557
578
|
// CDN or absolute paths (if configured)
|
|
558
579
|
filename.startsWith('http') ? filename : null
|
|
559
580
|
].filter((path) => path !== null);
|
|
581
|
+
console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
|
|
560
582
|
// Try each path
|
|
561
|
-
for (
|
|
583
|
+
for (let i = 0; i < possiblePaths.length; i++) {
|
|
584
|
+
const path = possiblePaths[i];
|
|
562
585
|
try {
|
|
563
586
|
const testUrl = path.startsWith('http')
|
|
564
587
|
? path
|
|
565
588
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
566
|
-
|
|
589
|
+
console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
|
|
590
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
591
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
567
592
|
if (response.ok) {
|
|
568
|
-
|
|
593
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
594
|
+
const text = await response.text();
|
|
595
|
+
const trimmedText = text.trim();
|
|
596
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
597
|
+
if (trimmedText.startsWith('<')) {
|
|
598
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
// Se parece JavaScript, retornar este caminho
|
|
602
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
603
|
+
console.log(`[web-audio-recorder-ts] ✅ Found encoder file at: ${path}`);
|
|
604
|
+
return path;
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
|
|
569
612
|
}
|
|
570
613
|
}
|
|
571
614
|
catch (e) {
|
|
615
|
+
console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
|
|
572
616
|
// Continue to next path
|
|
573
617
|
continue;
|
|
574
618
|
}
|
|
575
619
|
}
|
|
620
|
+
console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
|
|
621
|
+
console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
|
|
576
622
|
return null;
|
|
577
623
|
}
|
|
578
624
|
|
|
@@ -654,8 +700,14 @@ async function loadOggVorbisEncoder(scriptUrl) {
|
|
|
654
700
|
// Tentar encontrar o arquivo automaticamente
|
|
655
701
|
const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
|
|
656
702
|
if (!foundPath) {
|
|
657
|
-
|
|
658
|
-
'Please
|
|
703
|
+
const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
|
|
704
|
+
'Please try one of the following:\n' +
|
|
705
|
+
'1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
|
|
706
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
707
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
708
|
+
'4. Check browser console for detailed path information';
|
|
709
|
+
console.error(errorMsg);
|
|
710
|
+
throw new Error(errorMsg);
|
|
659
711
|
}
|
|
660
712
|
scriptUrl = foundPath;
|
|
661
713
|
}
|
|
@@ -703,13 +755,31 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
703
755
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
704
756
|
.then(response => {
|
|
705
757
|
if (!response.ok) {
|
|
706
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
758
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
759
|
+
}
|
|
760
|
+
// Verificar Content-Type
|
|
761
|
+
const contentType = response.headers.get('content-type') || '';
|
|
762
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
763
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
707
764
|
}
|
|
708
765
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
709
766
|
return response.text().then(text => {
|
|
767
|
+
const trimmedText = text.trim();
|
|
710
768
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
711
|
-
if (
|
|
712
|
-
|
|
769
|
+
if (trimmedText.startsWith('<')) {
|
|
770
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
771
|
+
`The file was not found at this path. Please:\n` +
|
|
772
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
773
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
774
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
775
|
+
`4. Try accessing the URL directly in your browser`;
|
|
776
|
+
console.error(errorMsg);
|
|
777
|
+
reject(new Error(errorMsg));
|
|
778
|
+
return; // Não continuar se for HTML
|
|
779
|
+
}
|
|
780
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
781
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
782
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
713
783
|
}
|
|
714
784
|
// Criar e carregar novo script
|
|
715
785
|
const script = document.createElement('script');
|
|
@@ -723,7 +793,7 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
723
793
|
resolve();
|
|
724
794
|
}
|
|
725
795
|
else {
|
|
726
|
-
reject(new Error(
|
|
796
|
+
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
797
|
}
|
|
728
798
|
}, 200);
|
|
729
799
|
};
|
|
@@ -738,7 +808,14 @@ function loadOggVorbisEncoderInternal(scriptUrl) {
|
|
|
738
808
|
});
|
|
739
809
|
})
|
|
740
810
|
.catch(error => {
|
|
741
|
-
|
|
811
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
812
|
+
`Troubleshooting:\n` +
|
|
813
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
814
|
+
`2. Check browser console for CORS errors\n` +
|
|
815
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
816
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
817
|
+
console.error(errorMsg);
|
|
818
|
+
reject(new Error(errorMsg));
|
|
742
819
|
});
|
|
743
820
|
});
|
|
744
821
|
}
|
|
@@ -821,8 +898,14 @@ async function loadMp3LameEncoder(scriptUrl) {
|
|
|
821
898
|
// Tentar encontrar o arquivo automaticamente
|
|
822
899
|
const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
|
|
823
900
|
if (!foundPath) {
|
|
824
|
-
|
|
825
|
-
'Please
|
|
901
|
+
const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
|
|
902
|
+
'Please try one of the following:\n' +
|
|
903
|
+
'1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
|
|
904
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
905
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
906
|
+
'4. Check browser console for detailed path information';
|
|
907
|
+
console.error(errorMsg);
|
|
908
|
+
throw new Error(errorMsg);
|
|
826
909
|
}
|
|
827
910
|
scriptUrl = foundPath;
|
|
828
911
|
}
|
|
@@ -870,13 +953,31 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
870
953
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
871
954
|
.then(response => {
|
|
872
955
|
if (!response.ok) {
|
|
873
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
956
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
957
|
+
}
|
|
958
|
+
// Verificar Content-Type
|
|
959
|
+
const contentType = response.headers.get('content-type') || '';
|
|
960
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
961
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
874
962
|
}
|
|
875
963
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
876
964
|
return response.text().then(text => {
|
|
965
|
+
const trimmedText = text.trim();
|
|
877
966
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
878
|
-
if (
|
|
879
|
-
|
|
967
|
+
if (trimmedText.startsWith('<')) {
|
|
968
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
969
|
+
`The file was not found at this path. Please:\n` +
|
|
970
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
971
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
972
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
973
|
+
`4. Try accessing the URL directly in your browser`;
|
|
974
|
+
console.error(errorMsg);
|
|
975
|
+
reject(new Error(errorMsg));
|
|
976
|
+
return; // Não continuar se for HTML
|
|
977
|
+
}
|
|
978
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
979
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
980
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
880
981
|
}
|
|
881
982
|
// Criar e carregar novo script
|
|
882
983
|
const script = document.createElement('script');
|
|
@@ -890,7 +991,7 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
890
991
|
resolve();
|
|
891
992
|
}
|
|
892
993
|
else {
|
|
893
|
-
reject(new Error(
|
|
994
|
+
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
995
|
}
|
|
895
996
|
}, 200);
|
|
896
997
|
};
|
|
@@ -905,7 +1006,14 @@ function loadMp3LameEncoderInternal(scriptUrl) {
|
|
|
905
1006
|
});
|
|
906
1007
|
})
|
|
907
1008
|
.catch(error => {
|
|
908
|
-
|
|
1009
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
1010
|
+
`Troubleshooting:\n` +
|
|
1011
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
1012
|
+
`2. Check browser console for CORS errors\n` +
|
|
1013
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
1014
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
1015
|
+
console.error(errorMsg);
|
|
1016
|
+
reject(new Error(errorMsg));
|
|
909
1017
|
});
|
|
910
1018
|
});
|
|
911
1019
|
}
|
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,41 +553,79 @@
|
|
|
545
553
|
* Useful when auto-detection fails
|
|
546
554
|
*/
|
|
547
555
|
async function findEncoderPath(filename) {
|
|
556
|
+
// Obter base URL atual para construir caminhos relativos
|
|
557
|
+
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
558
|
+
const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
|
|
559
|
+
// Priorizar caminhos do node_modules primeiro
|
|
548
560
|
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
|
|
561
|
+
// Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
|
|
558
562
|
`/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
563
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
564
|
+
// Caminhos relativos do node_modules
|
|
559
565
|
`./node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
560
566
|
`../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
561
|
-
|
|
567
|
+
`../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
568
|
+
`../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
569
|
+
// Com base no caminho atual
|
|
570
|
+
`${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
|
|
571
|
+
// From dist (se os arquivos foram copiados para dist/lib)
|
|
562
572
|
`/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
573
|
+
`${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
563
574
|
`./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
|
|
575
|
+
// Auto-detected path (pode apontar para node_modules)
|
|
576
|
+
getEncoderScriptUrl(filename),
|
|
577
|
+
// Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
|
|
578
|
+
`/${filename}`,
|
|
579
|
+
`${currentOrigin}/${filename}`,
|
|
580
|
+
// Direct lib paths (for development or custom setups)
|
|
581
|
+
`/lib/${filename}`,
|
|
582
|
+
`${currentOrigin}/lib/${filename}`,
|
|
583
|
+
`./lib/${filename}`,
|
|
584
|
+
`../lib/${filename}`,
|
|
564
585
|
// CDN or absolute paths (if configured)
|
|
565
586
|
filename.startsWith('http') ? filename : null
|
|
566
587
|
].filter((path) => path !== null);
|
|
588
|
+
console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
|
|
567
589
|
// Try each path
|
|
568
|
-
for (
|
|
590
|
+
for (let i = 0; i < possiblePaths.length; i++) {
|
|
591
|
+
const path = possiblePaths[i];
|
|
569
592
|
try {
|
|
570
593
|
const testUrl = path.startsWith('http')
|
|
571
594
|
? path
|
|
572
595
|
: new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
|
|
573
|
-
|
|
596
|
+
console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
|
|
597
|
+
// Usar GET para verificar se é JavaScript válido (não HTML)
|
|
598
|
+
const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
|
|
574
599
|
if (response.ok) {
|
|
575
|
-
|
|
600
|
+
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
601
|
+
const text = await response.text();
|
|
602
|
+
const trimmedText = text.trim();
|
|
603
|
+
// Se começar com '<', é HTML (404, etc) - pular este caminho
|
|
604
|
+
if (trimmedText.startsWith('<')) {
|
|
605
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
// Se parece JavaScript, retornar este caminho
|
|
609
|
+
if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
|
|
610
|
+
console.log(`[web-audio-recorder-ts] ✅ Found encoder file at: ${path}`);
|
|
611
|
+
return path;
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
|
|
576
619
|
}
|
|
577
620
|
}
|
|
578
621
|
catch (e) {
|
|
622
|
+
console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
|
|
579
623
|
// Continue to next path
|
|
580
624
|
continue;
|
|
581
625
|
}
|
|
582
626
|
}
|
|
627
|
+
console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
|
|
628
|
+
console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
|
|
583
629
|
return null;
|
|
584
630
|
}
|
|
585
631
|
|
|
@@ -661,8 +707,14 @@
|
|
|
661
707
|
// Tentar encontrar o arquivo automaticamente
|
|
662
708
|
const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
|
|
663
709
|
if (!foundPath) {
|
|
664
|
-
|
|
665
|
-
'Please
|
|
710
|
+
const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
|
|
711
|
+
'Please try one of the following:\n' +
|
|
712
|
+
'1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
|
|
713
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
714
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
715
|
+
'4. Check browser console for detailed path information';
|
|
716
|
+
console.error(errorMsg);
|
|
717
|
+
throw new Error(errorMsg);
|
|
666
718
|
}
|
|
667
719
|
scriptUrl = foundPath;
|
|
668
720
|
}
|
|
@@ -710,13 +762,31 @@
|
|
|
710
762
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
711
763
|
.then(response => {
|
|
712
764
|
if (!response.ok) {
|
|
713
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
765
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
766
|
+
}
|
|
767
|
+
// Verificar Content-Type
|
|
768
|
+
const contentType = response.headers.get('content-type') || '';
|
|
769
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
770
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
714
771
|
}
|
|
715
772
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
716
773
|
return response.text().then(text => {
|
|
774
|
+
const trimmedText = text.trim();
|
|
717
775
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
718
|
-
if (
|
|
719
|
-
|
|
776
|
+
if (trimmedText.startsWith('<')) {
|
|
777
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
778
|
+
`The file was not found at this path. Please:\n` +
|
|
779
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
780
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
781
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
782
|
+
`4. Try accessing the URL directly in your browser`;
|
|
783
|
+
console.error(errorMsg);
|
|
784
|
+
reject(new Error(errorMsg));
|
|
785
|
+
return; // Não continuar se for HTML
|
|
786
|
+
}
|
|
787
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
788
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
789
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
720
790
|
}
|
|
721
791
|
// Criar e carregar novo script
|
|
722
792
|
const script = document.createElement('script');
|
|
@@ -730,7 +800,7 @@
|
|
|
730
800
|
resolve();
|
|
731
801
|
}
|
|
732
802
|
else {
|
|
733
|
-
reject(new Error(
|
|
803
|
+
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
804
|
}
|
|
735
805
|
}, 200);
|
|
736
806
|
};
|
|
@@ -745,7 +815,14 @@
|
|
|
745
815
|
});
|
|
746
816
|
})
|
|
747
817
|
.catch(error => {
|
|
748
|
-
|
|
818
|
+
const errorMsg = `Cannot access OggVorbisEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
819
|
+
`Troubleshooting:\n` +
|
|
820
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
821
|
+
`2. Check browser console for CORS errors\n` +
|
|
822
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
823
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
824
|
+
console.error(errorMsg);
|
|
825
|
+
reject(new Error(errorMsg));
|
|
749
826
|
});
|
|
750
827
|
});
|
|
751
828
|
}
|
|
@@ -828,8 +905,14 @@
|
|
|
828
905
|
// Tentar encontrar o arquivo automaticamente
|
|
829
906
|
const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
|
|
830
907
|
if (!foundPath) {
|
|
831
|
-
|
|
832
|
-
'Please
|
|
908
|
+
const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
|
|
909
|
+
'Please try one of the following:\n' +
|
|
910
|
+
'1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
|
|
911
|
+
'2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
|
|
912
|
+
'3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
|
|
913
|
+
'4. Check browser console for detailed path information';
|
|
914
|
+
console.error(errorMsg);
|
|
915
|
+
throw new Error(errorMsg);
|
|
833
916
|
}
|
|
834
917
|
scriptUrl = foundPath;
|
|
835
918
|
}
|
|
@@ -877,13 +960,31 @@
|
|
|
877
960
|
fetch(scriptUrl, { method: 'GET', cache: 'no-cache' })
|
|
878
961
|
.then(response => {
|
|
879
962
|
if (!response.ok) {
|
|
880
|
-
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText})
|
|
963
|
+
throw new Error(`File not found: ${scriptUrl} (${response.status} ${response.statusText}). Make sure the file exists and is accessible.`);
|
|
964
|
+
}
|
|
965
|
+
// Verificar Content-Type
|
|
966
|
+
const contentType = response.headers.get('content-type') || '';
|
|
967
|
+
if (!contentType.includes('javascript') && !contentType.includes('application/javascript') && !contentType.includes('text/javascript')) {
|
|
968
|
+
console.warn(`Warning: Content-Type is "${contentType}", expected JavaScript. Proceeding with validation...`);
|
|
881
969
|
}
|
|
882
970
|
// Verificar se o conteúdo é JavaScript (não HTML)
|
|
883
971
|
return response.text().then(text => {
|
|
972
|
+
const trimmedText = text.trim();
|
|
884
973
|
// Se começar com '<', provavelmente é HTML (erro 404, etc)
|
|
885
|
-
if (
|
|
886
|
-
|
|
974
|
+
if (trimmedText.startsWith('<')) {
|
|
975
|
+
const errorMsg = `Invalid response from ${scriptUrl}. Expected JavaScript but received HTML (likely a 404 error page).\n\n` +
|
|
976
|
+
`The file was not found at this path. Please:\n` +
|
|
977
|
+
`1. Verify the file exists at: ${scriptUrl}\n` +
|
|
978
|
+
`2. Check if you need to copy files to your public/ folder\n` +
|
|
979
|
+
`3. Ensure your server is configured to serve the file\n` +
|
|
980
|
+
`4. Try accessing the URL directly in your browser`;
|
|
981
|
+
console.error(errorMsg);
|
|
982
|
+
reject(new Error(errorMsg));
|
|
983
|
+
return; // Não continuar se for HTML
|
|
984
|
+
}
|
|
985
|
+
// Verificar se parece com JavaScript (contém pelo menos algumas palavras-chave comuns)
|
|
986
|
+
if (!trimmedText.includes('function') && !trimmedText.includes('var') && !trimmedText.includes('const') && !trimmedText.includes('let')) {
|
|
987
|
+
console.warn(`Warning: Response from ${scriptUrl} does not appear to be valid JavaScript.`);
|
|
887
988
|
}
|
|
888
989
|
// Criar e carregar novo script
|
|
889
990
|
const script = document.createElement('script');
|
|
@@ -897,7 +998,7 @@
|
|
|
897
998
|
resolve();
|
|
898
999
|
}
|
|
899
1000
|
else {
|
|
900
|
-
reject(new Error(
|
|
1001
|
+
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
1002
|
}
|
|
902
1003
|
}, 200);
|
|
903
1004
|
};
|
|
@@ -912,7 +1013,14 @@
|
|
|
912
1013
|
});
|
|
913
1014
|
})
|
|
914
1015
|
.catch(error => {
|
|
915
|
-
|
|
1016
|
+
const errorMsg = `Cannot access Mp3LameEncoder script at ${scriptUrl}: ${error.message}\n\n` +
|
|
1017
|
+
`Troubleshooting:\n` +
|
|
1018
|
+
`1. Open ${scriptUrl} in your browser to verify the file exists\n` +
|
|
1019
|
+
`2. Check browser console for CORS errors\n` +
|
|
1020
|
+
`3. Ensure your server is configured to serve files from node_modules or public folder\n` +
|
|
1021
|
+
`4. See TROUBLESHOOTING_ENCODER.md for more help`;
|
|
1022
|
+
console.error(errorMsg);
|
|
1023
|
+
reject(new Error(errorMsg));
|
|
916
1024
|
});
|
|
917
1025
|
});
|
|
918
1026
|
}
|
package/package.json
CHANGED