forked from goodatlas/react-native-audio-record
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (19 loc) · 670 Bytes
/
index.js
File metadata and controls
24 lines (19 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { NativeModules, NativeEventEmitter } from 'react-native';
const { RNAudioRecord } = NativeModules;
const EventEmitter = new NativeEventEmitter(RNAudioRecord);
const AudioRecord = {};
AudioRecord.init = options => RNAudioRecord.init(options);
AudioRecord.start = () => RNAudioRecord.start();
AudioRecord.stop = () => RNAudioRecord.stop();
const eventsMap = {
data: 'data'
};
AudioRecord.on = (event, callback) => {
const nativeEvent = eventsMap[event];
if (!nativeEvent) {
throw new Error('Invalid event');
}
EventEmitter.removeAllListeners(nativeEvent);
return EventEmitter.addListener(nativeEvent, callback);
};
export default AudioRecord;