新聞中心
在IM開發(fā)中,一個問題是怎么管理傳輸,包括處理消息發(fā)送,消息接受和怎么轉(zhuǎn)發(fā)等等,就是上一篇文章提到的IMService扮演的角色。另一個問題就是傳輸?shù)木唧w數(shù)據(jù)是怎么定義的,既包括業(yè)務數(shù)據(jù)(文字,語音,圖片,地理位置等),也包括控制數(shù)據(jù)(音頻請求,加群請求,離群請求)?,F(xiàn)在通過分析Message實體類來學習一下。
下面一系列的常量定義了Message的type
#define MSG_HEARTBEAT 1 //心跳 #define MSG_AUTH 2 //認證 #define MSG_AUTH_STATUS 3 //認證狀態(tài) #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 //在線狀態(tài) #define MSG_ONLINE_STATE 12 //在線狀態(tài) #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 //系統(tǒng)消息 #define MSG_UNREAD_COUNT 22 //未讀消息數(shù) #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,發(fā)送者ID,時間戳,消息本地存儲ID,消息內(nèi)容構成,見下面代碼。
@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這幾個屬性需要根據(jù)客服消息特定的使用場景來理解。
@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
消息輸入狀態(tài)
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
如果想要在現(xiàn)有的消息類型上支持新的消息類型,比如(實時定位,閱后即焚,(T)一下)。需要在Message基礎上做擴展。
完整的代碼和DEMO可以到[Gobelieve IM]查看。
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站名稱:商業(yè)化IM客戶端設計---Message模型-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://fisionsoft.com.cn/article/dsjgej.html