-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
275 lines (248 loc) · 10 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
'use strict';
import {
NativeModules,
DeviceEventEmitter,
NativeEventEmitter,
Platform
}
from 'react-native';
const RongCloudIMLib = NativeModules.RongCloudIMLibModule;
var _onRongCloudMessageReceived = function (resp) {
console.log("融云接受消息:" + JSON.stringify(resp));
}
var _onMessageRecalled = function (resp) {
console.log("融云收到撤回消息:" + JSON.stringify(resp));
}
// DeviceEventEmitter.addListener('onRongMessageReceived', (resp) => {
// typeof (_onRongCloudMessageReceived) === 'function' && _onRongCloudMessageReceived(resp);
// });
const RongCloudIMLibEmitter = new NativeEventEmitter(RongCloudIMLib);
const messageSubscription = RongCloudIMLibEmitter.addListener(
'onRongMessageReceived',
(resp) => {
typeof (_onRongCloudMessageReceived) === 'function' && _onRongCloudMessageReceived(resp);
}
);
const recallMessageSubscription = RongCloudIMLibEmitter.addListener(
'onMessageRecalled',
(resp) => {
typeof (_onMessageRecalled) === 'function' && _onMessageRecalled(resp);
}
);
const ConversationType = {
PRIVATE: 'PRIVATE',
DISCUSSION: 'DISCUSSION',
SYSTEM: 'SYSTEM'
};
export default {
ConversationType: ConversationType,
/**
* SDK Init 初始化
* Connect and Disconnect 连接与断开服务器
* Received Message 接受新消息
*/
initWithAppKey(appKey) {
return RongCloudIMLib.initWithAppKey(appKey);
},
connectWithToken(token) {
return RongCloudIMLib.connectWithToken(token);
},
//isReceivePush-true 开启后台推送 false-关闭后台推送
disconnect(isReceivePush) {
return RongCloudIMLib.disconnect(isReceivePush);
},
logout() {
return RongCloudIMLib.logout();
},
getFCMToken() {
if (Platform.OS === 'android') {
return RongCloudIMLib.getFCMToken();
} else {
return '';
}
},
onReceived(callback) {
_onRongCloudMessageReceived = callback;
},
onMessageRecalled(callback) {
_onMessageRecalled = callback;
},
/**
* Unread Message 未读消息
*/
getTotalUnreadCount() {
// 获取全部未读消息数量(此消息数量为SDK本地查询到的未读消息数(有可能包含已退出群组的消息数量))
return RongCloudIMLib.getTotalUnreadCount();
},
getTargetUnreadCount(conversationType, targetId) {
// 获取某个会话类型的target 的未读消息数
return RongCloudIMLib.getTargetUnreadCount(conversationType, targetId);
},
getConversationsUnreadCount(conversationTypes) {
// 获取某些会话类型(conversationTypes为数组)的未读消息数(此消息数量为SDK本地查询到的未读消息数(有可能包含已退出群组的消息数量))
return RongCloudIMLib.getConversationsUnreadCount(conversationTypes);
},
clearUnreadMessage(conversationType, targetId) {
return RongCloudIMLib.clearUnreadMessage(conversationType, targetId);
},
/**
* Send Message 消息发送
*/
sendTextMessage(conversationType, targetId, content, pushContent, pushData, extra) {
return RongCloudIMLib.sendTextMessage(conversationType, targetId, content, pushContent, pushData, extra);
},
sendImageMessage(conversationType, targetId, imageUrl, pushContent, pushData, extra) {
return RongCloudIMLib.sendImageMessage(conversationType, targetId, imageUrl, pushContent, pushData, extra);
},
voiceBtnPressIn(conversationType, targetId, pushContent, pushData, extra) {
return RongCloudIMLib.voiceBtnPressIn(conversationType, targetId, pushContent, pushData, extra);
},
voiceBtnPressOut(conversationType, targetId, pushContent, pushData, extra) {
return RongCloudIMLib.voiceBtnPressOut(conversationType, targetId, pushContent, pushData, extra);
},
voiceBtnPressCancel(conversationType, targetId) {
return RongCloudIMLib.voiceBtnPressCancel(conversationType, targetId);
},
audioPlayStart(filePath) {
return RongCloudIMLib.audioPlayStart(filePath);
},
audioPlayStop() {
return RongCloudIMLib.audioPlayStop();
},
/**
* Recall Message 消息撤回
*/
recallMessage(message, push) {
return RongCloudIMLib.recallMessage(message, push);
},
/**
* Message Operation 消息操作
*/
getLatestMessages(type, targetId, count) {
return RongCloudIMLib.getLatestMessages(type, targetId, count);
},
getHistoryMessages(type, targetId, oldestMessageId, count) {
return RongCloudIMLib.getHistoryMessages(type, targetId, oldestMessageId, count);
},
getDesignatedTypeHistoryMessages(type, targetId, objectName, oldestMessageId, count) {
return RongCloudIMLib.getDesignatedTypeHistoryMessages(type, targetId, objectName, oldestMessageId, count);
},
getDesignatedDirectionypeHistoryMessages(type, targetId, objectName, baseMessageId, count, direction) {
return RongCloudIMLib.getDesignatedDirectionypeHistoryMessages(type, targetId, objectName, baseMessageId, count, direction);
},
getBaseOnSentTimeHistoryMessages(type, targetId, sentTime, before, after) {
return RongCloudIMLib.getBaseOnSentTimeHistoryMessages(type, targetId, sentTime, before, after);
},
/**
* Conversation List Operation 会话列表操作
*/
getConversationList() {
return RongCloudIMLib.getConversationList();
},
setConversationToTop(conversationType, targetId, isTop) {
return RongCloudIMLib.setConversationToTop(conversationType, targetId, isTop);
},
getTopConversationList(conversationTypeList) {
return RongCloudIMLib.getTopConversationList(conversationTypeList);
},
searchConversations(keyword) {
return RongCloudIMLib.searchConversations(keyword);
},
/**
* Conversation Draft 会话草稿操作
*/
getTextMessageDraft(conversationType, targetId) {
return RongCloudIMLib.getTextMessageDraft(conversationType, targetId);
},
saveTextMessageDraft(conversationType, targetId, content) {
return RongCloudIMLib.saveTextMessageDraft(conversationType, targetId, content);
},
clearTextMessageDraft(conversationType, targetId) {
return RongCloudIMLib.clearTextMessageDraft(conversationType, targetId);
},
/**
* Delete Messages 删除消息
*/
removeConversation(conversationType, targetId) {
return RongCloudIMLib.removeConversation(conversationType, targetId);
},
clearTargetMessages(conversationType, targetId) {
return RongCloudIMLib.clearTargetMessages(conversationType, targetId);
},
deleteTargetMessages(conversationType, targetId) {
return RongCloudIMLib.deleteTargetMessages(conversationType, targetId);
},
deleteMessages(messageIds) {
return RongCloudIMLib.deleteMessages(messageIds);
},
/**
* Conversation Push Notification 会话消息提醒
*/
setConversationNotificationStatus(conversationType, targetId, isBlocked) {
//设置会话消息提醒 isBlocked(true 屏蔽 false 新消息提醒) (return 0:(屏蔽) 1:(新消息提醒))
return RongCloudIMLib.setConversationNotificationStatus(conversationType, targetId, isBlocked);
},
getConversationNotificationStatus(conversationType, targetId) {
//获取会话消息提醒状态 (return 0:(屏蔽) 1:(新消息提醒))
return RongCloudIMLib.getConversationNotificationStatus(conversationType, targetId);
},
/**
* Global Push Notification 全局消息提醒
*/
screenGlobalNotification() {
//屏蔽全局新消息提醒
return RongCloudIMLib.screenGlobalNotification();
},
removeScreenOfGlobalNotification() {
//移除全局新消息屏蔽
return RongCloudIMLib.removeScreenOfGlobalNotification();
},
getGlobalNotificationStatus() {
//获取全局新消息提醒状态 ( return 0:(屏蔽) 1:(新消息提醒))
return RongCloudIMLib.getGlobalNotificationStatus();
},
/**
* Discussion 讨论组
*/
createDiscussion(name, userIdList) {
// 设置的讨论组名称长度不能超过40个字符,否则将会截断为前40个字符。
return RongCloudIMLib.createDiscussion(name, userIdList);
},
addMemberToDiscussion(discussionId, userIdList) {
return RongCloudIMLib.addMemberToDiscussion(discussionId, userIdList);
},
removeMemberFromDiscussion(discussionId, userId) {
// 如果当前登陆用户不是此讨论组的创建者并且此讨论组没有开放加人权限,则会返回错误。
// 不能使用此接口将自己移除,否则会返回错误。 如果您需要退出该讨论组,可以使用quitDiscussion方法。
return RongCloudIMLib.removeMemberFromDiscussion(discussionId, userId);
},
quitDiscussion(discussionId) {
return RongCloudIMLib.quitDiscussion(discussionId);
},
getDiscussion(discussionId) {
return RongCloudIMLib.getDiscussion(discussionId);
},
setDiscussionName(discussionId, name) {
return RongCloudIMLib.setDiscussionName(discussionId, name);
},
//注:isOpen type int,value CLOSED(1),OPENED(0);
setDiscussionInviteStatus(discussionId, isOpen) {
// 设置讨论组是否开放加人权限,讨论组默认开放加人权限,即所有成员都可以加人。如果关闭加人权限之后,只有讨论组的创建者有加人权限。
return RongCloudIMLib.setDiscussionInviteStatus(discussionId, isOpen);
},
/**
* Black List 黑名单
*/
addToBlacklist(userId) {
return RongCloudIMLib.addToBlacklist(userId);
},
removeFromBlacklist(userId) {
return RongCloudIMLib.removeFromBlacklist(userId);
},
getBlacklistStatus(userId) {
return RongCloudIMLib.getBlacklistStatus(userId);
},
getBlacklist() {
return RongCloudIMLib.getBlacklist();
},
};