Last active
August 16, 2022 04:16
-
-
Save ashraf2047/d9fc6639cbb1ba1e05e041ca59fac125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| initRecorder = async () => { | |
| navigator.getUserMedia = | |
| navigator.getUserMedia || | |
| navigator.webkitGetUserMedia || | |
| navigator.mozGetUserMedia || | |
| navigator.msGetUserMedia; | |
| if (navigator.mediaDevices) { | |
| const s = await navigator.mediaDevices.getUserMedia({ | |
| audio: true, | |
| }); | |
| this.mediaRecorder = new MediaRecorder(s); | |
| this.chunks = []; | |
| this.mediaRecorder.ondataavailable = (e) => { | |
| if (e.data && e.data.size > 0) { | |
| this.chunks.push(e.data); | |
| } | |
| }; | |
| this.stream = s; | |
| this.mediaRecorder.addEventListener("stop", () => { | |
| this.setStream(null); | |
| }); | |
| } | |
| }; | |
| export const uploadAudioToS3 = async ( | |
| postId, | |
| userId, | |
| blob, | |
| redirect = false | |
| ) => { | |
| s3.upload( | |
| { | |
| Bucket: "test", | |
| Body: blob, | |
| Key: `${userId}/${postId}.mp3`, | |
| ContentType: "audio/mp3", | |
| }, | |
| function (err, data) { | |
| if (err) { | |
| console.log(err); | |
| } else if (redirect) { | |
| // reload and redirect to explore page. | |
| window.location.href = "/explore"; | |
| } | |
| } | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment