真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

商業(yè)化IM客戶端接口設(shè)計分析-創(chuàng)新互聯(lián)

  對于剛接觸IM(即時通訊)開發(fā),通過閱讀成熟的商業(yè)代碼能夠?qū)磿r通訊軟件大體上有個認識,比如消息發(fā)送,消息接受,消息監(jiān)聽,群聊,單聊,聊天室。我這邊直接拿[Gobelieve IM] 源碼來做剖析。IMService在代碼層級里起著承上啟下的作用,負責發(fā)送消息,接受消息(聊天消息,系統(tǒng)消息,控制命令消息(比如邀請VOIP,退群,加群)),消息在客戶端轉(zhuǎn)發(fā),消息類型判斷和分發(fā),消息observer的增加和刪除,IMService本身會根據(jù)業(yè)務(wù)需求實現(xiàn)handlers對接到數(shù)據(jù)傳輸層(socket)。Observers是銜接IMService和UI層。如果只側(cè)重于UI層開發(fā),重點是Observers,比如PeerMessageObserver是一對一聊天監(jiān)聽,GroupMessageObserver:群聊天監(jiān)聽,RoomMessageObserver:聊天室監(jiān)聽。

創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)阜新,十年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108下面直接上接口代碼來說,
@class IMessage;

  IMessage 模型類的前置聲明

@protocol IMPeerMessageHandler 
-(BOOL)handleMessage:(IMMessage*)msg uid:(int64_t)uid;
-(BOOL)handleMessageACK:(int)msgLocalID uid:(int64_t)uid;
-(BOOL)handleMessageFailure:(int)msgLocalID uid:(int64_t)uid;
@end

  一對一聊天的hanlder定義,IM有一個ACK的設(shè)計,用來顯示消息是否已經(jīng)通過服務(wù)器下發(fā)到對方客戶端。具體的函數(shù),handleMessage()接收到消息的處理函數(shù)。handleMessageACK()接收到消息已讀的處理函數(shù)。 handleMessageFailure()接收到消息發(fā)送失敗的處理函數(shù)。

@protocol IMGroupMessageHandler 

-(BOOL)handleMessage:(IMMessage*)msg;
-(BOOL)handleMessageACK:(int)msgLocalID gid:(int64_t)gid;
-(BOOL)handleMessageFailure:(int)msgLocalID gid:(int64_t)gid;

-(BOOL)handleGroupNotification:(NSString*)notification;
@end

   群聊天的hanlder定義,接口上比單聊多一個群狀態(tài)改變的處理,還有就是單聊下發(fā)的是個人ID,群聊下發(fā)的是群聊ID,同樣的函數(shù),handleMessage()接收到消息的處理函數(shù)。handleMessageACK()接收到消息已讀的處理函數(shù)。 handleMessageFailure()接收到消息發(fā)送失敗的處理函數(shù)。handleGroupNotification(),處理群狀態(tài)改變的函數(shù),比如群名稱改變,群成員改變,群解散等等事件。

@protocol IMCustomerMessageHandler 
-(BOOL)handleCustomerSupportMessage:(CustomerMessage*)msg;
-(BOOL)handleMessage:(CustomerMessage*)msg;
-(BOOL)handleMessageACK:(CustomerMessage*)msg;
-(BOOL)handleMessageFailure:(CustomerMessage*)msg;
@end

  客服聊天的handler定義。

@protocol LoginPointObserver 
//用戶在其他地方登陸
-(void)onLoginPoint:(LoginPoint*)lp;
@end

  多端登錄事件監(jiān)聽。

@protocol PeerMessageObserver 
@optional
-(void)onPeerMessage:(IMMessage*)msg;

//服務(wù)器ack
-(void)onPeerMessageACK:(int)msgLocalID uid:(int64_t)uid;

//消息發(fā)送失敗
-(void)onPeerMessageFailure:(int)msgLocalID uid:(int64_t)uid;

//對方正在輸入
-(void)onPeerInputing:(int64_t)uid;

@end

  一對一聊天的Observer的定義,提供了對輸入狀態(tài)監(jiān)聽的接口,用來實現(xiàn),實時獲取對方是否在編輯消息。

@protocol GroupMessageObserver 
@optional
-(void)onGroupMessage:(IMMessage*)msg;
-(void)onGroupMessageACK:(int)msgLocalID gid:(int64_t)gid;
-(void)onGroupMessageFailure:(int)msgLocalID gid:(int64_t)gid;

-(void)onGroupNotification:(NSString*)notification;
@end

  群聊天的Observer的定義。

@protocol RoomMessageObserver 
@optional
-(void)onRoomMessage:(RoomMessage*)rm;
-(void)onRoomMessageACK:(RoomMessage*)rm;
-(void)onRoomMessageFailure:(RoomMessage*)rm;

@end

  聊天室消息Observer的定義。

@protocol RTMessageObserver 

@optional
-(void)onRTMessage:(RTMessage*)rt;

@end

@protocol SystemMessageObserver 
@optional
-(void)onSystemMessage:(NSString*)sm;

@end

  系統(tǒng)消息的Observer的定義。

@protocol CustomerMessageObserver 
@optional
-(void)onCustomerMessage:(CustomerMessage*)msg;
-(void)onCustomerSupportMessage:(CustomerMessage*)msg;

//服務(wù)器ack
-(void)onCustomerMessageACK:(CustomerMessage*)msg;
//消息發(fā)送失敗
-(void)onCustomerMessageFailure:(CustomerMessage*)msg;
@end

  客服消息的Observer的定義。

@protocol VOIPObserver 

-(void)onVOIPControl:(VOIPControl*)ctl;

@end

  支持整合VOIP功能的Observer的定義。

@interface IMService : TCPConnection
@property(nonatomic, copy) NSString *deviceID;
@property(nonatomic, copy) NSString *token;
@property(nonatomic) int64_t uid;
//客服app需要設(shè)置,普通app不需要設(shè)置
@property(nonatomic) int64_t appID;

@property(nonatomic, weak)id peerMessageHandler;//一對一聊天Handler
@property(nonatomic, weak)id groupMessageHandler;//群聊handler
@property(nonatomic, weak)id customerMessageHandler;//客服handler

當前的IMService實現(xiàn)了三個(一對一聊天,群聊,客服)handler,可以按自己需要增加新的handler類型。消息統(tǒng)一在IMService做轉(zhuǎn)發(fā)。
根據(jù)注冊的Observer,傳遞到對該消息類型感興趣的界面。

+(IMService*)instance;//IMService是單例的形式使用

-(BOOL)isPeerMessageSending:(int64_t)peer id:(int)msgLocalID;
-(BOOL)isGroupMessageSending:(int64_t)groupID id:(int)msgLocalID;
-(BOOL)isCustomerSupportMessageSending:(int)msgLocalID
                            customerID:(int64_t)customerID
                         customerAppID:(int64_t)customerAppID;
-(BOOL)isCustomerMessageSending:(int)msgLocalID storeID:(int64_t)storeID;

-(BOOL)sendPeerMessage:(IMMessage*)msg;
-(BOOL)sendGroupMessage:(IMMessage*)msg;
-(BOOL)sendRoomMessage:(RoomMessage*)msg;
//顧客->客服
-(BOOL)sendCustomerMessage:(CustomerMessage*)im;
//客服->顧客
-(BOOL)sendCustomerSupportMessage:(CustomerMessage*)im;
-(BOOL)sendRTMessage:(RTMessage*)msg;

-(void)enterRoom:(int64_t)roomID;
-(void)leaveRoom:(int64_t)roomID;

//正在輸入
-(void)sendInputing:(MessageInputing*)inputing;
//更新未讀的消息數(shù)目
-(void)sendUnreadCount:(int)unread;

-(void)addPeerMessageObserver:(id)ob;
-(void)removePeerMessageObserver:(id)ob;

-(void)addGroupMessageObserver:(id)ob;
-(void)removeGroupMessageObserver:(id)ob;

-(void)addLoginPointObserver:(id)ob;
-(void)removeLoginPointObserver:(id)ob;

-(void)addRoomMessageObserver:(id)ob;
-(void)removeRoomMessageObserver:(id)ob;

-(void)addSystemMessageObserver:(id)ob;
-(void)removeSystemMessageObserver:(id)ob;

-(void)addCustomerMessageObserver:(id)ob;
-(void)removeCustomerMessageObserver:(id)ob;

-(void)addRTMessageObserver:(id)ob;
-(void)removeRTMessageObserver:(id)ob;
    
-(void)pushVOIPObserver:(id)ob;
-(void)popVOIPObserver:(id)ob;

-(BOOL)sendVOIPControl:(VOIPControl*)ctl;

@end

  坑下挖好,慢慢補充,完整的代碼和DEMO可以到[Gobelieve IM]查看。

[1]: http://developer.gobelieve.io/

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。


分享文章:商業(yè)化IM客戶端接口設(shè)計分析-創(chuàng)新互聯(lián)
地址分享:http://weahome.cn/article/cocdpe.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部