Skip to content

Commit

Permalink
Merge pull request #101 from wicked-tc130/master
Browse files Browse the repository at this point in the history
update version to 4.1.2
  • Loading branch information
wicked-tc130 committed Apr 29, 2019
2 parents 5b227c1 + 2583cf6 commit 3de787f
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 41 deletions.
13 changes: 13 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@
}, (error) => {
alert("Send message fail: " + error.description);
});
//这里的路径以android为例
// var videoFilePath = "sdcard/DCIM/1.mp4";
// var videoFileName = "xxxxxx";
// var videoImagePath = "sdcard/DCIM/1.png";
// var videoImageFormat = "png";
// var videoDuration = 10;
// window.JMessage.sendVideoMessage({'type': 'single','username': username,'appKey': appKey,
// "videoFilePath":videoFilePath,"videoFileName":videoFileName,"videoImagePath":videoImagePath,"videoImageFormat":videoImageFormat,"videoDuration":videoDuration},
// (msg) => {
// console.log("sendVideo success");
// },(error) => {
// console.log("sendVideo error:"+error.description);
// });
}

function addConversation() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jmessage-phonegap-plugin",
"version": "4.1.1",
"version": "4.1.2",
"description": "JMessage Cordova Plugin.",
"cordova": {
"id": "jmessage-phonegap-plugin",
Expand Down
188 changes: 153 additions & 35 deletions src/android/JMessagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

Expand All @@ -21,6 +23,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -46,6 +49,7 @@
import cn.jpush.im.android.api.content.ImageContent;
import cn.jpush.im.android.api.content.LocationContent;
import cn.jpush.im.android.api.content.TextContent;
import cn.jpush.im.android.api.content.VideoContent;
import cn.jpush.im.android.api.content.VoiceContent;
import cn.jpush.im.android.api.enums.ContentType;
import cn.jpush.im.android.api.event.ChatRoomMessageEvent;
Expand Down Expand Up @@ -628,6 +632,57 @@ void sendVoiceMessage(JSONArray data, CallbackContext callback) {
}
}

void sendVideoMessage(JSONArray data, CallbackContext callback) {
boolean hasPermission = PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (!hasPermission) {
handleResult(ERR_CODE_PERMISSION, ERR_MSG_PERMISSION_WRITE_EXTERNAL_STORAGE, callback);
return;
}
String videoFilePath;
String videoFileName;
String videoImagePath;
String videoImageFormat;
int videoDuration;
Map<String, String> extras = null;
MessageSendingOptions messageSendingOptions = null;
Conversation conversation;
try {
JSONObject params = data.getJSONObject(0);
conversation = JMessageUtils.createConversation(params);
if (conversation == null) {
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
return;
}
videoFilePath = params.getString("videoFilePath");
videoFileName = params.getString("videoFileName");
videoImagePath = params.getString("videoImagePath");
videoImageFormat = params.getString("videoImageFormat");
videoDuration = params.getInt("videoDuration");
if (params.has("extras")) {
extras = fromJson(params.getJSONObject("extras"));
}
if (params.has("messageSendingOptions")) {
messageSendingOptions = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
}
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
return;
}
try {
Bitmap thumbImage = BitmapFactory.decodeFile(videoImagePath);
File videoFile = new File(videoFilePath);
VideoContent videoContent = new VideoContent(thumbImage, videoImageFormat, videoFile, videoFileName, videoDuration);
if (extras != null) {
videoContent.setExtras(extras);
}
sendMessage(conversation, videoContent, messageSendingOptions, callback);
} catch (IOException e) {
e.printStackTrace();
handleResult(ERR_CODE_FILE, ERR_MSG_FILE, callback);
}
}

void sendCustomMessage(JSONArray data, CallbackContext callback) {
try {
JSONObject params = data.getJSONObject(0);
Expand Down Expand Up @@ -1061,6 +1116,48 @@ public void onComplete(int status, String desc, File file) {
});
}

void downloadVideoFile(JSONArray data, final CallbackContext callback) {
final Message msg;

try {
JSONObject params = data.getJSONObject(0);
msg = JMessageUtils.getMessage(params);
if (msg == null) {
handleResult(ERR_CODE_MESSAGE, ERR_MSG_MESSAGE, callback);
return;
}
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
return;
}

if (msg.getContentType() != ContentType.file) {
handleResult(ERR_CODE_MESSAGE, "Message type isn't video", callback);
return;
}

VideoContent content = (VideoContent) msg.getContent();
content.downloadVideoFile(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (status == 0) {
JSONObject result = new JSONObject();
try {
result.put("messageId", msg.getId());
result.put("filePath", file.getAbsolutePath());
} catch (JSONException e) {
e.printStackTrace();
}
handleResult(result, status, desc, callback);

} else {
handleResult(status, desc, callback);
}
}
});
}

void downloadFile(JSONArray data, final CallbackContext callback) {
final Message msg;

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

switch (msg.getContentType()) {
case image:
((ImageContent) msg.getContent()).downloadThumbnailImage(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (fI == fLatestMediaMessageIndex) {
for (Message msg : offlineMsgList) {
msgJsonArr.put(toJson(msg));
}
try {
json.put("messageArray", msgJsonArr);
} catch (JSONException e) {
e.printStackTrace();
}
case image:
((ImageContent) msg.getContent()).downloadThumbnailImage(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (fI == fLatestMediaMessageIndex) {
for (Message msg : offlineMsgList) {
msgJsonArr.put(toJson(msg));
}
try {
json.put("messageArray", msgJsonArr);
} catch (JSONException e) {
e.printStackTrace();
}

JSONObject eventJson = toJson("syncOfflineMessage", json);
eventSuccess(eventJson);
}
}
});
break;
case voice:
((VoiceContent) msg.getContent()).downloadVoiceFile(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (fI == fLatestMediaMessageIndex) {
for (Message msg : offlineMsgList) {
msgJsonArr.put(toJson(msg));
JSONObject eventJson = toJson("syncOfflineMessage", json);
eventSuccess(eventJson);
}
try {
json.put("messageArray", msgJsonArr);
} catch (JSONException e) {
e.printStackTrace();
}
});
break;
case voice:
((VoiceContent) msg.getContent()).downloadVoiceFile(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (fI == fLatestMediaMessageIndex) {
for (Message msg : offlineMsgList) {
msgJsonArr.put(toJson(msg));
}
try {
json.put("messageArray", msgJsonArr);
} catch (JSONException e) {
e.printStackTrace();
}

JSONObject eventJson = toJson("syncOfflineMessage", json);
eventSuccess(eventJson);
}
}
});
break;
case video:
((VideoContent) msg.getContent()).downloadVideoFile(msg, new DownloadCompletionCallback() {
@Override
public void onComplete(int status, String desc, File file) {
if (fI == fLatestMediaMessageIndex) {
for (Message msg : offlineMsgList) {
msgJsonArr.put(toJson(msg));
}
try {
json.put("messageArray", msgJsonArr);
} catch (JSONException e) {
e.printStackTrace();
}

JSONObject eventJson = toJson("syncOfflineMessage", json);
eventSuccess(eventJson);
JSONObject eventJson = toJson("syncOfflineMessage", json);
eventSuccess(eventJson);
}
}
}
});
default:
});
break;
default:
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/android/JMessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;

import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
Expand Down Expand Up @@ -39,6 +40,7 @@ static void handleResult(int status, String desc, CallbackContext callback) {
callback.success();
} else {
try {
JSONObject errorObject = getErrorObject(status, desc);
callback.error(getErrorObject(status, desc));
} catch (JSONException e) {
e.printStackTrace();
Expand Down
18 changes: 16 additions & 2 deletions src/ios/Plugins/JMessageHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ - (void)onReceiveUserLoginStatusChangeEvent:(JMSGUserLoginStatusChangeEvent *)ev
switch (event.eventType) {
case kJMSGEventNotificationLoginKicked:
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
object:@{@"type":@"user_kicked"}];
object:@{@"type":@"user_logout"}];
break;
case kJMSGEventNotificationServerAlterPassword:
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
object:@{@"type":@"user_password_change"}];
break;
case kJMSGEventNotificationUserLoginStatusUnexpected:
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
object:@{@"type":@"user_login_state_unexpected"}];
object:@{@"type":@"user_login_status_unexpected"}];
break;
case kJMSGEventNotificationCurrentUserDeleted:
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageLoginStateChanged
object:@{@"type":@"user_deleted"}];
break;
}
}
Expand Down Expand Up @@ -502,6 +506,16 @@ - (NSMutableDictionary *)messageToDictionary {
dict[@"duration"] = [voiceContent duration];
break;
}
case kJMSGContentTypeVideo: {
dict[@"type"] = @"video";
dict[@"mediaFilePath"] = [self getOriginMediaFilePath];
JMSGVideoContent *videoContent = (JMSGVideoContent *) self.content;
//dict[@"mediaFilePath"] = [videoContent mediaFilePath];
dict[@"mediaFileName"] = [videoContent fileName];
dict[@"videoDuration"] = [videoContent videoThumbImageLocalPath];
dict[@"videoDuration"] = [videoContent duration];
break;
}
case kJMSGContentTypeCustom: {
dict[@"type"] = @"custom";
JMSGCustomContent *customContent = (JMSGCustomContent *) self.content;
Expand Down
1 change: 1 addition & 0 deletions src/ios/Plugins/JMessagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- (void)downloadThumbImage:(CDVInvokedUrlCommand *)command;
- (void)downloadOriginalImage:(CDVInvokedUrlCommand *)command;
- (void)downloadVoiceFile:(CDVInvokedUrlCommand *)command;
- (void)downloadVideoFile:(CDVInvokedUrlCommand *)command;
- (void)downloadFile:(CDVInvokedUrlCommand *)command;
- (void)createConversation:(CDVInvokedUrlCommand *)command;
- (void)deleteConversation:(CDVInvokedUrlCommand *)command;
Expand Down
Loading

0 comments on commit 3de787f

Please sign in to comment.