Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consertando o problema de reprodução de áudio em iOS TWF-82 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pedrolucasfv
Copy link

@pedrolucasfv pedrolucasfv commented Jul 27, 2023

O problema ocorria porque no iPhone não reproduzia o formato de áudio (.ogg) gravado através do MediaRecorder do navegador . Foi adicionado um backend que permite a conversão do tipo de áudio para ser aceito no iOS, porém, isso trouxe outros problemas como o tempo gasto quando o áudio é descartado (apertar o botão de cancelar), então foram feitas modificações para resolver esses problemas, por exemplo, adicionando um loading. Como já estava sendo feito alterações nesse trecho de código, aproveitamos para estilizar os botões e deixá-los mais atraentes para o usuário. Com todas essas alterações, agora o gravador funciona em todos os navegadores.

export const fetchConvertAudio = async (blob: Blob) => {
const audioData = await blobToBase64(blob);

const apiUrl = "http://localhost:3001/features/send-wa-audio/convert-audio";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisamos usar uma variável de ambiente aqui

if (chunks.length === 0) return;

const blob = new Blob(chunks, { type: "audio/wav" });
const mp3Blob = await fetchConvertAudio(blob);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltou implementar tratamento de erros no fetchConvertAudio.


const triggerConvertAndSave = useCallback(() => {
if (convertAndSaveAudioRef.current) {
setIsLoading(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setIsLoading(true) poderia ser movido para dentro do método convertAndSaveAudioRef?

if (recorder && recorder.state === "inactive") {
recorder.start();

recorder.ondataavailable = (e: MediaRecorderEvent) => {
recorder.ondataavailable = async (e: MediaRecorderEvent) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pq temos esse async aqui?

Comment on lines 31 to 33
setTimeout(() => {
convertAndSaveAudioRef.current && convertAndSaveAudioRef.current();
}, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não entendi o objetivo dessa parte. A função é chamada na linha 30 e depois é chamada aqui novamente com um delay de 500ms? Pq isso é necessário?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbm nao entendi!!

cancelRecording: () => {
setRecorderState(initialState);
},
saveRecording: () => triggerConvertAndSave(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui vc não poderia chamar diretamente convertAndSaveAudioRef.current() ?
Pq precisa dessa trigger com useCallback?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O convertAndSaveAudioRef.current() funciona apenas para leitura. Já no caso do useCallback ele foi usado para garantir que, sempre que triggerConvertAndSave e outras funções fossem referenciadas ou chamadas, elas teriam a mesma referência entre re-renderizações, a menos que suas dependências mudassem. Isso ajuda a evitar re-renderizações desnecessárias.

if: () => isFirefox
}
// {
// if: () => isFirefox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bora remover esse código comentado aqui


export const ControlsContainer = styled('div')`
export const ControlsContainer = styled("div")`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parece q todas as aspas simples foram trocadas por duplas e ponto-e-virgulas adicionados no final das linhas.

sera q a config do prettier ta com problema?

Copy link
Author

@pedrolucasfv pedrolucasfv Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O commit do pigs também estava com aspas duplas, então aparetemente não está funcionando. Mas vamos subir um commit com alterações aqui.

Comment on lines 31 to 33
setTimeout(() => {
convertAndSaveAudioRef.current && convertAndSaveAudioRef.current();
}, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbm nao entendi!!

})
typeof recordingInterval === "number" && clearInterval(recordingInterval);
};
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pq a gente nao tem o array de dependencias aqui nesse useEffect? a gente quer mesmo executar ele em cada re-renderização?? nao faz sentido pra mim =/

Copy link
Author

@pedrolucasfv pedrolucasfv Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ele é o cara que conta o tempo de áudio, como ele precisa contar os segundos, então faz sentido executar ele em cada rederização, não?

Signed-off-by: Gabriel Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants