-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
47 lines (44 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Platform, NativeEventEmitter, NativeModules, PermissionsAndroid } from 'react-native';
const { RNQuiet } = NativeModules;
const nativeEventEmitter = new NativeEventEmitter(
RNQuiet,
);
export default {
...RNQuiet,
start: (key) => {
if (Platform.OS === 'android') {
return Promise
.resolve()
.then(
() => {
return PermissionsAndroid
.request(
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
)
.then(
(result) => {
if (result === PermissionsAndroid.RESULTS.GRANTED) {
return RNQuiet
.start(key);
}
return Promise
.reject(
new Error(
'RNQuiet: Unable to start, because we\'re missing the microphone permission.',
),
);
},
);
},
);
}
return Promise
.resolve()
.then(() => RNQuiet.start(key));
},
addListener: listener => nativeEventEmitter
.addListener(
"onMessageReceived",
listener,
),
};