I call them needles 🪡
injecting 💉a function to return a function
Fixed bugs
...
This commit is contained in:
parent
0bebb60f19
commit
da09ab1469
3 changed files with 31 additions and 13 deletions
|
@ -14,6 +14,7 @@ function AttachmentFrame({
|
||||||
attachmentOrUi,
|
attachmentOrUi,
|
||||||
fileSetter,
|
fileSetter,
|
||||||
uploadProgressRef,
|
uploadProgressRef,
|
||||||
|
cancelNeedle,
|
||||||
}) {
|
}) {
|
||||||
function fileAttachedIndicator() {
|
function fileAttachedIndicator() {
|
||||||
console.log(attachmentOrUi.type);
|
console.log(attachmentOrUi.type);
|
||||||
|
@ -43,6 +44,7 @@ function AttachmentFrame({
|
||||||
let initStop;
|
let initStop;
|
||||||
const fnInitStop = (func) => {
|
const fnInitStop = (func) => {
|
||||||
initStop = func;
|
initStop = func;
|
||||||
|
cancelNeedle(initStop);
|
||||||
};
|
};
|
||||||
let requestResult;
|
let requestResult;
|
||||||
const fnRequestResult = (func) => {
|
const fnRequestResult = (func) => {
|
||||||
|
@ -52,6 +54,7 @@ function AttachmentFrame({
|
||||||
const fnHowToSubmit = (func) => {
|
const fnHowToSubmit = (func) => {
|
||||||
submission = func;
|
submission = func;
|
||||||
console.log(submission);
|
console.log(submission);
|
||||||
|
fileSetter(submission);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If there already is an attachment, show it
|
// If there already is an attachment, show it
|
||||||
|
@ -73,7 +76,6 @@ function AttachmentFrame({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachmentFrame();
|
return attachmentFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +83,7 @@ AttachmentFrame.propTypes = {
|
||||||
attachmentOrUi: PropTypes.node.isRequired,
|
attachmentOrUi: PropTypes.node.isRequired,
|
||||||
fileSetter: PropTypes.func.isRequired,
|
fileSetter: PropTypes.func.isRequired,
|
||||||
uploadProgressRef: PropTypes.node.isRequired,
|
uploadProgressRef: PropTypes.node.isRequired,
|
||||||
|
cancelNeedle: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AttachmentFrame;
|
export default AttachmentFrame;
|
||||||
|
|
|
@ -50,6 +50,8 @@ function RoomViewInput({
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const { roomsInput } = initMatrix;
|
const { roomsInput } = initMatrix;
|
||||||
|
|
||||||
|
let cancelAttachmentCmd;
|
||||||
|
|
||||||
function requestFocusInput() {
|
function requestFocusInput() {
|
||||||
if (textAreaRef === null) return;
|
if (textAreaRef === null) return;
|
||||||
textAreaRef.current.focus();
|
textAreaRef.current.focus();
|
||||||
|
@ -296,6 +298,8 @@ function RoomViewInput({
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAttachmentTypeSelectorReturn = (ret) => {
|
const handleAttachmentTypeSelectorReturn = (ret) => {
|
||||||
|
if (cancelAttachmentCmd) cancelAttachmentCmd();
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case attachmentUiFrameTypes.none:
|
case attachmentUiFrameTypes.none:
|
||||||
setAttachmentOrUi(attachmentUiFrameTypes.none);
|
setAttachmentOrUi(attachmentUiFrameTypes.none);
|
||||||
|
@ -397,8 +401,13 @@ function RoomViewInput({
|
||||||
uploadProgressRef={uploadProgressRef}
|
uploadProgressRef={uploadProgressRef}
|
||||||
fileSetter={(blob) => {
|
fileSetter={(blob) => {
|
||||||
setAttachmentOrUi(blob);
|
setAttachmentOrUi(blob);
|
||||||
|
console.log(blob);
|
||||||
roomsInput.setAttachment(roomId, blob);
|
roomsInput.setAttachment(roomId, blob);
|
||||||
}}
|
}}
|
||||||
|
cancelNeedle={(cmd) => {
|
||||||
|
cancelAttachmentCmd = cmd;
|
||||||
|
console.log(cmd);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) }
|
) }
|
||||||
<form className="room-input" onSubmit={(e) => { e.preventDefault(); }}>
|
<form className="room-input" onSubmit={(e) => { e.preventDefault(); }}>
|
||||||
|
|
|
@ -55,24 +55,26 @@ function startOrResumeRec() {
|
||||||
}
|
}
|
||||||
function restartRec() {
|
function restartRec() {
|
||||||
if (_mediaRecorder.state !== 'inactive') _mediaRecorder.stop();
|
if (_mediaRecorder.state !== 'inactive') _mediaRecorder.stop();
|
||||||
audioChunks.length = 0;
|
|
||||||
|
_mediaRecorder = null;
|
||||||
|
init();
|
||||||
|
|
||||||
startOrResumeRec();
|
startOrResumeRec();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle turning off the recorder to remove the browser indicator
|
// TODO: Handle turning off the recorder to remove the browser indicator
|
||||||
function VoiceMailRecorder({ fnCancel, fnRequestResult, fnHowToSubmit }) {
|
function VoiceMailRecorder({ fnCancel, fnRequestResult, fnHowToSubmit }) {
|
||||||
const [state, setState] = React.useState('unknown');
|
const [state, setState] = React.useState('unknown');
|
||||||
const [duration, setDuraction] = React.useState('unknown');
|
|
||||||
|
|
||||||
async function initiateInitiation() {
|
async function initiateInitiation() {
|
||||||
if (!_mediaRecorder) {
|
if (!_mediaRecorder) {
|
||||||
await init();
|
await init();
|
||||||
startOrResumeRec();
|
startOrResumeRec();
|
||||||
}
|
}
|
||||||
_mediaRecorder.onstop = () => setState('stopped');
|
_mediaRecorder.onstop = () => setState('Recording stopped');
|
||||||
_mediaRecorder.onstart = () => setState('started');
|
_mediaRecorder.onstart = () => setState('Recording...');
|
||||||
_mediaRecorder.onpause = () => setState('paused');
|
_mediaRecorder.onpause = () => setState('Recording paused');
|
||||||
_mediaRecorder.onresume = () => setState('resumed');
|
_mediaRecorder.onresume = () => setState('Recording...');
|
||||||
}
|
}
|
||||||
initiateInitiation();
|
initiateInitiation();
|
||||||
|
|
||||||
|
@ -81,11 +83,16 @@ function VoiceMailRecorder({ fnCancel, fnRequestResult, fnHowToSubmit }) {
|
||||||
|
|
||||||
_stream.getTracks().forEach((track) => track.stop());
|
_stream.getTracks().forEach((track) => track.stop());
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
_mediaRecorder = null;
|
||||||
|
_stream = null;
|
||||||
|
|
||||||
const opts = { type: 'audio/webm' };
|
const opts = { type: 'audio/webm' };
|
||||||
const audioBlob = new Blob(audioChunks, opts);
|
const audioBlob = new Blob(audioChunks, opts);
|
||||||
|
console.log('audioBlob', audioBlob);
|
||||||
const audioFile = new File([audioBlob], 'voicemail.webm', opts);
|
const audioFile = new File([audioBlob], 'voicemail.webm', opts);
|
||||||
fnHowToSubmit(audioFile);
|
fnHowToSubmit(audioFile);
|
||||||
|
}, 300); // TODO: Fix this hack, stop does not mean dataavailable but its going to happen soon
|
||||||
}
|
}
|
||||||
fnCancel(stopAndSubmit);
|
fnCancel(stopAndSubmit);
|
||||||
fnRequestResult(stopAndSubmit);
|
fnRequestResult(stopAndSubmit);
|
||||||
|
@ -97,10 +104,9 @@ function VoiceMailRecorder({ fnCancel, fnRequestResult, fnHowToSubmit }) {
|
||||||
</div>
|
</div>
|
||||||
<div className="room-attachment__info">
|
<div className="room-attachment__info">
|
||||||
<Text variant="b1">
|
<Text variant="b1">
|
||||||
Recording...
|
|
||||||
{state}
|
{state}
|
||||||
</Text>
|
</Text>
|
||||||
<Text variant="b3">{`for: ${duration}`}</Text>
|
<Text variant="b3">for some time maybe?</Text>
|
||||||
<IconButton onClick={pauseRec} src={PauseIC}>Pause</IconButton>
|
<IconButton onClick={pauseRec} src={PauseIC}>Pause</IconButton>
|
||||||
<IconButton onClick={startOrResumeRec} src={PlayIC}>Start</IconButton>
|
<IconButton onClick={startOrResumeRec} src={PlayIC}>Start</IconButton>
|
||||||
<IconButton onClick={restartRec} src={ArrowIC}>Reset</IconButton>
|
<IconButton onClick={restartRec} src={ArrowIC}>Reset</IconButton>
|
||||||
|
|
Loading…
Reference in a new issue