From 355284bbf46e25a65517b2a6bccdb3a3d36c8354 Mon Sep 17 00:00:00 2001 From: duckietm Date: Fri, 15 Mar 2024 10:23:33 +0100 Subject: [PATCH] Start: working on Chat --- public/ui-config.json.example | 1 + .../room/widgets/chat-input/ChatInputView.tsx | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/public/ui-config.json.example b/public/ui-config.json.example index 72f1ffb..8218380 100644 --- a/public/ui-config.json.example +++ b/public/ui-config.json.example @@ -26,6 +26,7 @@ "game.center.enabled": false, "guides.enabled": true, "toolbar.hide.quests": true, + "api.sound.upload": "/chatvoice/upload.php", "navigator.room.models": [ { "clubLevel": 0, "tileSize": 104, "name": "a" }, { "clubLevel": 0, "tileSize": 94, "name": "b" }, diff --git a/src/components/room/widgets/chat-input/ChatInputView.tsx b/src/components/room/widgets/chat-input/ChatInputView.tsx index cf07fe3..fdd9676 100644 --- a/src/components/room/widgets/chat-input/ChatInputView.tsx +++ b/src/components/room/widgets/chat-input/ChatInputView.tsx @@ -29,14 +29,14 @@ export const ChatInputView: FC<{}> = props => var deletedAudio = false; - function startRecording(){ - + function startRecording() { + if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { microphoneOn.style.display = "none"; microphoneOff.style.display = "inline-block"; deleteAudio.style.display = "inline-block"; - - navigator.mediaDevices.getUserMedia({audio:true}) - .then(stream=> { + + navigator.mediaDevices.getUserMedia({ audio: true }) + .then(stream => { mediaRecorder = new MediaRecorder(stream); mediaRecorder.start(); @@ -49,23 +49,27 @@ export const ChatInputView: FC<{}> = props => microphoneOff.style.display = "none"; deleteAudio.style.display = "none"; - if(!deletedAudio){ + if (!deletedAudio) { const audioBlob = new Blob(audioChunks); - var fd = new FormData(); - fd.append("audio", audioBlob); - fetch("https://int.habbeh.net/audio.php", {method:"POST", body: fd}) - .then((response) => response.text()) - .then((resp) => { - roomSession.sendChatMessage("https://int.habbeh.net/audios/" + resp + ".mp3",0); - }) - + var fd = new FormData(); + fd.append("audio", audioBlob); + fetch(GetConfiguration('api.sound.url'), { method: "POST", body: fd }) + .then((response) => response.text()) + .then((resp) => { + roomSession.sendChatMessage(GetConfiguration('api.sound.upload') + resp + ".mp3", 0); + }) } - deletedAudio = false; audioChunks = []; }); }) - } + .catch(error => { + console.error('Error accessing microphone:', error); + }); + } else { + console.error('getUserMedia is not supported'); + } + } function stopRecording(){ microphoneOn.style.display = "inline-block";