UNPKG

@fugood/react-native-audio-pcm-stream

Version:
25 lines (19 loc) 711 B
import { NativeModules, NativeEventEmitter } from 'react-native'; const { RNLiveAudioStream } = NativeModules; const EventEmitter = RNLiveAudioStream && new NativeEventEmitter(RNLiveAudioStream); const AudioRecord = {}; AudioRecord.init = options => RNLiveAudioStream.init(options); AudioRecord.start = () => RNLiveAudioStream.start(); AudioRecord.stop = () => RNLiveAudioStream.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;