forked from reactnativecomponent/react-native-netease-im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
executable file
·86 lines (75 loc) · 1.68 KB
/
Utils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict'
import { NativeModules,Platform, NetInfo } from 'react-native'
const { RNNeteaseIm,PinYin } = NativeModules
class Utils {
/**
* 清除数据缓存
*/
cleanCache() {
return RNNeteaseIm.cleanCache()
}
/**
* 获取缓存大小
*/
getCacheSize() {
return RNNeteaseIm.getCacheSize()
}
/**
* 获取网络状态
*/
networkIsConnected() {//0:无网络,1:有网络
if (Platform.OS === 'ios') {
if (RNNeteaseIm.getNetWorkStatus() === '1') {
return true
}
return false
} else {
return NetInfo.isConnected.fetch().done()
}
}
/**
* 播放录音
* @returns {*}
*/
play(filepath) {
return RNNeteaseIm.play(filepath)
}
/**
* 播放本地资源音乐
* name:iOS:文件名字,Android:文件路径
* type:音乐类型,如:'mp3'
* @returns {*}
*/
playLocacl(name, type) {
if (Platform.OS === 'ios') {
return RNNeteaseIm.playLocal(name, type)
}
return RNNeteaseIm.playLocal('assets:///' + name + '.' + type, type)
}
/**
* 停止播放录音
* @returns {*}
*/
stopPlay() {
return RNNeteaseIm.stopPlay()
}
sortPinYin(o, key) {
return PinYin.sortPinYin(o, key)
}
/**
* 仅限Android
* @returns {*}
*/
fetchNetInfo() {
return RNNeteaseIm.fetchNetInfo()
}
/**
* 仅限IOS
* 设置webview UA
* @returns {*}
*/
setupWebViewUserAgent() {
RNNeteaseIm.setupWebViewUserAgent()
}
}
export default new Utils()