Fixed audio recording issues (#310)
This commit is contained in:
parent
f61a57bb30
commit
3b278f47ce
|
@ -36,6 +36,7 @@ export default class extends React.PureComponent {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.recordingCanceled = false;
|
this.recordingCanceled = false;
|
||||||
|
this.recording = true;
|
||||||
this.state = {
|
this.state = {
|
||||||
currentTime: '00:00'
|
currentTime: '00:00'
|
||||||
};
|
};
|
||||||
|
@ -65,6 +66,12 @@ export default class extends React.PureComponent {
|
||||||
AudioRecorder.startRecording();
|
AudioRecorder.startRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.recording) {
|
||||||
|
this.cancelAudioMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_finishRecording(didSucceed, filePath) {
|
_finishRecording(didSucceed, filePath) {
|
||||||
if (!didSucceed) {
|
if (!didSucceed) {
|
||||||
return this.props.onFinish && this.props.onFinish(didSucceed);
|
return this.props.onFinish && this.props.onFinish(didSucceed);
|
||||||
|
@ -81,6 +88,7 @@ export default class extends React.PureComponent {
|
||||||
|
|
||||||
finishAudioMessage = async() => {
|
finishAudioMessage = async() => {
|
||||||
try {
|
try {
|
||||||
|
this.recording = false;
|
||||||
const filePath = await AudioRecorder.stopRecording();
|
const filePath = await AudioRecorder.stopRecording();
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
this._finishRecording(true, filePath);
|
this._finishRecording(true, filePath);
|
||||||
|
@ -92,6 +100,7 @@ export default class extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelAudioMessage = async() => {
|
cancelAudioMessage = async() => {
|
||||||
|
this.recording = false;
|
||||||
this.recordingCanceled = true;
|
this.recordingCanceled = true;
|
||||||
await AudioRecorder.stopRecording();
|
await AudioRecorder.stopRecording();
|
||||||
return this._finishRecording(false);
|
return this._finishRecording(false);
|
||||||
|
@ -113,7 +122,7 @@ export default class extends React.PureComponent {
|
||||||
accessibilityTraits='button'
|
accessibilityTraits='button'
|
||||||
onPress={this.cancelAudioMessage}
|
onPress={this.cancelAudioMessage}
|
||||||
/>
|
/>
|
||||||
<Text key='currentTime' style={[styles.textBoxInput, { width: 50, height: 60 }]}>{this.state.currentTime}</Text>
|
<Text key='currentTime' style={styles.textBoxInput}>{this.state.currentTime}</Text>
|
||||||
<Icon
|
<Icon
|
||||||
style={[styles.actionButtons, { color: 'green' }]}
|
style={[styles.actionButtons, { color: 'green' }]}
|
||||||
name='check'
|
name='check'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { View, TextInput, FlatList, Text, TouchableOpacity } from 'react-native';
|
import { View, TextInput, FlatList, Text, TouchableOpacity, Alert } from 'react-native';
|
||||||
import Icon from 'react-native-vector-icons/MaterialIcons';
|
import Icon from 'react-native-vector-icons/MaterialIcons';
|
||||||
import ImagePicker from 'react-native-image-picker';
|
import ImagePicker from 'react-native-image-picker';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
@ -209,12 +209,19 @@ export default class MessageBox extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
finishAudioMessage = async(fileInfo) => {
|
finishAudioMessage = async(fileInfo) => {
|
||||||
if (fileInfo) {
|
|
||||||
RocketChat.sendFileMessage(this.props.rid, fileInfo);
|
|
||||||
}
|
|
||||||
this.setState({
|
this.setState({
|
||||||
recording: false
|
recording: false
|
||||||
});
|
});
|
||||||
|
if (fileInfo) {
|
||||||
|
try {
|
||||||
|
await RocketChat.sendFileMessage(this.props.rid, fileInfo);
|
||||||
|
} catch (e) {
|
||||||
|
if (e && e.error === 'error-file-too-large') {
|
||||||
|
return Alert.alert('File is too large!');
|
||||||
|
}
|
||||||
|
log('finishAudioMessage', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeEmoji() {
|
closeEmoji() {
|
||||||
|
|
|
@ -615,7 +615,7 @@ const RocketChat = {
|
||||||
return call('sendFileMessage', rid, null, data, msg);
|
return call('sendFileMessage', rid, null, data, msg);
|
||||||
},
|
},
|
||||||
async sendFileMessage(rid, fileInfo, data) {
|
async sendFileMessage(rid, fileInfo, data) {
|
||||||
const placeholder = RocketChat.getMessage(rid, 'Sending a file');
|
let placeholder;
|
||||||
try {
|
try {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = await RNFetchBlob.wrap(fileInfo.path);
|
data = await RNFetchBlob.wrap(fileInfo.path);
|
||||||
|
@ -624,6 +624,15 @@ const RocketChat = {
|
||||||
fileInfo.name = fileStat.filename;
|
fileInfo.name = fileStat.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { FileUpload_MaxFileSize } = reduxStore.getState().settings;
|
||||||
|
|
||||||
|
// -1 maxFileSize means there is no limit
|
||||||
|
if (FileUpload_MaxFileSize > -1 && fileInfo.size > FileUpload_MaxFileSize) {
|
||||||
|
return Promise.reject({ error: 'error-file-too-large' }); // eslint-disable-line
|
||||||
|
}
|
||||||
|
|
||||||
|
placeholder = RocketChat.getMessage(rid, 'Sending a file');
|
||||||
|
|
||||||
const result = await RocketChat._ufsCreate({ ...fileInfo, rid });
|
const result = await RocketChat._ufsCreate({ ...fileInfo, rid });
|
||||||
await RNFetchBlob.fetch('POST', result.url, {
|
await RNFetchBlob.fetch('POST', result.url, {
|
||||||
'Content-Type': 'application/octet-stream'
|
'Content-Type': 'application/octet-stream'
|
||||||
|
@ -643,10 +652,12 @@ const RocketChat = {
|
||||||
} finally {
|
} finally {
|
||||||
// TODO: fix that
|
// TODO: fix that
|
||||||
try {
|
try {
|
||||||
database.write(() => {
|
if (placeholder) {
|
||||||
const msg = database.objects('messages').filtered('_id = $0', placeholder._id);
|
database.write(() => {
|
||||||
database.delete(msg);
|
const msg = database.objects('messages').filtered('_id = $0', placeholder._id);
|
||||||
});
|
database.delete(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue