-
Notifications
You must be signed in to change notification settings - Fork 998
/
index.js
158 lines (137 loc) · 3.42 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import {
NativeModules,
Platform,
DeviceEventEmitter
} from 'react-native';
import ChatInput from './ReactNative/chatinput';
import MessageList from './ReactNative/messagelist';
const AuroraIMUIModule = NativeModules.AuroraIMUIModule;
const listeners = {};
const IMUIMessageListDidLoad = "IMUIMessageListDidLoad";
const GET_INPUT_TEXT_EVENT = "getInputText";
class AuroraIMUIController {
/**
* append messages into messageList's bottom
*
* @param {Array} messageList [message]
*/
static appendMessages(messageList) {
AuroraIMUIModule.appendMessages(messageList)
}
/**
* update Messages. NOTE: It will replace message according to msgID.
* @param {Array} messageList [message]
*/
static updateMessage(messageList) {
AuroraIMUIModule.updateMessage(messageList)
}
/**
* insert messages into messageList's top, the message list to be inserted must be sorted chronologically.
* @param {Array} messageList [message]
*/
static insertMessagesToTop(messageList) {
AuroraIMUIModule.insertMessagesToTop(messageList)
}
/**
* remove message from messageList
* @param {String} messageId
*/
static removeMessage(messageId) {
AuroraIMUIModule.removeMessage(messageId)
}
/**
* stop play voice
*/
static stopPlayVoice() {
AuroraIMUIModule.stopPlayVoice()
}
/**
* scroll messageList to bottom
* @param {Boolean} animate
*/
static scrollToBottom(animate) {
AuroraIMUIModule.scrollToBottom(animate)
}
/**
* hiden featureView
* @param {Boolean} animate
*/
static hidenFeatureView(animate) {
AuroraIMUIModule.hidenFeatureView(animate)
}
/**
* layout input view
*/
static layoutInputView() {
AuroraIMUIModule.layoutInputView()
}
/**
* add listener: messageList did Loaded will call cb
* @param {Function} cb
*/
static addMessageListDidLoadListener(cb) {
listeners[cb] = DeviceEventEmitter.addListener(IMUIMessageListDidLoad,
() => {
cb();
});
}
/**
* Get Input text, Android Only
* @param {Function} cb
* @param {String} text
*/
static addGetInputTextListener(cb) {
listeners[cb] = DeviceEventEmitter.addListener(GET_INPUT_TEXT_EVENT, (text) => {
cb(text);
});
}
/**
* remove listener:
* @param {Function} cb
*/
static removeMessageListDidLoadListener(cb) {
if (!listeners[cb]) {
return;
}
listeners[cb].remove();
listeners[cb] = null;
}
static removeGetInputTextListener(cb) {
if (!listeners[cb]) {
return;
}
listeners[cb].remove();
listeners[cb] = null;
}
/**
* 清空所有消息
*/
static removeAllMessage() {
AuroraIMUIModule.removeAllMessage();
}
/**
* 裁剪图片,将图片裁剪成 width * height 大小
* param = { "path": String, "width": number, "height": number }
* result = { "code": number(0 表示裁剪成功,否则不成功), "thumbPath": String }
*/
static scaleImage(param, cb) {
AuroraIMUIModule.scaleImage(param, (result) => {
cb(result);
});
}
/**
* 压缩图片,将图片压缩成指定质量的大小
* param = { "path": String, "compressionQuality": number } // compressionQuality = {0 - 1}
* result = { "code": number(0 表示压缩成功,否则不成功), "thumbPath": String }
*/
static compressImage(param, cb) {
AuroraIMUIModule.compressImage(param, (result) => {
cb(result);
});
}
}
module.exports = {
ChatInput: ChatInput,
MessageList: MessageList,
AuroraIMUIController: AuroraIMUIController,
};