diff --git a/src/app/organisms/room/AttachmentTypeSelector.jsx b/src/app/organisms/room/AttachmentTypeSelector.jsx index e849fd97..0c8627b2 100644 --- a/src/app/organisms/room/AttachmentTypeSelector.jsx +++ b/src/app/organisms/room/AttachmentTypeSelector.jsx @@ -9,7 +9,6 @@ const AttachmentTypes = { remove: 'remove', file: 'file', voice: 'voice', - currentLocation: 'currentLocation', }; function AttachmentTypeSelector({ alreadyHasAttachment, actOnAttaching }) { diff --git a/src/app/organisms/room/VoiceMailRecorder.jsx b/src/app/organisms/room/VoiceMailRecorder.jsx new file mode 100644 index 00000000..4bab8f3a --- /dev/null +++ b/src/app/organisms/room/VoiceMailRecorder.jsx @@ -0,0 +1,66 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import Text from '../../atoms/text/Text'; +import RawIcon from '../../atoms/system-icons/RawIcon'; +import VolumeFullIC from '../../../../public/res/ic/outlined/volume-full.svg'; + +function VoiceMailRecorder({ returnedFileHandler }) { + let mediaRecorder; + + const recordVoice = () => { + console.log('record voice, new recorder'); + // TODO: Check if supported + // navigator.getUserMedia = navigator.getUserMedia + // || navigator.webkitGetUserMedia + // || navigator.mozGetUserMedia + // || navigator.msGetUserMedia; + + navigator.mediaDevices.getUserMedia({ audio: true }) + .then((stream) => { + mediaRecorder = new MediaRecorder(stream); + mediaRecorder.start(); + const audioChunks = []; + + mediaRecorder.addEventListener('dataavailable', (event) => { + audioChunks.push(event.data); + }); + mediaRecorder.addEventListener('error', (error) => { + console.log(error); + mediaRecorder.stop(); + }); + mediaRecorder.addEventListener('stop', () => { + const opts = { type: 'audio/webm' }; + const audioBlob = new Blob(audioChunks, opts); + + const audioFile = new File([audioBlob], 'voicemail.webm', opts); + returnedFileHandler(audioFile); + }); + + setTimeout(() => { + mediaRecorder.stop(); + }, 5000); // 1 hour 3600000 + }) + .catch(console.log); + }; + + recordVoice(); + + return ( +