juggleim-rnsdk 0.0.11 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/ios/JuggleIMManager.m +6 -7
- package/{im-rn-sdk.podspec → juggleim-rnsdk.podspec} +3 -3
- package/package.json +5 -5
- package/src/index.d.ts +100 -8
- package/src/index.js +37 -11
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ React Native wrapper for Juggle IM SDK,提供即时通讯功能的React Native
|
|
|
6
6
|
## 安装
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
|
-
npm install
|
|
9
|
+
npm install juggleim-rnsdk --legacy-peer-deps
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
## 初始化
|
|
@@ -14,7 +14,7 @@ npm install im-rn-sdk --registry=https://repo.juggle.im/repository/npm-hosted/ -
|
|
|
14
14
|
在使用Juggle IM SDK之前,需要先进行初始化设置:
|
|
15
15
|
|
|
16
16
|
```javascript
|
|
17
|
-
import JuggleIM from '
|
|
17
|
+
import JuggleIM from 'juggleim-rnsdk';
|
|
18
18
|
|
|
19
19
|
// 设置服务器地址
|
|
20
20
|
JuggleIM.setServerUrls(['your_server_url']);
|
package/ios/JuggleIMManager.m
CHANGED
|
@@ -1082,12 +1082,11 @@ RCT_EXPORT_METHOD(getMessages:(NSDictionary *)conversationDict
|
|
|
1082
1082
|
/**
|
|
1083
1083
|
* 撤回消息
|
|
1084
1084
|
*/
|
|
1085
|
-
RCT_EXPORT_METHOD(recallMessage:(
|
|
1085
|
+
RCT_EXPORT_METHOD(recallMessage:(NSString *)messageId
|
|
1086
1086
|
extras:(NSDictionary *)extras
|
|
1087
1087
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
1088
1088
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
1089
1089
|
@try {
|
|
1090
|
-
NSString *messageId = messageDict[@"messageId"];
|
|
1091
1090
|
NSDictionary *extrasDict = extras ?: @{};
|
|
1092
1091
|
|
|
1093
1092
|
[JIM.shared.messageManager recallMessage:messageId
|
|
@@ -1095,7 +1094,7 @@ RCT_EXPORT_METHOD(recallMessage:(NSDictionary *)messageDict
|
|
|
1095
1094
|
success:^(JMessage *message){
|
|
1096
1095
|
resolve(@YES);
|
|
1097
1096
|
} error:^(JErrorCode errorCode) {
|
|
1098
|
-
reject(@"RECALL_MESSAGE_ERROR",
|
|
1097
|
+
reject(@"RECALL_MESSAGE_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
|
|
1099
1098
|
}];
|
|
1100
1099
|
} @catch (NSException *exception) {
|
|
1101
1100
|
reject(@"RECALL_MESSAGE_ERROR", exception.reason, nil);
|
|
@@ -1105,8 +1104,8 @@ RCT_EXPORT_METHOD(recallMessage:(NSDictionary *)messageDict
|
|
|
1105
1104
|
/**
|
|
1106
1105
|
* 根据clientMsgNo列表删除消息
|
|
1107
1106
|
*/
|
|
1108
|
-
RCT_EXPORT_METHOD(deleteMessagesByClientMsgNoList:(
|
|
1109
|
-
|
|
1107
|
+
RCT_EXPORT_METHOD(deleteMessagesByClientMsgNoList:(NSDictionary *)conversationMap
|
|
1108
|
+
clientMsgNos:(NSArray<NSNumber *> *)clientMsgNos
|
|
1110
1109
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
1111
1110
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
1112
1111
|
@try {
|
|
@@ -1117,7 +1116,7 @@ RCT_EXPORT_METHOD(deleteMessagesByClientMsgNoList:(NSArray<NSNumber *> *)clientM
|
|
|
1117
1116
|
success:^{
|
|
1118
1117
|
resolve(@YES);
|
|
1119
1118
|
} error:^(JErrorCode errorCode) {
|
|
1120
|
-
reject(@"DELETE_MESSAGES_ERROR",
|
|
1119
|
+
reject(@"DELETE_MESSAGES_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
|
|
1121
1120
|
}];
|
|
1122
1121
|
} @catch (NSException *exception) {
|
|
1123
1122
|
reject(@"DELETE_MESSAGES_ERROR", exception.reason, nil);
|
|
@@ -1141,7 +1140,7 @@ RCT_EXPORT_METHOD(addMessageReaction:(NSDictionary *)messageDict
|
|
|
1141
1140
|
success:^{
|
|
1142
1141
|
resolve(@YES);
|
|
1143
1142
|
} error:^(JErrorCode errorCode) {
|
|
1144
|
-
reject(@"ADD_REACTION_ERROR",
|
|
1143
|
+
reject(@"ADD_REACTION_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
|
|
1145
1144
|
}];
|
|
1146
1145
|
} @catch (NSException *exception) {
|
|
1147
1146
|
reject(@"ADD_REACTION_ERROR", exception.reason, nil);
|
|
@@ -3,14 +3,14 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = "
|
|
6
|
+
s.name = "juggleim-rnsdk"
|
|
7
7
|
s.version = package["version"]
|
|
8
8
|
s.summary = package["description"]
|
|
9
|
-
s.homepage = "https://github.com/juggleim/
|
|
9
|
+
s.homepage = "https://github.com/juggleim/imsdk-rn"
|
|
10
10
|
s.license = "MIT"
|
|
11
11
|
s.authors = { "Juggle IM" => "support@juggleim.com" }
|
|
12
12
|
s.platforms = { :ios => "9.0" }
|
|
13
|
-
s.source = { :git => "https://github.com/juggleim/
|
|
13
|
+
s.source = { :git => "https://github.com/juggleim/imsdk-rn.git", :tag => "#{s.version}" }
|
|
14
14
|
|
|
15
15
|
s.source_files = "ios/**/*.{h,m,mm}"
|
|
16
16
|
s.requires_arc = true
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juggleim-rnsdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "React Native wrapper for Juggle IM SDK",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"react-native": "src/index.js",
|
|
8
|
-
"homepage": "https://github.com/juggleim/
|
|
8
|
+
"homepage": "https://github.com/juggleim/imsdk-rn",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/juggleim/
|
|
11
|
+
"url": "https://github.com/juggleim/imsdk-rn.git"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"src",
|
|
15
15
|
"android",
|
|
16
16
|
"ios",
|
|
17
|
-
"
|
|
17
|
+
"juggleim-rnsdk.podspec",
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
-
"
|
|
22
|
+
"app": "cd app && npm start",
|
|
23
23
|
"prepare": "npm run build",
|
|
24
24
|
"build": "echo \"Build completed\""
|
|
25
25
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module "
|
|
1
|
+
declare module "juggleim-rnsdk" {
|
|
2
2
|
/**
|
|
3
3
|
* 连接状态类型
|
|
4
4
|
*/
|
|
@@ -39,13 +39,83 @@ declare module "im-rn-sdk" {
|
|
|
39
39
|
contentType: string;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* 消息内容基类
|
|
44
|
+
* @property {string} contentType - 消息内容类型
|
|
45
|
+
* 枚举:jg:text, jg:img, jg:file, jg:voice
|
|
46
|
+
*/
|
|
47
|
+
export abstract class MessageContent {
|
|
48
|
+
abstract contentType: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
/**
|
|
43
52
|
* 文本消息内容
|
|
44
53
|
*/
|
|
45
|
-
export
|
|
54
|
+
export class TextMessageContent extends MessageContent {
|
|
55
|
+
contentType = 'jg:text';
|
|
46
56
|
content: string;
|
|
57
|
+
constructor(content: string) {
|
|
58
|
+
super();
|
|
59
|
+
this.content = content;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 撤回消息内容
|
|
65
|
+
*/
|
|
66
|
+
export class RecallInfoMessageContent extends MessageContent {
|
|
67
|
+
contentType = 'jg:recallinfo';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 合并消息内容
|
|
72
|
+
*/
|
|
73
|
+
export class MergeMessageContent extends MessageContent {
|
|
74
|
+
contentType = 'jg:merge';
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
title?: string,
|
|
78
|
+
conversation?: Conversation,
|
|
79
|
+
messageIdList?: string[],
|
|
80
|
+
previewList?: MergeMessagePreviewUnit[]
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// 对应 Java 字段
|
|
84
|
+
title?: string;
|
|
85
|
+
containerMsgId?: string;
|
|
86
|
+
conversation?: Conversation;
|
|
87
|
+
messageIdList?: string[];
|
|
88
|
+
previewList?: MergeMessagePreviewUnit[];
|
|
89
|
+
extra?: string;
|
|
90
|
+
|
|
91
|
+
conversationDigest?(): string;
|
|
92
|
+
getTitle?(): string | undefined;
|
|
93
|
+
getContainerMsgId?(): string | undefined;
|
|
94
|
+
setContainerMsgId?(containerMsgId: string): void;
|
|
95
|
+
getConversation?(): Conversation | undefined;
|
|
96
|
+
setConversation?(conversation: Conversation): void;
|
|
97
|
+
getMessageIdList?(): string[] | undefined;
|
|
98
|
+
getPreviewList?(): MergeMessagePreviewUnit[] | undefined;
|
|
99
|
+
getExtra?(): string | undefined;
|
|
100
|
+
setExtra?(extra: string): void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 合并消息预览单元
|
|
105
|
+
*/
|
|
106
|
+
export class MergeMessagePreviewUnit {
|
|
107
|
+
constructor(previewContent?: string, sender?: UserInfo);
|
|
108
|
+
|
|
109
|
+
previewContent?: string;
|
|
110
|
+
sender?: UserInfo;
|
|
111
|
+
|
|
112
|
+
getPreviewContent?(): string | undefined;
|
|
113
|
+
setPreviewContent?(previewContent: string): void;
|
|
114
|
+
getSender?(): UserInfo | undefined;
|
|
115
|
+
setSender?(sender: UserInfo): void;
|
|
47
116
|
}
|
|
48
117
|
|
|
118
|
+
|
|
49
119
|
/**
|
|
50
120
|
* 图片消息内容
|
|
51
121
|
* @property {string} localPath - 图片本地路径:支持 /
|
|
@@ -55,13 +125,15 @@ declare module "im-rn-sdk" {
|
|
|
55
125
|
* @property {number} width - 图片宽度
|
|
56
126
|
* @property {number} height - 图片高度
|
|
57
127
|
*/
|
|
58
|
-
export
|
|
128
|
+
export class ImageMessageContent extends MessageContent {
|
|
59
129
|
localPath: string;
|
|
60
130
|
thumbnailLocalPath?: string;
|
|
61
131
|
url?: string;
|
|
62
132
|
thumbnailUrl?: string;
|
|
63
133
|
width: number;
|
|
64
134
|
height: number;
|
|
135
|
+
|
|
136
|
+
contentType = 'jg:img';
|
|
65
137
|
}
|
|
66
138
|
|
|
67
139
|
/**
|
|
@@ -72,12 +144,14 @@ declare module "im-rn-sdk" {
|
|
|
72
144
|
* @property {number} size - 文件大小,单位字节
|
|
73
145
|
* @property {string} [type] - 文件类型(MIME类型)
|
|
74
146
|
*/
|
|
75
|
-
export
|
|
147
|
+
export class FileMessageContent extends MessageContent {
|
|
76
148
|
localPath: string;
|
|
77
149
|
url?: string;
|
|
78
150
|
name: string;
|
|
79
151
|
size: number;
|
|
80
152
|
type?: string;
|
|
153
|
+
|
|
154
|
+
contentType = 'jg:file';
|
|
81
155
|
}
|
|
82
156
|
|
|
83
157
|
/**
|
|
@@ -86,12 +160,15 @@ declare module "im-rn-sdk" {
|
|
|
86
160
|
* @property {string} [url] - 语音远程URL
|
|
87
161
|
* @property {number} duration - 语音时长,单位秒
|
|
88
162
|
*/
|
|
89
|
-
export
|
|
163
|
+
export class VoiceMessageContent extends MessageContent {
|
|
90
164
|
localPath: string;
|
|
91
165
|
url?: string;
|
|
92
166
|
duration: number;
|
|
167
|
+
|
|
168
|
+
contentType = 'jg:voice';
|
|
93
169
|
}
|
|
94
170
|
|
|
171
|
+
|
|
95
172
|
/**
|
|
96
173
|
* 消息对象
|
|
97
174
|
* @interface Message
|
|
@@ -576,13 +653,28 @@ declare module "im-rn-sdk" {
|
|
|
576
653
|
* 发送消息
|
|
577
654
|
* @param {SendMessageObject} message 发送消息对象
|
|
578
655
|
* @param {SendMessageCallback} [callback] 发送消息回调函数
|
|
579
|
-
* @returns {Message}
|
|
656
|
+
* @returns {Promise<Message>} 发送的消息对象
|
|
580
657
|
*/
|
|
581
658
|
static sendMessage(
|
|
582
659
|
message: SendMessageObject,
|
|
583
660
|
callback?: SendMessageCallback
|
|
584
661
|
): Promise<Message>;
|
|
585
662
|
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* 发送合并消息
|
|
666
|
+
* @param {string} title 合并消息的标题
|
|
667
|
+
* @param {string[]} messageIds 要合并的消息ID列表
|
|
668
|
+
* @param {Conversation} conversation 目标会话对象
|
|
669
|
+
* @param {SendMessageCallback} [callback] 发送消息回调函数
|
|
670
|
+
* @returns {Promise<Message>} 发送的消息对象
|
|
671
|
+
*/
|
|
672
|
+
static sendMergeMessage(
|
|
673
|
+
message: MergeMessageContent,
|
|
674
|
+
conversation: Conversation,
|
|
675
|
+
callback?: SendMessageCallback
|
|
676
|
+
): Promise<Message>;
|
|
677
|
+
|
|
586
678
|
/**
|
|
587
679
|
* 发送图片消息
|
|
588
680
|
* 示例
|
|
@@ -657,12 +749,12 @@ declare module "im-rn-sdk" {
|
|
|
657
749
|
|
|
658
750
|
/**
|
|
659
751
|
* 撤回消息
|
|
660
|
-
* @param
|
|
752
|
+
* @param messageId 消息ID列表
|
|
661
753
|
* @param extras 扩展字段
|
|
662
754
|
* @returns {Promise<Boolean>} 是否撤回成功
|
|
663
755
|
*/
|
|
664
756
|
static recallMessage(
|
|
665
|
-
|
|
757
|
+
messageId: string,
|
|
666
758
|
extras?: { [key: string]: any }
|
|
667
759
|
): Promise<Boolean>;
|
|
668
760
|
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { NativeModules, Platform, NativeEventEmitter } from "react-native";
|
|
2
2
|
|
|
3
3
|
const { JuggleIM: JMI } = NativeModules;
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
// NativeEventEmitter requires a non-null native module. If the native
|
|
6
|
+
// module is not linked (JMI is undefined), create a safe fallback that
|
|
7
|
+
// implements `addListener` and returns a subscription with `remove()` so
|
|
8
|
+
// JS code can call it without crashing during development or in environments
|
|
9
|
+
// where the native module isn't available.
|
|
10
|
+
const juggleIMEmitter = JMI
|
|
11
|
+
? new NativeEventEmitter(JMI)
|
|
12
|
+
: {
|
|
13
|
+
addListener: () => ({ remove: () => {} }),
|
|
14
|
+
removeAllListeners: () => {},
|
|
15
|
+
};
|
|
5
16
|
|
|
6
17
|
/**
|
|
7
18
|
* Juggle IM React Native SDK
|
|
@@ -535,8 +546,8 @@ class JuggleIM {
|
|
|
535
546
|
/**
|
|
536
547
|
* 发送消息
|
|
537
548
|
* @param {SendMessageObject} message
|
|
538
|
-
* @param {import("
|
|
539
|
-
* @returns {import("
|
|
549
|
+
* @param {import("juggleim-rnsdk").SendMessageCallback} callback - 回调对象
|
|
550
|
+
* @returns {import("juggleim-rnsdk").Message} - 消息对象
|
|
540
551
|
*/
|
|
541
552
|
static async sendMessage(
|
|
542
553
|
message,
|
|
@@ -812,6 +823,22 @@ class JuggleIM {
|
|
|
812
823
|
}
|
|
813
824
|
}
|
|
814
825
|
|
|
826
|
+
/**
|
|
827
|
+
* 发送合并消息(构建 MergeMessage 并发送)
|
|
828
|
+
* @param {MergedMessageContent} mergedMessage - 要合并转发的消息 ID 列表
|
|
829
|
+
* @param {Conversation} conversation - 目标会话(同时作为 MergeMessage 中的 conversation 字段)
|
|
830
|
+
* @param {SendMessageCallback} callback - 回调对象,包含 onSuccess/onError
|
|
831
|
+
*/
|
|
832
|
+
static async sendMergeMessage(mergedMessage, conversation, callback = {}) {
|
|
833
|
+
const messageObj = {
|
|
834
|
+
conversationType: conversation && conversation.conversationType,
|
|
835
|
+
conversationId: conversation && conversation.conversationId,
|
|
836
|
+
content: mergedMessage,
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
return this.sendMessage(messageObj, callback);
|
|
840
|
+
}
|
|
841
|
+
|
|
815
842
|
/**
|
|
816
843
|
* 获取历史消息
|
|
817
844
|
* @param {Object} conversation - 会话对象
|
|
@@ -824,11 +851,11 @@ class JuggleIM {
|
|
|
824
851
|
|
|
825
852
|
/**
|
|
826
853
|
* 撤回消息
|
|
827
|
-
* @param {
|
|
854
|
+
* @param {String} messageId - 消息ID
|
|
828
855
|
* @param {Object} extras - kv 扩展信息
|
|
829
856
|
*/
|
|
830
|
-
static recallMessage(
|
|
831
|
-
return JMI.recallMessage(
|
|
857
|
+
static recallMessage(messageId, extras = {}) {
|
|
858
|
+
return JMI.recallMessage(messageId, extras);
|
|
832
859
|
}
|
|
833
860
|
|
|
834
861
|
/**
|
|
@@ -838,11 +865,10 @@ class JuggleIM {
|
|
|
838
865
|
* @returns {Promise<boolean>} 删除结果
|
|
839
866
|
*/
|
|
840
867
|
static deleteMessagesByClientMsgNoList(conversation, clientMsgNos) {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
868
|
+
const nums = (clientMsgNos || [])
|
|
869
|
+
.map(n => Number(n))
|
|
870
|
+
.filter(n => !isNaN(n));
|
|
871
|
+
return JMI.deleteMessagesByClientMsgNoList(conversation, nums);
|
|
846
872
|
}
|
|
847
873
|
|
|
848
874
|
/**
|