商业化IM 客户端设计---Message模型

1 篇文章 0 订阅

在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查看。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值