在IM开发中,一个问题是怎么管理传输,包括处理消息发送,消息接受和怎么转发等等,就是上一篇文章提到的IMService扮演的角色。另一个问题就是传输的具体数据是怎么定义的,既包括业务数据(文字,语音,图片,地理位置等),也包括控制数据(音频请求,加群请求,离群请求)。现在通过分析Message实体类来学习一下。

下面一系列的常量定义了Message的type

#define MSG_HEARTBEAT 1  //心跳
#define MSG_AUTH 2 //认证
#define MSG_AUTH_STATUS 3 //认证状态
#define MSG_IM 4
#define MSG_ACK 5 //ACK
#define MSG_RST 6
#define MSG_GROUP_NOTIFICATION 7 //群消息
#define MSG_GROUP_IM 8 //群消息
#define MSG_PEER_ACK 9 //ACK
#define MSG_INPUTING 10 //输入
#define MSG_SUBSCRIBE_ONLINE_STATE 11 //在线状态
#define MSG_ONLINE_STATE 12 //在线状态
#define MSG_PING 13 //
#define MSG_PONG 14 //
#define MSG_AUTH_TOKEN 15 //TOKEN
#define MSG_LOGIN_POINT 16 //多点登录
#define MSG_RT 17
#define MSG_ENTER_ROOM 18 //进入聊天室
#define MSG_LEAVE_ROOM 19 //离开聊天室
#define MSG_ROOM_IM 20 //聊天室消息
#define MSG_SYSTEM 21 //系统消息
#define MSG_UNREAD_COUNT 22 //未读消息数
#define MSG_CUSTOMER_SERVICE 23 //客服服务消息
#define MSG_CUSTOMER 24 //客服消息
#define MSG_CUSTOMER_SUPPORT 25 //客服支持
#define MSG_VOIP_CONTROL 64 //VOIP命令

  下面几个常量定义了平台type

#define PLATFORM_IOS  1
#define PLATFORM_ANDROID 2
#define PLATFORM_WEB 3

  IMMessage类由接受者ID,发送者ID,时间戳,消息本地存储ID,消息内容构成,见下面代码。

@interface IMMessage : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@property(nonatomic, assign)int32_t timestamp;
@property(nonatomic, assign)int32_t msgLocalID;
@property(nonatomic, copy)NSString *content;
@end

  CustomerMessage,客服消息类,和通用的IM消息格式差别在,customerID,sellerID,customerAppID,storeID这几个属性需要根据客服消息特定的使用场景来理解。

@interface CustomerMessage : NSObject
//本地消息id 不会序列化传到服务器
@property(nonatomic, assign)int32_t msgLocalID;本地存储ID
@property(nonatomic, assign)int64_t customerAppID;//APPid
@property(nonatomic, assign)int64_t customerID;//客服用户ID
@property(nonatomic, assign)int64_t storeID;//商铺ID
@property(nonatomic, assign)int64_t sellerID;//客服ID
@property(nonatomic, assign)int32_t timestamp;
@property(nonatomic, copy)NSString *content;
@end

RoomMessage 聊天室消息

  

@interface RoomMessage : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@property(nonatomic, copy)NSString *content;
@end

  

消息输入状态

typedef RoomMessage RTMessage;

@interface MessageInputing : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@end

    

  授权结构体

@interface AuthenticationToken : NSObject
@property(nonatomic, copy) NSString *token;
@property(nonatomic, assign) int8_t platformID;
@property(nonatomic, copy) NSString *deviceID;
@end

  

  多点登录结构体

@interface LoginPoint : NSObject
@property(nonatomic, assign) int32_t upTimestamp;
@property(nonatomic, assign) int8_t platformID;
@property(nonatomic, copy) NSString *deviceID;
@end
@interface VOIPControl : NSObject
@property(nonatomic, assign) int64_t sender;
@property(nonatomic, assign) int64_t receiver;
@property(nonatomic) NSData *content; @end

  

@interface Message : NSObject
@property(nonatomic, assign)int cmd;
@property(nonatomic, assign)int seq;
@property(nonatomic) NSObject *body; -(NSData*)pack; -(BOOL)unpack:(NSData*)data;
@end

  如果想要在现有的消息类型上支持新的消息类型,比如(实时定位,阅后即焚,(T)一下)。需要在Message基础上做扩展。

完整的代码和DEMO可以到[Gobelieve IM]查看。

  

商业化IM 客户端设计---Message模型的更多相关文章

  1. GPS部标平台的架构设计(九)-GPS监控客户端设计

    交通部的部标过检,所有的测试都是从客户端发起的,也是在客户端体现的,在客户端承载了部标标准所要求的所有的功能,是整个部标平台当中工作量最大的部分,也是最繁琐的部分. 客户端设计面临两个问题: 1.基于 ...

  2. Android 客户端设计之环境考虑

    我做过两三个android客户端应用的整体设计和部分的编码,这里仅仅谈一下设计方面的故事(此乃原创2015:11:02). 做客户端设计,首先要考虑应用所在的环境,包括三方面:1 要设计的apk是在一 ...

  3. iOS 非ARC基本内存管理系列总结6 -设计微博模型

    设计简单的微博模型:用User类和Status类来模拟实现 在非ARC机制下有两种方式,两者没有太大的区别之所以写了两种只是为了方便学习和对比两种写法! 第一种:没有使用atuorelease和自动释 ...

  4. $1200元 设计数据挖掘模型及对应RESTful Web Service

    利用MongoDB和NodeJS/Java设计数据挖掘模型以及对应的RESTful Web Service.要求:1. 精通MongoDB集群的配置2. 精通MongoDB Sehll的使用3. 精通 ...

  5. Linux 下 简单客户端服务器通讯模型(TCP)

    原文:Linux 下 简单客户端服务器通讯模型(TCP) 服务器端:server.c #include<stdio.h> #include<stdlib.h> #include ...

  6. [并发并行]_[线程模型]_[Pthread线程使用模型之三 客户端/服务端模型(Client/Server]

    Pthread线程使用模型之三 客户端/服务端模型(Client/Server) 场景 1.在客户端/服务端模型时,客户端向服务端请求一些数据集的操作. 服务端执行执行操作独立的(多进程或跨网络)– ...

  7. 系统编程-网络-tcp客户端服务器编程模型(续)、连接断开、获取连接状态场景

    相关博文: 系统编程-网络-tcp客户端服务器编程模型.socket.htons.inet_ntop等各API详解.使用telnet测试基本服务器功能 接着该上篇博文,咱们继续,首先,为了内容的完整性 ...

  8. 商业化IM 客户端接口设计分析

    对于刚接触IM(即时通讯)开发,通过阅读成熟的商业代码能够对即时通讯软件大体上有个认识,比如消息发送,消息接受,消息监听,群聊,单聊,聊天室.我这边直接拿[Gobelieve IM]源码来做剖析.IM ...

  9. 表演的艺术,妖尾回合制战斗系统客户端设计[Unity]

    妖尾历经几年开发,终于在今年6月底顺利上线,笔者从2017年初参与开发,主要负责妖尾战斗系统开发.战斗作为游戏的核心玩法系统,涉及很多技术点,希望能借几篇文字,系统性总结MMORPG战斗系统的开发经验 ...

随机推荐

  1. H5,API的pushState(),replaceState()和popstate()用法

    pushState和replaceState是H5的API中新添加的两个方法.通过window.history方法来对浏览器历史记录的读写. pushState和replaceState 在 HTML ...

  2. html 之 position用法

    引用: position的四个属性值: 1.relative2.absolute3.fixed4.static下面分别讲述这四个属性. <div id="parent"> ...

  3. windows定位dll的搜索顺序

    原文:http://blog.csdn.net/zzxian/article/details/6429293 Visual C++ Windows 用来定位 DLL 的搜索路径 通过隐式和显式链接,W ...

  4. SpringBoot中Mybaties PageHelper插件使用

    首先引入pom.xml文件配置  <!-- mybatis --> <dependency>  <groupId>org.mybatis.spring.boot&l ...

  5. CSS居中问题:块级元素和行级元素在水平方向以及垂直方向的居中问题

    元素的居中问题是每个初学者碰到的第一个大问题,在此我总结了下各种块级 行级 水平 垂直 的居中方法,并尽量给出代码实例. 首先请先明白块级元素和行级元素的区别 块级元素 块级元素水平居中 1:marg ...

  6. gradle中文学习资料

    http://wiki.jikexueyuan.com/project/GradleUserGuide-Wiki/ https://www.gitbook.com/book/lippiouyang/g ...

  7. WebView设置透明和设置背景图片的方法

    http://blog.csdn.net/Vincent20111024/article/details/8478219 1. WebView若要设置背景图,直接设置web .setBackgroun ...

  8. Windows IO 性能简单测试

    转自:http://bbs.csdn.net/topics/360111289, 有改动. #include <windows.h> #include <stdio.h> #i ...

  9. python爬虫系列:(一)、安装scrapy

    1.安装python 下载好安装包,一路next安装即可 2.把python和pip加入环境变量. 我的电脑----->右键“属性”------>“高级系统设置”------->“环 ...

  10. google离线小恐龙-备份

    开启方法: 地址栏输入: chrome://dino 空格开始