温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-10 03:08:07 来源:网络 阅读:1220 作者:gobelieve_io 栏目:移动开发

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

  

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI