@@ -3,80 +3,89 @@ import { NativeModules,Platform, NetInfo } from 'react-native';
3
3
4
4
const { RNNeteaseIm, PinYin } = NativeModules ;
5
5
6
- class Utils {
6
+ class Utils {
7
7
/**
8
8
* 清除数据缓存
9
9
*/
10
- cleanCache ( ) {
10
+ cleanCache ( ) {
11
11
return RNNeteaseIm . cleanCache ( ) ;
12
12
}
13
13
14
14
/**
15
15
* 获取缓存大小
16
16
*/
17
- getCacheSize ( ) {
17
+ getCacheSize ( ) {
18
18
return RNNeteaseIm . getCacheSize ( ) ;
19
19
}
20
20
21
21
/**
22
22
* 获取网络状态
23
23
*/
24
- networkIsConnected ( ) { //0:无网络,1:有网络
25
- if ( Platform . OS === 'ios' ) {
26
- if ( RNNeteaseIm . getNetWorkStatus ( ) === '1' ) {
27
- return true ;
28
- }
29
- return false ;
30
- } else {
24
+ networkIsConnected ( ) { //0:无网络,1:有网络
25
+ if ( Platform . OS === 'ios' ) {
26
+ if ( RNNeteaseIm . getNetWorkStatus ( ) === '1' ) {
27
+ return true ;
28
+ }
29
+ return false ;
30
+ } else {
31
31
return NetInfo . isConnected . fetch ( ) . done ( ) ;
32
32
}
33
33
}
34
+
34
35
/** ******************************播放 ****************************************** **/
35
36
36
37
/**
37
38
* 播放录音
38
39
* @returns {* }
39
40
*/
40
- play ( filepath ) {
41
+ play ( filepath ) {
41
42
return RNNeteaseIm . play ( filepath ) ;
42
43
}
44
+
43
45
/**
44
46
* 播放本地资源音乐
45
47
* name:iOS:文件名字,Android:文件路径
46
48
* type:音乐类型,如:'mp3'
47
49
* @returns {* }
48
50
*/
49
- playLocacl ( name , type ) {
50
- if ( Platform . OS === 'ios' ) {
51
- return RNNeteaseIm . playLocal ( name , type ) ;
51
+ playLocacl ( name , type ) {
52
+ if ( Platform . OS === 'ios' ) {
53
+ return RNNeteaseIm . playLocal ( name , type ) ;
52
54
}
53
- return RNNeteaseIm . playLocal ( 'assets:///' + name + '.' + type , type ) ;
55
+ return RNNeteaseIm . playLocal ( 'assets:///' + name + '.' + type , type ) ;
54
56
}
57
+
55
58
/**
56
59
* 停止播放录音
57
60
* @returns {* }
58
61
*/
59
- stopPlay ( ) {
62
+ stopPlay ( ) {
60
63
return RNNeteaseIm . stopPlay ( ) ;
61
64
}
62
- sortPinYin ( o , key ) {
63
- return PinYin . sortPinYin ( o , key ) ;
65
+
66
+ sortPinYin ( o , key ) {
67
+ return PinYin . sortPinYin ( o , key ) ;
64
68
}
65
69
66
70
67
- fetchNetInfo ( ) {
71
+ /**
72
+ * 仅限Android
73
+ * @returns {* }
74
+ */
75
+ fetchNetInfo ( ) {
68
76
return RNNeteaseIm . fetchNetInfo ( ) ;
69
77
}
70
-
78
+
71
79
/**
80
+ * 仅限IOS
72
81
* 设置webview UA
73
82
* @returns {* }
74
83
*/
75
- setupWebViewUserAgent ( ) {
76
- if ( Platform . OS === 'ios' ) {
77
- RNNeteaseIm . setupWebViewUserAgent ( ) ;
78
- }
84
+ setupWebViewUserAgent ( ) {
85
+ RNNeteaseIm . setupWebViewUserAgent ( ) ;
79
86
}
87
+
80
88
}
89
+
81
90
module . exports = new Utils ( ) ;
82
91
0 commit comments