diff --git a/README.md b/README.md index d9bcfbf..96499e5 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,16 @@ import 'package:wukongimfluttersdk/wkim.dart'; ``` +**安装方式** +需要手动下载该项目到本地,注意:与你的开发项目在同一目录下 +1. 打开pubspec + 项目目录下找到 pubspec.yaml +2. 在 dependencies 中添加 +```yaml +wukongimfluttersdk: + path: ../wkim/ +``` + **初始化sdk** ```dart WKIM.shared.setup(Options.newDefault('uid', 'token')); @@ -27,6 +37,7 @@ WKIM.shared.options.getAddr = (Function(String address) complete) async { ```dart WKIM.shared.connectionManager.connect(); ``` + **断开** ```dart // isLogout true:退出并不再重连 false:退出保持重连 @@ -57,18 +68,21 @@ WKIM.shared.connectionManager.addOnConnectionStatus('home', } }); ``` + **消息入库** ```dart WKIM.shared.messageManager.addOnMsgInsertedListener((wkMsg) { // todo 展示在UI上 }); ``` + **收到新消息** ```dart WKIM.shared.messageManager.addOnNewMsgListener('chat', (msgs) { // todo 展示在UI上 }); ``` + **刷新某条消息** ```dart WKIM.shared.messageManager.addOnRefreshMsgListener('chat', (wkMsg) { @@ -82,6 +96,7 @@ WKIM.shared.cmdManager.addOnCmdListener('chat', (cmdMsg) { // todo 按需处理cmd消息 }); ``` + - 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件 **发送消息时间** @@ -100,8 +115,8 @@ ntp7.aliyun.com **Socket链接逻辑** 将socket链接分成两部分: (链接成功之前,链接成功之后)这里是根据是否有返回消息/结合onDone来判断 1.链接成功之前:(链接中) - 当前没有任何处理,链接不成功的话不回重复链接。 - 需求是 链接不成功 时 每隔1.5秒重新链接。 + 链接不成功 时 每隔5秒重新链接。即没有返回消息并且onDone触发时会触发 5秒 后断线重连 + 当 WKIM.shared.connectionManager.disconnect 时会清理掉计时器。 2.链接成功之后 接首到消息返回,开启心跳检测/网络异常监听 diff --git a/lib/entity/channel.dart b/lib/entity/channel.dart index ab7f4c5..2c4a2a8 100644 --- a/lib/entity/channel.dart +++ b/lib/entity/channel.dart @@ -1,49 +1,70 @@ import '../type/const.dart'; +/// 频道 class WKChannel { String channelID = ""; int channelType = WKChannelType.personal; String channelName = ""; - //频道备注(频道的备注名称,个人的话就是个人备注,群的话就是群别名) + + /// 频道备注(频道的备注名称,个人的话就是个人备注,群的话就是群别名) String channelRemark = ""; int showNick = 0; - //是否置顶 + + /// 是否置顶 int top = 0; - //是否保存在通讯录 + + /// 是否保存在通讯录 int save = 0; - //免打扰 + + /// 免打扰 int mute = 0; - //禁言 + + /// 禁言 int forbidden = 0; - //邀请确认 + + /// 邀请确认 int invite = 0; - //频道状态[1:正常2:黑名单] + + /// 频道状态[1:正常2:黑名单] int status = 1; - //是否已关注 0.未关注(陌生人) 1.已关注(好友) + + /// 是否已关注 0.未关注(陌生人) 1.已关注(好友) int follow = 0; - //是否删除 + + /// 是否删除 int isDeleted = 0; - //创建时间 + + /// 创建时间 String createdAt = ""; - //修改时间 + + /// 修改时间 String updatedAt = ""; - //频道头像 + + /// 频道头像 String avatar = ""; - //版本 + + /// 版本 int version = 0; - //扩展字段 + + /// 扩展字段 dynamic localExtra; - //是否在线 + + /// 是否在线 int online = 0; - //最后一次离线时间 + + /// 最后一次离线时间 int lastOffline = 0; - // 最后一次离线设备标识 + + /// 最后一次离线设备标识 int deviceFlag = 0; - //是否回执消息 + + /// 是否回执消息 int receipt = 0; - // 机器人 + + /// 机器人 int robot = 0; - //分类[service:客服] + + /// 分类[service:客服] String category = ""; String username = ""; String avatarCacheKey = ""; @@ -53,8 +74,10 @@ class WKChannel { WKChannel(this.channelID, this.channelType); } +/// 频道搜索结果 class WKChannelSearchResult { WKChannel? channel; - // 包含的成员名称 + + /// 包含的成员名称 String containMemberName = ''; } diff --git a/lib/entity/channel_member.dart b/lib/entity/channel_member.dart index 5798e8a..8e391ac 100644 --- a/lib/entity/channel_member.dart +++ b/lib/entity/channel_member.dart @@ -1,36 +1,53 @@ +/// 频道成员 class WKChannelMember { String channelID = ""; - //频道类型 + + /// 频道类型 int channelType = 0; - //成员id + + /// 成员id String memberUID = ""; - //成员名称 + + /// 成员名称 String memberName = ""; - //成员备注 + + /// 成员备注 String memberRemark = ""; - //成员头像 + + /// 成员头像 String memberAvatar = ""; - //成员角色 + + /// 成员角色 int role = 0; - //成员状态黑名单等1:正常2:黑名单 + + /// 成员状态黑名单等1:正常2:黑名单 int status = 0; - //是否删除 + + /// 是否删除 int isDeleted = 0; - //创建时间 + + /// 创建时间 String createdAt = ""; - //修改时间 + + /// 修改时间 String updatedAt = ""; - //版本 + + /// 版本 int version = 0; - // 机器人0否1是 + + /// 机器人0否1是 int robot = 0; - //扩展字段 + + /// 扩展字段 dynamic extraMap; - // 用户备注 + + /// 用户备注 String remark = ""; - // 邀请者uid + + /// 邀请者uid String memberInviteUID = ""; - // 被禁言到期时间 + + /// 被禁言到期时间 int forbiddenExpirationTime = 0; String memberAvatarCacheKey = ""; } diff --git a/lib/entity/cmd.dart b/lib/entity/cmd.dart index 033f2e4..4ab3aca 100644 --- a/lib/entity/cmd.dart +++ b/lib/entity/cmd.dart @@ -1,8 +1,10 @@ +/// 同步命令 class WkSyncCMD { String cmd = ''; dynamic param; } +/// 命令 class WKCMD { String cmd = ''; dynamic param; diff --git a/lib/entity/conversation.dart b/lib/entity/conversation.dart index a555b49..1f44fc7 100644 --- a/lib/entity/conversation.dart +++ b/lib/entity/conversation.dart @@ -6,30 +6,40 @@ import 'cmd.dart'; import 'msg.dart'; import 'reminder.dart'; +/// 会话消息 class WKConversationMsg { - //频道id + /// 频道id String channelID = ''; - //频道类型 + + /// 频道类型 int channelType = WKChannelType.personal; - //最后一条消息本地ID + + /// 最后一条消息本地ID String lastClientMsgNO = ''; - //是否删除 + + /// 是否删除 int isDeleted = 0; - //服务器同步版本号 + + /// 服务器同步版本号 int version = 0; - //最后一条消息时间 + + /// 最后一条消息时间 int lastMsgTimestamp = 0; - //未读消息数量 + + /// 未读消息数量 int unreadCount = 0; - //最后一条消息序号 + + /// 最后一条消息序号 int lastMsgSeq = 0; - //扩展字段 + + /// 扩展字段 dynamic localExtraMap; WKConversationMsgExtra? msgExtra; String parentChannelID = ''; int parentChannelType = 0; } +/// 会话消息扩展 class WKConversationMsgExtra { String channelID = ''; int channelType = 0; @@ -41,26 +51,35 @@ class WKConversationMsgExtra { int draftUpdatedAt = 0; } +/// 用户界面对话消息 class WKUIConversationMsg { int lastMsgSeq = 0; String clientMsgNo = ''; - //频道ID + + /// 频道ID String channelID = ''; - //频道类型 + + /// 频道类型 int channelType = 0; - //最后一条消息时间 + + /// 最后一条消息时间 int lastMsgTimestamp = 0; - //消息频道 + + /// 消息频道 WKChannel? _wkChannel; - //消息正文 + + /// 消息正文 WKMsg? _wkMsg; - //未读消息数量 + + /// 未读消息数量 int unreadCount = 0; int isDeleted = 0; WKConversationMsgExtra? _remoteMsgExtra; - //高亮内容[{type:1,text:'[有人@你]'}] + + /// 高亮内容[{type:1,text:'[有人@你]'}] List? _reminderList; - //扩展字段 + + /// 扩展字段 dynamic localExtraMap; String parentChannelID = ''; int parentChannelType = 0; @@ -103,6 +122,7 @@ class WKUIConversationMsg { } } +/// 同步对话 class WKSyncConversation { int cmdVersion = 0; List? cmds; @@ -110,6 +130,7 @@ class WKSyncConversation { List? conversations; } +/// 同步对话消息 class WKSyncConvMsg { String channelID = ''; int channelType = 0; diff --git a/lib/entity/msg.dart b/lib/entity/msg.dart index c142a2d..b5f0ff9 100644 --- a/lib/entity/msg.dart +++ b/lib/entity/msg.dart @@ -10,6 +10,7 @@ import '../type/const.dart'; import 'channel.dart'; import 'channel_member.dart'; +/// 消息 class WKMsg { MessageHeader header = MessageHeader(); Setting setting = Setting(); diff --git a/lib/entity/reminder.dart b/lib/entity/reminder.dart index c38f35f..842fc11 100644 --- a/lib/entity/reminder.dart +++ b/lib/entity/reminder.dart @@ -1,3 +1,4 @@ +/// 消息提醒 class WKReminder { int reminderID = 0; String messageID = ''; @@ -15,6 +16,7 @@ class WKReminder { String publisher = ''; } +/// 提及类型 class WKMentionType { //有人@我 static const int wkReminderTypeMentionMe = 1; diff --git a/lib/main.dart b/lib/main.dart index dda5554..fd25cc4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,27 +7,11 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a blue toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), @@ -38,16 +22,6 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - final String title; @override @@ -59,50 +33,19 @@ class _MyHomePageState extends State { void _incrementCounter() { setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. _counter++; }); } @override Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( @@ -119,7 +62,7 @@ class _MyHomePageState extends State { onPressed: _incrementCounter, tooltip: 'Increment', child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ); } } diff --git a/lib/wkim.dart b/lib/wkim.dart index e098854..a516aca 100644 --- a/lib/wkim.dart +++ b/lib/wkim.dart @@ -18,13 +18,30 @@ import 'model/wk_card_content.dart'; class WKIM { WKIM._privateConstructor(); - int deviceFlagApp = 0; static final WKIM _instance = WKIM._privateConstructor(); - static WKIM get shared => _instance; + + /// 设备标志应用程序 + int deviceFlagApp = 0; + + /// 使用选项设备标志 + @Deprecated('Use Options deviceFlag') + void setDeviceFlag(int deviceFlag) { + deviceFlagApp = deviceFlag; + } + + /// 运行模式 Model runMode = Model.app; + + /// 运行模式 - 是否是APP + bool isApp() { + return runMode == Model.app; + } + + /// 配置 Options options = Options(); + /// 设置配置 Future setup(Options opts) async { options = opts; deviceFlagApp = opts.deviceFlag; @@ -39,6 +56,7 @@ class WKIM { return true; } + /// 初始化正常消息内容 _initNormalMsgContent() { messageManager.registerMsgContent(WkMessageContentType.text, (dynamic data) { @@ -62,20 +80,24 @@ class WKIM { }); } - @Deprecated('Use Options deviceFlag') - void setDeviceFlag(int deviceFlag) { - deviceFlagApp = deviceFlag; - } - - bool isApp() { - return runMode == Model.app; - } - + /// 连接管理器 WKWebConnectionManager connectionManager = WKWebConnectionManager.shared; + + /// 消息管理器 WKMessageManager messageManager = WKMessageManager.shared; + + /// 会话管理器 WKConversationManager conversationManager = WKConversationManager.shared; + + /// 渠道经理 WKChannelManager channelManager = WKChannelManager.shared; + + /// 渠道成员经理 WKChannelMemberManager channelMemberManager = WKChannelMemberManager.shared; + + /// 提醒管理器 WKReminderManager reminderManager = WKReminderManager.shared; + + /// 命令管理器 WKCMDManager cmdManager = WKCMDManager.shared; }