zoukankan      html  css  js  c++  java
  • 商业化IM 客户端设计---Message模型

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

      

  • 相关阅读:
    mysql limit
    random.nextint()
    “MSDTC 事务的导入失败: Result Code = 0x8004d00e。
    JUnit-4.11使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
    iOS ERROR: unable to get the receiver data from the DB 解决方式
    STL algorithm算法mov,move_backward(38)
    看 《一次谷歌面试趣事》 后感
    C++胜者树
    拿年终奖前跳槽,你才是赢家!
    日期字符串格式化成日期/日期格式化成指定格式字符串
  • 原文地址:https://www.cnblogs.com/nuanshou/p/5867262.html
Copyright © 2011-2022 走看看