diff --git a/android/build.gradle b/android/build.gradle index 256b76d..a4986e7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -52,5 +52,5 @@ android { } dependencies { // implementation 'io.openim:client:0.0.13@aar' - implementation 'io.openim:client-sdk:0.0.4@aar' + implementation 'io.openim:client-sdk:0.0.6@aar' } \ No newline at end of file diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/manager/IMManager.java b/android/src/main/java/io/openim/flutter_openim_sdk/manager/IMManager.java index d4438ab..2983400 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/manager/IMManager.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/manager/IMManager.java @@ -11,7 +11,7 @@ public class IMManager { public void initSDK(MethodCall methodCall, MethodChannel.Result result) { Open_im_sdk.initSDK(CommonUtil.getSDKJsonParam(methodCall), new SDKListener()); - CommonUtil.runMainThreadReturn(result, null); +// CommonUtil.runMainThreadReturn(result, null); } public void login(MethodCall methodCall, MethodChannel.Result result) { diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/manager/MessageManager.java b/android/src/main/java/io/openim/flutter_openim_sdk/manager/MessageManager.java index 4997b6d..8a64f05 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/manager/MessageManager.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/manager/MessageManager.java @@ -106,6 +106,12 @@ public class MessageManager { CommonUtil.getImagePath(methodCall))); } + public void createImageMessageFromFullPath(MethodCall methodCall, MethodChannel.Result result) { + CommonUtil.runMainThreadReturn(result, + Open_im_sdk.createImageMessageFromFullPath( + CommonUtil.getImagePath(methodCall))); + } + public void createSoundMessage(MethodCall methodCall, MethodChannel.Result result) { CommonUtil.runMainThreadReturn(result, Open_im_sdk.createSoundMessage( @@ -113,6 +119,13 @@ public class MessageManager { CommonUtil.getSoundDuration(methodCall))); } + public void createSoundMessageFromFullPath(MethodCall methodCall, MethodChannel.Result result) { + CommonUtil.runMainThreadReturn(result, + Open_im_sdk.createSoundMessageFromFullPath( + CommonUtil.getSoundPath(methodCall), + CommonUtil.getSoundDuration(methodCall))); + } + public void createVideoMessage(MethodCall methodCall, MethodChannel.Result result) { CommonUtil.runMainThreadReturn(result, Open_im_sdk.createVideoMessage( @@ -122,6 +135,15 @@ public class MessageManager { CommonUtil.getVideoSnapshotPath(methodCall))); } + public void createVideoMessageFromFullPath(MethodCall methodCall, MethodChannel.Result result) { + CommonUtil.runMainThreadReturn(result, + Open_im_sdk.createVideoMessageFromFullPath( + CommonUtil.getVideoPath(methodCall), + CommonUtil.getVideoType(methodCall), + CommonUtil.getVideoDuration(methodCall), + CommonUtil.getVideoSnapshotPath(methodCall))); + } + public void createFileMessage(MethodCall methodCall, MethodChannel.Result result) { CommonUtil.runMainThreadReturn(result, Open_im_sdk.createFileMessage( @@ -137,12 +159,29 @@ public class MessageManager { CommonUtil.getSummaryList(methodCall))); } + public void createForwardMessage(MethodCall methodCall, MethodChannel.Result result) { CommonUtil.runMainThreadReturn(result, Open_im_sdk.createForwardMessage( CommonUtil.getForwardMessage(methodCall))); } + public void createLocationMessage(MethodCall methodCall, MethodChannel.Result result) { + CommonUtil.runMainThreadReturn(result, Open_im_sdk.createLocationMessage( + CommonUtil.getMessageDes(methodCall), + CommonUtil.getLocationLongitude(methodCall), + CommonUtil.getLocationLatitude(methodCall) + )); + } + + public void createCustomMessage(MethodCall methodCall, MethodChannel.Result result) { + CommonUtil.runMainThreadReturn(result, Open_im_sdk.createCustomMessage( + CommonUtil.getCustomMessageData(methodCall), + CommonUtil.getCustomMessageExt(methodCall), + CommonUtil.getMessageDes(methodCall) + )); + } + public void getTotalUnreadMsgCount(MethodCall methodCall, MethodChannel.Result result) { Open_im_sdk.getTotalUnreadMsgCount(new BaseListener(result)); } diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java b/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java index 8ee3be3..ac1e64d 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java @@ -263,6 +263,27 @@ public class CommonUtil { return getSDKJsonParam(methodCall, KEY_GROUP_APPLICATION_INFO); } + + public static double getLocationLatitude(MethodCall methodCall) { + return getParamValue(methodCall, KEY_LOCATION_MESSAGE_LA); + } + + public static double getLocationLongitude(MethodCall methodCall) { + return getParamValue(methodCall, KEY_LOCATION_MESSAGE_LO); + } + + public static String getMessageDes(MethodCall methodCall) { + return getParamValue(methodCall, KEY_MESSAGE_DES); + } + + public static byte[] getCustomMessageData(MethodCall methodCall) { + return getParamValue(methodCall, KEY_CUSTOM_MESSAGE_DATA); + } + + public static byte[] getCustomMessageExt(MethodCall methodCall) { + return getParamValue(methodCall, KEY_CUSTOM_MESSAGE_EXT); + } + //login final static String KEY_UID = "uid"; final static String KEY_TOKEN = "token"; @@ -282,6 +303,11 @@ public class CommonUtil { final static String KEY_MERGER_MESSAGE_TITLE = "title"; final static String KEY_SUMMARY_LIST = "summaryList"; final static String KEY_FORWARD_MESSAGE = "message"; + final static String KEY_LOCATION_MESSAGE_LO = "longitude"; + final static String KEY_LOCATION_MESSAGE_LA = "latitude"; + final static String KEY_MESSAGE_DES = "description"; + final static String KEY_CUSTOM_MESSAGE_DATA = "data"; + final static String KEY_CUSTOM_MESSAGE_EXT = "extension"; //send message final static String KEY_SEND_MESSAGE_CONTENT = "message"; final static String KEY_SEND_MESSAGE_CONTENT_CLIENT_ID = "clientMsgID"; diff --git a/lib/src/enum/message_type.dart b/lib/src/enum/message_type.dart index 95fd296..bcd9b6d 100644 --- a/lib/src/enum/message_type.dart +++ b/lib/src/enum/message_type.dart @@ -7,6 +7,9 @@ class MessageType { static const file = 105; static const at_text = 106; static const merger = 107; + static const forward = 108; + static const location = 109; + static const custom = 110; static const revoke = 111; static const has_read_receipt = 112; static const typing = 113; @@ -18,12 +21,12 @@ class MessageType { static const set_self_info = 204; static const revoke_message = 205; static const c2c_message_as_read = 206; + static const kick_online = 303; /// static const transfer_group_owner = 501; static const create_group = 502; - // static const create_group = 503; static const join_group = 504; static const quit_group = 505; diff --git a/lib/src/listener/init_sdk_listener.dart b/lib/src/listener/init_sdk_listener.dart index 3711817..20879dd 100644 --- a/lib/src/listener/init_sdk_listener.dart +++ b/lib/src/listener/init_sdk_listener.dart @@ -8,7 +8,7 @@ class InitSDKListener { void onConnectSuccess() {} /// SDK 连接服务器失败 - void onConnectFailed(int? int, String? errorMsg) {} + void onConnectFailed(int? code, String? errorMsg) {} /// 当前用户被踢下线,此时可以 UI 提示用户,并再次调用 IMManager 的 login() 函数重新登录。 void onKickedOffline() {} diff --git a/lib/src/manager/im_message_manager.dart b/lib/src/manager/im_message_manager.dart index 4db74a0..e228d7c 100644 --- a/lib/src/manager/im_message_manager.dart +++ b/lib/src/manager/im_message_manager.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:flutter/services.dart'; import 'package:flutter_openim_sdk/flutter_openim_sdk.dart'; @@ -194,6 +195,15 @@ class MessageManager { .then((value) => _toObj(value)); } + Future createImageMessageFromFullPath({required String imagePath}) { + return _channel + .invokeMethod( + 'createImageMessageFromFullPath', + _buildParam({'imagePath': imagePath}), + ) + .then((value) => _toObj(value)); + } + /// Future createSoundMessage({ required String soundPath, @@ -207,6 +217,18 @@ class MessageManager { .then((value) => _toObj(value)); } + Future createSoundMessageFromFullPath({ + required String soundPath, + required int duration, + }) { + return _channel + .invokeMethod( + 'createSoundMessageFromFullPath', + _buildParam({'soundPath': soundPath, "duration": duration}), + ) + .then((value) => _toObj(value)); + } + /// Future createVideoMessage({ required String videoPath, @@ -226,6 +248,24 @@ class MessageManager { .then((value) => _toObj(value)); } + Future createVideoMessageFromFullPath({ + required String videoPath, + required String videoType, + required int duration, + required String snapshotPath, + }) { + return _channel + .invokeMethod( + 'createVideoMessageFromFullPath', + _buildParam({ + 'videoPath': videoPath, + 'videoType': videoType, + 'duration': duration, + 'snapshotPath': snapshotPath, + })) + .then((value) => _toObj(value)); + } + /// Future createFileMessage({ required String filePath, @@ -269,6 +309,38 @@ class MessageManager { .then((value) => _toObj(value)); } + Future createLocationMessage({ + required double latitude, + required double longitude, + required String description, + }) { + return _channel + .invokeMethod( + 'createLocationMessage', + _buildParam({ + 'latitude': latitude, + 'longitude': longitude, + 'description': description, + })) + .then((value) => _toObj(value)); + } + + Future createCustomMessage({ + required Uint8List data, + required Uint8List extension, + required String description, + }) { + return _channel + .invokeMethod( + 'createCustomMessage', + _buildParam({ + 'data': data, + 'extension': extension, + 'description': description, + })) + .then((value) => _toObj(value)); + } + /// Future getTotalUnreadMsgCount() { return _channel.invokeMethod('getTotalUnreadMsgCount', _buildParam({})); diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 884726b..335f492 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + class Message { String? clientMsgID; String? serverMsgID; @@ -24,6 +26,8 @@ class Message { VideoElem? videoElem; FileElem? fileElem; AtElem? atElem; + LocationElem? locationElem; + CustomElem? customElem; Message({ this.clientMsgID, @@ -51,6 +55,8 @@ class Message { this.videoElem, this.fileElem, this.atElem, + this.locationElem, + this.customElem, }); Message.fromJson(Map json) @@ -89,6 +95,13 @@ class Message { fileElem = json['fileElem'] != null ? FileElem.fromJson(json['fileElem']) : null; atElem = json['atElem'] != null ? AtElem.fromJson(json['atElem']) : null; + locationElem = json['locationElem'] != null + ? LocationElem.fromJson(json['locationElem']) + : null; + + customElem = json['customElem'] != null + ? CustomElem.fromJson(json['customElem']) + : null; } Map toJson() { @@ -113,21 +126,13 @@ class Message { data['remark'] = this.remark; data['ext'] = this.ext; data['sessionType'] = this.sessionType; - if (this.pictureElem != null) { - data['pictureElem'] = this.pictureElem!.toJson(); - } - if (this.soundElem != null) { - data['soundElem'] = this.soundElem!.toJson(); - } - if (this.videoElem != null) { - data['videoElem'] = this.videoElem!.toJson(); - } - if (this.fileElem != null) { - data['fileElem'] = this.fileElem!.toJson(); - } - if (this.atElem != null) { - data['atElem'] = this.atElem!.toJson(); - } + data['pictureElem'] = this.pictureElem?.toJson(); + data['soundElem'] = this.soundElem?.toJson(); + data['videoElem'] = this.videoElem?.toJson(); + data['fileElem'] = this.fileElem?.toJson(); + data['atElem'] = this.atElem?.toJson(); + data['locationElem'] = this.locationElem?.toJson(); + data['customElem'] = this.customElem?.toJson(); return data; } @@ -368,6 +373,59 @@ class AtElem { } } +class LocationElem { + String? description; + double? longitude; + double? latitude; + + LocationElem({this.description, this.longitude, this.latitude}); + + LocationElem.fromJson(Map json) { + description = json['description']; + if (json['longitude'] is int) { + longitude = (json['longitude'] as int).toDouble(); + } else { + longitude = json['longitude']; + } + + if (json['latitude'] is int) { + latitude = (json['latitude'] as int).toDouble(); + } else { + latitude = json['latitude']; + } + } + + Map toJson() { + final Map data = new Map(); + data['description'] = this.description; + data['longitude'] = this.longitude; + data['latitude'] = this.latitude; + return data; + } +} + +class CustomElem { + Uint8List? data; + Uint8List? extension; + String? description; + + CustomElem({this.data, this.extension, this.description}); + + CustomElem.fromJson(Map json) { + data = json['data']; + extension = json['extension']; + description = json['description']; + } + + Map toJson() { + final Map data = new Map(); + data['data'] = this.data; + data['extension'] = this.extension; + data['description'] = this.description; + return data; + } +} + class HaveReadInfo { String? uid; List? msgIDList; @@ -376,13 +434,12 @@ class HaveReadInfo { int? contentType; int? sessionType; - HaveReadInfo( - {this.uid, - this.msgIDList, - this.readTime, - this.msgFrom, - this.contentType, - this.sessionType}); + HaveReadInfo({this.uid, + this.msgIDList, + this.readTime, + this.msgFrom, + this.contentType, + this.sessionType}); HaveReadInfo.fromJson(Map json) { uid = json['uid'];