Skip to content

Commit 3de787f

Browse files
author
wicked-tc130
authored
Merge pull request #101 from wicked-tc130/master
update version to 4.1.2
2 parents 5b227c1 + 2583cf6 commit 3de787f

File tree

8 files changed

+327
-41
lines changed

8 files changed

+327
-41
lines changed

example/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@
216216
}, (error) => {
217217
alert("Send message fail: " + error.description);
218218
});
219+
//这里的路径以android为例
220+
// var videoFilePath = "sdcard/DCIM/1.mp4";
221+
// var videoFileName = "xxxxxx";
222+
// var videoImagePath = "sdcard/DCIM/1.png";
223+
// var videoImageFormat = "png";
224+
// var videoDuration = 10;
225+
// window.JMessage.sendVideoMessage({'type': 'single','username': username,'appKey': appKey,
226+
// "videoFilePath":videoFilePath,"videoFileName":videoFileName,"videoImagePath":videoImagePath,"videoImageFormat":videoImageFormat,"videoDuration":videoDuration},
227+
// (msg) => {
228+
// console.log("sendVideo success");
229+
// },(error) => {
230+
// console.log("sendVideo error:"+error.description);
231+
// });
219232
}
220233

221234
function addConversation() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmessage-phonegap-plugin",
3-
"version": "4.1.1",
3+
"version": "4.1.2",
44
"description": "JMessage Cordova Plugin.",
55
"cordova": {
66
"id": "jmessage-phonegap-plugin",

src/android/JMessagePlugin.java

Lines changed: 153 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import android.app.Activity;
55
import android.content.Intent;
66
import android.graphics.Bitmap;
7+
import android.graphics.BitmapFactory;
78
import android.media.MediaPlayer;
89
import android.net.Uri;
10+
import android.os.Environment;
911
import android.text.TextUtils;
1012
import android.util.Log;
1113

@@ -21,6 +23,7 @@
2123

2224
import java.io.File;
2325
import java.io.FileNotFoundException;
26+
import java.io.IOException;
2427
import java.lang.reflect.InvocationTargetException;
2528
import java.lang.reflect.Method;
2629
import java.util.ArrayList;
@@ -46,6 +49,7 @@
4649
import cn.jpush.im.android.api.content.ImageContent;
4750
import cn.jpush.im.android.api.content.LocationContent;
4851
import cn.jpush.im.android.api.content.TextContent;
52+
import cn.jpush.im.android.api.content.VideoContent;
4953
import cn.jpush.im.android.api.content.VoiceContent;
5054
import cn.jpush.im.android.api.enums.ContentType;
5155
import cn.jpush.im.android.api.event.ChatRoomMessageEvent;
@@ -628,6 +632,57 @@ void sendVoiceMessage(JSONArray data, CallbackContext callback) {
628632
}
629633
}
630634

635+
void sendVideoMessage(JSONArray data, CallbackContext callback) {
636+
boolean hasPermission = PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
637+
if (!hasPermission) {
638+
handleResult(ERR_CODE_PERMISSION, ERR_MSG_PERMISSION_WRITE_EXTERNAL_STORAGE, callback);
639+
return;
640+
}
641+
String videoFilePath;
642+
String videoFileName;
643+
String videoImagePath;
644+
String videoImageFormat;
645+
int videoDuration;
646+
Map<String, String> extras = null;
647+
MessageSendingOptions messageSendingOptions = null;
648+
Conversation conversation;
649+
try {
650+
JSONObject params = data.getJSONObject(0);
651+
conversation = JMessageUtils.createConversation(params);
652+
if (conversation == null) {
653+
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
654+
return;
655+
}
656+
videoFilePath = params.getString("videoFilePath");
657+
videoFileName = params.getString("videoFileName");
658+
videoImagePath = params.getString("videoImagePath");
659+
videoImageFormat = params.getString("videoImageFormat");
660+
videoDuration = params.getInt("videoDuration");
661+
if (params.has("extras")) {
662+
extras = fromJson(params.getJSONObject("extras"));
663+
}
664+
if (params.has("messageSendingOptions")) {
665+
messageSendingOptions = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
666+
}
667+
} catch (JSONException e) {
668+
e.printStackTrace();
669+
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
670+
return;
671+
}
672+
try {
673+
Bitmap thumbImage = BitmapFactory.decodeFile(videoImagePath);
674+
File videoFile = new File(videoFilePath);
675+
VideoContent videoContent = new VideoContent(thumbImage, videoImageFormat, videoFile, videoFileName, videoDuration);
676+
if (extras != null) {
677+
videoContent.setExtras(extras);
678+
}
679+
sendMessage(conversation, videoContent, messageSendingOptions, callback);
680+
} catch (IOException e) {
681+
e.printStackTrace();
682+
handleResult(ERR_CODE_FILE, ERR_MSG_FILE, callback);
683+
}
684+
}
685+
631686
void sendCustomMessage(JSONArray data, CallbackContext callback) {
632687
try {
633688
JSONObject params = data.getJSONObject(0);
@@ -1061,6 +1116,48 @@ public void onComplete(int status, String desc, File file) {
10611116
});
10621117
}
10631118

1119+
void downloadVideoFile(JSONArray data, final CallbackContext callback) {
1120+
final Message msg;
1121+
1122+
try {
1123+
JSONObject params = data.getJSONObject(0);
1124+
msg = JMessageUtils.getMessage(params);
1125+
if (msg == null) {
1126+
handleResult(ERR_CODE_MESSAGE, ERR_MSG_MESSAGE, callback);
1127+
return;
1128+
}
1129+
} catch (JSONException e) {
1130+
e.printStackTrace();
1131+
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
1132+
return;
1133+
}
1134+
1135+
if (msg.getContentType() != ContentType.file) {
1136+
handleResult(ERR_CODE_MESSAGE, "Message type isn't video", callback);
1137+
return;
1138+
}
1139+
1140+
VideoContent content = (VideoContent) msg.getContent();
1141+
content.downloadVideoFile(msg, new DownloadCompletionCallback() {
1142+
@Override
1143+
public void onComplete(int status, String desc, File file) {
1144+
if (status == 0) {
1145+
JSONObject result = new JSONObject();
1146+
try {
1147+
result.put("messageId", msg.getId());
1148+
result.put("filePath", file.getAbsolutePath());
1149+
} catch (JSONException e) {
1150+
e.printStackTrace();
1151+
}
1152+
handleResult(result, status, desc, callback);
1153+
1154+
} else {
1155+
handleResult(status, desc, callback);
1156+
}
1157+
}
1158+
});
1159+
}
1160+
10641161
void downloadFile(JSONArray data, final CallbackContext callback) {
10651162
final Message msg;
10661163

@@ -2630,46 +2727,67 @@ public void onEvent(OfflineMessageEvent event) throws JSONException {
26302727
final int fI = i;
26312728

26322729
switch (msg.getContentType()) {
2633-
case image:
2634-
((ImageContent) msg.getContent()).downloadThumbnailImage(msg, new DownloadCompletionCallback() {
2635-
@Override
2636-
public void onComplete(int status, String desc, File file) {
2637-
if (fI == fLatestMediaMessageIndex) {
2638-
for (Message msg : offlineMsgList) {
2639-
msgJsonArr.put(toJson(msg));
2640-
}
2641-
try {
2642-
json.put("messageArray", msgJsonArr);
2643-
} catch (JSONException e) {
2644-
e.printStackTrace();
2645-
}
2730+
case image:
2731+
((ImageContent) msg.getContent()).downloadThumbnailImage(msg, new DownloadCompletionCallback() {
2732+
@Override
2733+
public void onComplete(int status, String desc, File file) {
2734+
if (fI == fLatestMediaMessageIndex) {
2735+
for (Message msg : offlineMsgList) {
2736+
msgJsonArr.put(toJson(msg));
2737+
}
2738+
try {
2739+
json.put("messageArray", msgJsonArr);
2740+
} catch (JSONException e) {
2741+
e.printStackTrace();
2742+
}
26462743

2647-
JSONObject eventJson = toJson("syncOfflineMessage", json);
2648-
eventSuccess(eventJson);
2649-
}
2650-
}
2651-
});
2652-
break;
2653-
case voice:
2654-
((VoiceContent) msg.getContent()).downloadVoiceFile(msg, new DownloadCompletionCallback() {
2655-
@Override
2656-
public void onComplete(int status, String desc, File file) {
2657-
if (fI == fLatestMediaMessageIndex) {
2658-
for (Message msg : offlineMsgList) {
2659-
msgJsonArr.put(toJson(msg));
2744+
JSONObject eventJson = toJson("syncOfflineMessage", json);
2745+
eventSuccess(eventJson);
26602746
}
2661-
try {
2662-
json.put("messageArray", msgJsonArr);
2663-
} catch (JSONException e) {
2664-
e.printStackTrace();
2747+
}
2748+
});
2749+
break;
2750+
case voice:
2751+
((VoiceContent) msg.getContent()).downloadVoiceFile(msg, new DownloadCompletionCallback() {
2752+
@Override
2753+
public void onComplete(int status, String desc, File file) {
2754+
if (fI == fLatestMediaMessageIndex) {
2755+
for (Message msg : offlineMsgList) {
2756+
msgJsonArr.put(toJson(msg));
2757+
}
2758+
try {
2759+
json.put("messageArray", msgJsonArr);
2760+
} catch (JSONException e) {
2761+
e.printStackTrace();
2762+
}
2763+
2764+
JSONObject eventJson = toJson("syncOfflineMessage", json);
2765+
eventSuccess(eventJson);
26652766
}
2767+
}
2768+
});
2769+
break;
2770+
case video:
2771+
((VideoContent) msg.getContent()).downloadVideoFile(msg, new DownloadCompletionCallback() {
2772+
@Override
2773+
public void onComplete(int status, String desc, File file) {
2774+
if (fI == fLatestMediaMessageIndex) {
2775+
for (Message msg : offlineMsgList) {
2776+
msgJsonArr.put(toJson(msg));
2777+
}
2778+
try {
2779+
json.put("messageArray", msgJsonArr);
2780+
} catch (JSONException e) {
2781+
e.printStackTrace();
2782+
}
26662783

2667-
JSONObject eventJson = toJson("syncOfflineMessage", json);
2668-
eventSuccess(eventJson);
2784+
JSONObject eventJson = toJson("syncOfflineMessage", json);
2785+
eventSuccess(eventJson);
2786+
}
26692787
}
2670-
}
2671-
});
2672-
default:
2788+
});
2789+
break;
2790+
default:
26732791
}
26742792
}
26752793
}

src/android/JMessageUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.graphics.Bitmap;
44
import android.os.Environment;
5+
import android.util.Log;
56

67
import org.apache.cordova.CallbackContext;
78
import org.json.JSONArray;
@@ -39,6 +40,7 @@ static void handleResult(int status, String desc, CallbackContext callback) {
3940
callback.success();
4041
} else {
4142
try {
43+
JSONObject errorObject = getErrorObject(status, desc);
4244
callback.error(getErrorObject(status, desc));
4345
} catch (JSONException e) {
4446
e.printStackTrace();

src/ios/Plugins/JMessageHelper.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@ - (void)onReceiveUserLoginStatusChangeEvent:(JMSGUserLoginStatusChangeEvent *)ev
117117
switch (event.eventType) {
118118
case kJMSGEventNotificationLoginKicked:
119119
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
120-
object:@{@"type":@"user_kicked"}];
120+
object:@{@"type":@"user_logout"}];
121121
break;
122122
case kJMSGEventNotificationServerAlterPassword:
123123
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
124124
object:@{@"type":@"user_password_change"}];
125125
break;
126126
case kJMSGEventNotificationUserLoginStatusUnexpected:
127127
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
128-
object:@{@"type":@"user_login_state_unexpected"}];
128+
object:@{@"type":@"user_login_status_unexpected"}];
129+
break;
130+
case kJMSGEventNotificationCurrentUserDeleted:
131+
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
132+
object:@{@"type":@"user_deleted"}];
129133
break;
130134
}
131135
}
@@ -502,6 +506,16 @@ - (NSMutableDictionary *)messageToDictionary {
502506
dict[@"duration"] = [voiceContent duration];
503507
break;
504508
}
509+
case kJMSGContentTypeVideo: {
510+
dict[@"type"] = @"video";
511+
dict[@"mediaFilePath"] = [self getOriginMediaFilePath];
512+
JMSGVideoContent *videoContent = (JMSGVideoContent *) self.content;
513+
//dict[@"mediaFilePath"] = [videoContent mediaFilePath];
514+
dict[@"mediaFileName"] = [videoContent fileName];
515+
dict[@"videoDuration"] = [videoContent videoThumbImageLocalPath];
516+
dict[@"videoDuration"] = [videoContent duration];
517+
break;
518+
}
505519
case kJMSGContentTypeCustom: {
506520
dict[@"type"] = @"custom";
507521
JMSGCustomContent *customContent = (JMSGCustomContent *) self.content;

src/ios/Plugins/JMessagePlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
- (void)downloadThumbImage:(CDVInvokedUrlCommand *)command;
5656
- (void)downloadOriginalImage:(CDVInvokedUrlCommand *)command;
5757
- (void)downloadVoiceFile:(CDVInvokedUrlCommand *)command;
58+
- (void)downloadVideoFile:(CDVInvokedUrlCommand *)command;
5859
- (void)downloadFile:(CDVInvokedUrlCommand *)command;
5960
- (void)createConversation:(CDVInvokedUrlCommand *)command;
6061
- (void)deleteConversation:(CDVInvokedUrlCommand *)command;

0 commit comments

Comments
 (0)