Skip to content

Commit d1a5bec

Browse files
committed
update example
1 parent 72f2f3a commit d1a5bec

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed

index.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const syncOfflineMessage = "JMessage.SyncOfflineMessage" // 同步离线消息
1414
const syncRoamingMessage = "JMessage.SyncRoamingMessage" // 同步漫游消息事件
1515
const messageRetract = "JMessage.MessageRetract" // 消息撤回事件
1616
const contactNotify = "JMessage.ContactNotify" // 收到好友请求消息事件
17-
17+
const uploadProgress = "JMessage.UploadProgress" // 收到好友请求消息事件
1818

1919
export default class JMessage {
2020

@@ -146,8 +146,7 @@ export default class JMessage {
146146
* 'customObject': {'key1': 'value1'} // Optional. Optional 自定义键值对
147147
* 'extras': Object, // Optional. 自定义键值对 = {'key1': 'value1'}
148148
* }
149-
* @param {function} success = function (msg) {} // 以参数形式返回消息对象。
150-
* @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {}
149+
* @param {function} callback = function (msg) {} // 以参数形式返回消息对象。
151150
*/
152151
static createSendMessage(params, callback) {
153152
JMessageModule.createSendMessage(params, callback);
@@ -164,10 +163,9 @@ export default class JMessage {
164163
* }
165164
* @param {function} success = function (msg) {} // 以参数形式返回消息对象。
166165
* @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {}
167-
* @param {function} progress = function (progress) {} // 上传进度回调,回调数值从 0 到 1, 会多次回调
168166
*/
169-
static sendMessage(params, success, error, progress) {
170-
JMessageModule.sendMessage(params, success, error, progress);
167+
static sendMessage(params, success, error) {
168+
JMessageModule.sendMessage(params, success, error);
171169
}
172170

173171
/**
@@ -866,4 +864,27 @@ export default class JMessage {
866864
listeners[listener].remove();
867865
listeners[listener] = null;
868866
}
867+
/**
868+
*
869+
* @param {function} listener = function (result) {}
870+
* result = {
871+
* messageId = String, // 消息 Id
872+
* progress = Float // 消息文件上传的进度
873+
* }
874+
*/
875+
static addUploadProgressListener(listener) {
876+
listeners[listener] = DeviceEventEmitter.addListener(uploadProgress,
877+
(message) => {
878+
listener(message);
879+
});
880+
}
881+
882+
static removeUploadProgressListener(listener) {
883+
if (!listeners[listener]) {
884+
return;
885+
}
886+
listeners[listener].remove();
887+
listeners[listener] = null;
888+
}
889+
869890
}

ios/RCTJMessageModule/RCTJMessageModule.m

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -176,54 +176,29 @@ -(void)didSendMessage:(NSNotification *)notification {
176176
//}
177177

178178
- (void)loginStateChanged:(NSNotification *)notification{
179-
// CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"loginStateChanged", @"value": notification.object}];
180-
//
181-
// [result setKeepCallback:@(true)];
182-
// [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId];
183-
179+
184180
[self.bridge.eventDispatcher sendAppEventWithName:loginStateChangedEvent body:notification.object];
185181
}
186182

187183
- (void)onContactNotify:(NSNotification *)notification{
188-
// CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"contactNotify", @"value": notification.object}];
189-
//
190-
// [result setKeepCallback:@(true)];
191-
// [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId];
192-
184+
193185
[self.bridge.eventDispatcher sendAppEventWithName:contactNotifyEvent body:notification.object];
194186
}
195187

196188
- (void)didReceiveRetractMessage:(NSNotification *)notification{
197-
// CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"retractMessage", @"value": notification.object}];
198-
//
199-
// [result setKeepCallback:@(true)];
200-
// [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId];
189+
201190
[self.bridge.eventDispatcher sendAppEventWithName:messageRetractEvent body:notification.object];
202191
}
203192

204193
//didReceiveJMessageMessage change name
205194
- (void)didReceiveJMessageMessage:(NSNotification *)notification {
206-
// CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"receiveMessage", @"value": notification.object}];
207-
// [result setKeepCallback:@(true)];
208-
//
209-
// [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId];
195+
210196
[self.bridge.eventDispatcher sendAppEventWithName:receiveMsgEvent body:notification.object];
211197
}
212198

213199
// TODO: fix <================
214200

215201

216-
//+(void)evalFuntionName:(NSString*)functionName jsonParm:(NSString*)jsonString{
217-
// dispatch_async(dispatch_get_main_queue(), ^{
218-
// [SharedJMessagePlugin.commandDelegate evalJs:[NSString stringWithFormat:@"%@.%@('%@')",JMessagePluginName,functionName,jsonString]];
219-
// });
220-
//}
221-
//
222-
//+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
223-
// dispatch_async(dispatch_get_main_queue(), ^{
224-
// [SharedJMessagePlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jmessage.%@',%@)", eventName, jsString]];
225-
// });
226-
//}
227202

228203
//#pragma mark IM - User
229204

@@ -298,7 +273,6 @@ - (void)didReceiveJMessageMessage:(NSNotification *)notification {
298273
RCT_EXPORT_METHOD(updateMyPassword:(NSDictionary *)param
299274
successCallback:(RCTResponseSenderBlock)successCallback
300275
failCallback:(RCTResponseSenderBlock)failCallback) {
301-
// NSDictionary * param = [command argumentAtIndex:0];
302276

303277
if (param[@"oldPwd"] && param[@"newPwd"]) {
304278
[JMSGUser updateMyPasswordWithNewPassword:param[@"newPwd"] oldPassword:param[@"oldPwd"] completionHandler:^(id resultObject, NSError *error) {
@@ -317,7 +291,6 @@ - (void)didReceiveJMessageMessage:(NSNotification *)notification {
317291
RCT_EXPORT_METHOD(updateMyAvatar:(NSDictionary *)param
318292
successCallback:(RCTResponseSenderBlock)successCallback
319293
failCallback:(RCTResponseSenderBlock)failCallback) {
320-
// NSDictionary * param = [command argumentAtIndex:0];
321294

322295
if (!param[@"imgPath"]) {
323296
failCallback(@[[self getParamError]]);
@@ -428,7 +401,6 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
428401
RCT_EXPORT_METHOD(sendTextMessage:(NSDictionary *)param
429402
successCallback:(RCTResponseSenderBlock)successCallback
430403
failCallback:(RCTResponseSenderBlock)failCallback) {
431-
// NSDictionary * param = [command argumentAtIndex:0];
432404

433405
if (param[@"type"] == nil) {
434406

@@ -504,7 +476,6 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
504476
RCT_EXPORT_METHOD(sendImageMessage:(NSDictionary *)param
505477
successCallback:(RCTResponseSenderBlock)successCallback
506478
failCallback:(RCTResponseSenderBlock)failCallback) {
507-
// NSDictionary * param = [command argumentAtIndex:0];
508479

509480
if (param[@"type"] == nil) {
510481
failCallback(@[[self getParamError]]);
@@ -891,7 +862,7 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
891862
RCT_EXPORT_METHOD(getHistoryMessages:(NSDictionary *)param
892863
successCallback:(RCTResponseSenderBlock)successCallback
893864
failCallback:(RCTResponseSenderBlock)failCallback) {
894-
// NSDictionary * param = [command argumentAtIndex:0];
865+
895866
if (param[@"type"] == nil ||
896867
param[@"from"] == nil ||
897868
param[@"limit"] == nil) {
@@ -978,7 +949,7 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
978949
RCT_EXPORT_METHOD(acceptInvitation:(NSDictionary *)param
979950
successCallback:(RCTResponseSenderBlock)successCallback
980951
failCallback:(RCTResponseSenderBlock)failCallback) {
981-
// NSDictionary * param = [command argumentAtIndex:0];
952+
982953
if (param[@"username"] == nil) {
983954
failCallback(@[[self getParamError]]);
984955
return;
@@ -2185,5 +2156,27 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
21852156
}
21862157
}
21872158

2159+
RCT_EXPORT_METHOD(createSendMessage:(NSDictionary *)param
2160+
successCallback:(RCTResponseSenderBlock)successCallback) {
2161+
/**
2162+
* @param {object} params = {
2163+
* 'type': String, // 'single' / 'group'
2164+
* 'messageType': String, // 'text', 'image', 'voice', 'location', 'file', 'custom'
2165+
* 'groupId': String, // 当 type = group 时,groupId 不能为空
2166+
* 'username': String, // 当 type = single 时,username 不能为空
2167+
* 'appKey': String, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。
2168+
* 'text': String, // Optional 消息内容
2169+
* 'path': String // Optional 资源路径
2170+
* 'fileName': String, // Optional 文件名
2171+
* 'latitude': Number, // Optional 纬度信息
2172+
* 'longitude': Number, // Optional 经度信息
2173+
* 'scale': Number, // Optional 地图缩放比例
2174+
* 'address': String, // Optional 详细地址信息
2175+
* 'customObject': {'key1': 'value1'} // Optional. Optional 自定义键值对
2176+
* 'extras': Object, // Optional. 自定义键值对 = {'key1': 'value1'}
2177+
* }
2178+
*/
2179+
JMSGMessage
21882180

2181+
}
21892182
@end

0 commit comments

Comments
 (0)