diff --git a/backend/src/app.js b/backend/src/app.js index 31513ae..ec21928 100644 --- a/backend/src/app.js +++ b/backend/src/app.js @@ -7,9 +7,9 @@ const cors = require("cors"); const sequelize = require("./database/"); const multer = require("multer"); -const wBot = require("./controllers/wbot"); -const wbotMessageListener = require("./controllers/wbotMessageListener"); -const wbotMonitor = require("./controllers/wbotMonitor"); +const wBot = require("./libs/wbot"); +const wbotMessageListener = require("./services/wbotMessageListener"); +const wbotMonitor = require("./services/wbotMonitor"); const messageRoutes = require("./routes/message"); const ContactRoutes = require("./routes/contacts"); diff --git a/backend/src/controllers/contact.js b/backend/src/controllers/contact.js index 1f73ffc..8784c00 100644 --- a/backend/src/controllers/contact.js +++ b/backend/src/controllers/contact.js @@ -2,7 +2,7 @@ const Contact = require("../models/Contact"); const Message = require("../models/Message"); const Sequelize = require("sequelize"); const { getIO } = require("../libs/socket"); -const { getWbot } = require("./wbot"); +const { getWbot } = require("../libs/wbot"); exports.getContacts = async (req, res) => { const { searchParam = "" } = req.query; diff --git a/backend/src/controllers/message.js b/backend/src/controllers/message.js index 1fca754..689b2e7 100644 --- a/backend/src/controllers/message.js +++ b/backend/src/controllers/message.js @@ -2,7 +2,7 @@ const fs = require("fs"); const Message = require("../models/Message"); const Contact = require("../models/Contact"); const { getIO } = require("../libs/socket"); -const { getWbot } = require("./wbot"); +const { getWbot } = require("../libs/wbot"); const Sequelize = require("sequelize"); const { MessageMedia } = require("whatsapp-web.js"); diff --git a/backend/src/controllers/whatsapp.js b/backend/src/controllers/whatsapp.js index a870ef0..6397c8e 100644 --- a/backend/src/controllers/whatsapp.js +++ b/backend/src/controllers/whatsapp.js @@ -1,6 +1,6 @@ const Whatsapp = require("../models/Whatsapp"); const { getIO } = require("../libs/socket"); -const { getWbot, init } = require("./wbot"); +const { getWbot, init } = require("../libs/wbot"); exports.getSession = async (req, res, next) => { const dbSession = await Whatsapp.findOne({ where: { id: 1 } }); diff --git a/backend/src/controllers/wbot.js b/backend/src/libs/wbot.js similarity index 100% rename from backend/src/controllers/wbot.js rename to backend/src/libs/wbot.js diff --git a/backend/src/public/1594209242031-blob b/backend/src/public/1594209242031-blob new file mode 100644 index 0000000..32d918d Binary files /dev/null and b/backend/src/public/1594209242031-blob differ diff --git a/backend/src/public/1594209495148-teste.mp3 b/backend/src/public/1594209495148-teste.mp3 new file mode 100644 index 0000000..3b5097c Binary files /dev/null and b/backend/src/public/1594209495148-teste.mp3 differ diff --git a/backend/src/public/1594209531928-teste.mp3 b/backend/src/public/1594209531928-teste.mp3 new file mode 100644 index 0000000..36dac9a Binary files /dev/null and b/backend/src/public/1594209531928-teste.mp3 differ diff --git a/backend/src/public/1594209575652-teste.mp3 b/backend/src/public/1594209575652-teste.mp3 new file mode 100644 index 0000000..e665406 Binary files /dev/null and b/backend/src/public/1594209575652-teste.mp3 differ diff --git a/backend/src/public/1594209640061-teste.mp3 b/backend/src/public/1594209640061-teste.mp3 new file mode 100644 index 0000000..0879c89 Binary files /dev/null and b/backend/src/public/1594209640061-teste.mp3 differ diff --git a/backend/src/public/1594209651878-teste.mp3 b/backend/src/public/1594209651878-teste.mp3 new file mode 100644 index 0000000..af4802e Binary files /dev/null and b/backend/src/public/1594209651878-teste.mp3 differ diff --git a/backend/src/public/1594209685379-teste.mp3 b/backend/src/public/1594209685379-teste.mp3 new file mode 100644 index 0000000..6547997 Binary files /dev/null and b/backend/src/public/1594209685379-teste.mp3 differ diff --git a/backend/src/public/1594209825576-1594209825495.mp3 b/backend/src/public/1594209825576-1594209825495.mp3 new file mode 100644 index 0000000..87b6a7a Binary files /dev/null and b/backend/src/public/1594209825576-1594209825495.mp3 differ diff --git a/backend/src/public/1594209876958-blob b/backend/src/public/1594209876958-blob new file mode 100644 index 0000000..09276ad Binary files /dev/null and b/backend/src/public/1594209876958-blob differ diff --git a/backend/src/public/1594209912038-blob b/backend/src/public/1594209912038-blob new file mode 100644 index 0000000..b04d54d Binary files /dev/null and b/backend/src/public/1594209912038-blob differ diff --git a/backend/src/public/1594210255048-1594210254935.mp3 b/backend/src/public/1594210255048-1594210254935.mp3 new file mode 100644 index 0000000..17911cd Binary files /dev/null and b/backend/src/public/1594210255048-1594210254935.mp3 differ diff --git a/backend/src/public/1594210385463-1594210385336.mp3 b/backend/src/public/1594210385463-1594210385336.mp3 new file mode 100644 index 0000000..c6eb22b Binary files /dev/null and b/backend/src/public/1594210385463-1594210385336.mp3 differ diff --git a/backend/src/public/1594210397628-1594210397504.mp3 b/backend/src/public/1594210397628-1594210397504.mp3 new file mode 100644 index 0000000..f31220f Binary files /dev/null and b/backend/src/public/1594210397628-1594210397504.mp3 differ diff --git a/backend/src/public/1594210516393-1594210516262.mp3 b/backend/src/public/1594210516393-1594210516262.mp3 new file mode 100644 index 0000000..ca45d60 Binary files /dev/null and b/backend/src/public/1594210516393-1594210516262.mp3 differ diff --git a/backend/src/public/1594210517298-1594210517175.mp3 b/backend/src/public/1594210517298-1594210517175.mp3 new file mode 100644 index 0000000..7acc917 Binary files /dev/null and b/backend/src/public/1594210517298-1594210517175.mp3 differ diff --git a/backend/src/public/1594210561179-1594210561047.mp3 b/backend/src/public/1594210561179-1594210561047.mp3 new file mode 100644 index 0000000..502260a Binary files /dev/null and b/backend/src/public/1594210561179-1594210561047.mp3 differ diff --git a/backend/src/public/1594210592808-1594210592630.mp3 b/backend/src/public/1594210592808-1594210592630.mp3 new file mode 100644 index 0000000..1202cf6 Binary files /dev/null and b/backend/src/public/1594210592808-1594210592630.mp3 differ diff --git a/backend/src/public/1594210622265-1594210621806.mp3 b/backend/src/public/1594210622265-1594210621806.mp3 new file mode 100644 index 0000000..4343f16 Binary files /dev/null and b/backend/src/public/1594210622265-1594210621806.mp3 differ diff --git a/backend/src/public/1594210693158-1594210692847.mp3 b/backend/src/public/1594210693158-1594210692847.mp3 new file mode 100644 index 0000000..aebe9eb Binary files /dev/null and b/backend/src/public/1594210693158-1594210692847.mp3 differ diff --git a/backend/src/public/1594210753855-1594210753417.mp3 b/backend/src/public/1594210753855-1594210753417.mp3 new file mode 100644 index 0000000..4e8f5ae Binary files /dev/null and b/backend/src/public/1594210753855-1594210753417.mp3 differ diff --git a/backend/src/public/1594210804127-1594210803692.mp3 b/backend/src/public/1594210804127-1594210803692.mp3 new file mode 100644 index 0000000..028e56f Binary files /dev/null and b/backend/src/public/1594210804127-1594210803692.mp3 differ diff --git a/backend/src/public/1594210900328-1594210900137.mp3 b/backend/src/public/1594210900328-1594210900137.mp3 new file mode 100644 index 0000000..b332e45 Binary files /dev/null and b/backend/src/public/1594210900328-1594210900137.mp3 differ diff --git a/backend/src/public/1594210942862-1594210942716.mp3 b/backend/src/public/1594210942862-1594210942716.mp3 new file mode 100644 index 0000000..339b733 Binary files /dev/null and b/backend/src/public/1594210942862-1594210942716.mp3 differ diff --git a/backend/src/public/1594211810591-1594211810395.mp3 b/backend/src/public/1594211810591-1594211810395.mp3 new file mode 100644 index 0000000..ac02974 Binary files /dev/null and b/backend/src/public/1594211810591-1594211810395.mp3 differ diff --git a/backend/src/public/1594212195029-1594212194768.mp3 b/backend/src/public/1594212195029-1594212194768.mp3 new file mode 100644 index 0000000..5f9b632 Binary files /dev/null and b/backend/src/public/1594212195029-1594212194768.mp3 differ diff --git a/backend/src/public/1594212253309-1594212253064.mp3 b/backend/src/public/1594212253309-1594212253064.mp3 new file mode 100644 index 0000000..ba6b004 Binary files /dev/null and b/backend/src/public/1594212253309-1594212253064.mp3 differ diff --git a/backend/src/public/1594212283618-1594212283365.mp3 b/backend/src/public/1594212283618-1594212283365.mp3 new file mode 100644 index 0000000..19cd5b1 Binary files /dev/null and b/backend/src/public/1594212283618-1594212283365.mp3 differ diff --git a/backend/src/public/1594212342578-1594212342312.mp3 b/backend/src/public/1594212342578-1594212342312.mp3 new file mode 100644 index 0000000..8d58bab Binary files /dev/null and b/backend/src/public/1594212342578-1594212342312.mp3 differ diff --git a/backend/src/public/1594212351722-1594212351494.mp3 b/backend/src/public/1594212351722-1594212351494.mp3 new file mode 100644 index 0000000..bfb4f8d Binary files /dev/null and b/backend/src/public/1594212351722-1594212351494.mp3 differ diff --git a/backend/src/public/1594212457467-1594212457219.mp3 b/backend/src/public/1594212457467-1594212457219.mp3 new file mode 100644 index 0000000..5981c83 Binary files /dev/null and b/backend/src/public/1594212457467-1594212457219.mp3 differ diff --git a/backend/src/controllers/wbotMessageListener.js b/backend/src/services/wbotMessageListener.js similarity index 94% rename from backend/src/controllers/wbotMessageListener.js rename to backend/src/services/wbotMessageListener.js index 4a1216a..b80beab 100644 --- a/backend/src/controllers/wbotMessageListener.js +++ b/backend/src/services/wbotMessageListener.js @@ -5,7 +5,7 @@ const path = require("path"); const fs = require("fs"); const { getIO } = require("../libs/socket"); -const { getWbot, init } = require("./wbot"); +const { getWbot, init } = require("../libs/wbot"); const wbotMessageListener = () => { const io = getIO(); diff --git a/backend/src/controllers/wbotMonitor.js b/backend/src/services/wbotMonitor.js similarity index 91% rename from backend/src/controllers/wbotMonitor.js rename to backend/src/services/wbotMonitor.js index edc744c..d56206f 100644 --- a/backend/src/controllers/wbotMonitor.js +++ b/backend/src/services/wbotMonitor.js @@ -2,7 +2,7 @@ const Whatsapp = require("../models/Whatsapp"); const wbotMessageListener = require("./wbotMessageListener"); const { getIO } = require("../libs/socket"); -const { getWbot, init } = require("./wbot"); +const { getWbot, init } = require("../libs/wbot"); const wbotMonitor = () => { const io = getIO(); diff --git a/frontend/src/pages/Chat/components/MessagesInput/MessagesInput.js b/frontend/src/pages/Chat/components/MessagesInput/MessagesInput.js index c8c7a55..a1c644d 100644 --- a/frontend/src/pages/Chat/components/MessagesInput/MessagesInput.js +++ b/frontend/src/pages/Chat/components/MessagesInput/MessagesInput.js @@ -80,6 +80,11 @@ const useStyles = makeStyles(theme => ({ marginLeft: -12, }, + audioLoading: { + color: green[500], + opacity: "70%", + }, + recorderWrapper: { display: "flex", alignItems: "center", @@ -108,7 +113,6 @@ const MessagesInput = ({ searchParam }) => { const [loading, setLoading] = useState(false); const [recording, setRecording] = useState(false); - const [blobURL, setBlobURL] = useState(""); useEffect(() => { return () => { @@ -167,6 +171,7 @@ const MessagesInput = ({ searchParam }) => { const handleSendMessage = async () => { if (inputMessage.trim() === "") return; + setLoading(true); const message = { read: 1, userId: userId, @@ -180,9 +185,10 @@ const MessagesInput = ({ searchParam }) => { } setInputMessage(""); setShowEmoji(false); + setLoading(false); }; - const startRecording = () => { + const handleStartRecording = () => { navigator.getUserMedia( { audio: true }, () => { @@ -198,17 +204,40 @@ const MessagesInput = ({ searchParam }) => { ); }; - const stopRecording = () => { + const handleUploadAudio = () => { + setLoading(true); Mp3Recorder.stop() .getMp3() - .then(([buffer, blob]) => { - const blobURL = URL.createObjectURL(blob); - setBlobURL(blobURL); + .then(async ([buffer, blob]) => { + if (blob.size < 10000) { + setLoading(false); + setRecording(false); + return; + } + const formData = new FormData(); + const filename = `${new Date().getTime()}.mp3`; + console.log(blob); + formData.append("media", blob, filename); + formData.append("messageBody", filename); + formData.append("userId", userId); + try { + await api.post(`/messages/${contactId}`, formData); + } catch (err) { + console.log(err); + alert(err); + } setRecording(false); + setLoading(false); }) .catch(e => console.log(e)); }; + const handleCancelAudio = () => { + Mp3Recorder.stop() + .getMp3() + .then(() => setRecording(false)); + }; + if (media.preview) return ( { else { return ( -