WFCCNetworkService.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // WFCCNetworkService.h
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/11/5.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #ifndef WFCCNetworkService_h
  9. #define WFCCNetworkService_h
  10. #import <Foundation/Foundation.h>
  11. #import "WFCCMessage.h"
  12. extern const NSString *SDKVERSION;
  13. #pragma mark - 频道通知定义
  14. //群组信息更新通知
  15. extern NSString *kGroupInfoUpdated;
  16. //用户信息更新通知
  17. extern NSString *kUserInfoUpdated;
  18. //好友列表更新通知
  19. extern NSString *kFriendListUpdated;
  20. //好友请求信息更新通知
  21. extern NSString *kFriendRequestUpdated;
  22. //设置更新通知
  23. extern NSString *kSettingUpdated;
  24. //频道信息更新通知
  25. extern NSString *kChannelInfoUpdated;
  26. #pragma mark - 枚举值定义
  27. /**
  28. 连接状态
  29. - kConnectionStatusRejected: 被拒绝
  30. - kConnectionStatusLogout: 退出登录
  31. - kConnectionStatusUnconnected: 未连接
  32. - kConnectionStatusConnecting: 连接中
  33. - kConnectionStatusConnected: 已连接
  34. - kConnectionStatusReceiving: 获取离线消息中,可忽略
  35. */
  36. typedef NS_ENUM(NSInteger, ConnectionStatus) {
  37. kConnectionStatusRejected = -3,
  38. kConnectionStatusLogout = -2,
  39. kConnectionStatusUnconnected = -1,
  40. kConnectionStatusConnecting = 0,
  41. kConnectionStatusConnected = 1,
  42. kConnectionStatusReceiving = 2
  43. };
  44. #pragma mark - 连接状态&消息监听
  45. /**
  46. 连接状态的监听
  47. */
  48. @protocol ConnectionStatusDelegate <NSObject>
  49. /**
  50. 连接状态变化的回调
  51. @param status 连接状态
  52. */
  53. - (void)onConnectionStatusChanged:(ConnectionStatus)status;
  54. @end
  55. /**
  56. 消息接收的监听
  57. */
  58. @protocol ReceiveMessageDelegate <NSObject>
  59. /**
  60. 接收消息的回调
  61. @param messages 收到的消息
  62. @param hasMore 是否还有待接受的消息,UI可以根据此参数决定刷新的时机
  63. */
  64. - (void)onReceiveMessage:(NSArray<WFCCMessage *> *)messages hasMore:(BOOL)hasMore;
  65. @optional
  66. - (void)onRecallMessage:(long long)messageUid;
  67. @end
  68. /**
  69. 接收消息前的拦截Filter
  70. */
  71. @protocol ReceiveMessageFilter <NSObject>
  72. /**
  73. 是否拦截收到的消息
  74. @param message 消息
  75. @return 是否拦截,如果拦截该消息,则ReceiveMessageDelegate回调不会再收到此消息
  76. */
  77. - (BOOL)onReceiveMessage:(WFCCMessage *)message;
  78. @end
  79. #pragma mark - 连接服务
  80. /**
  81. 连接服务
  82. */
  83. @interface WFCCNetworkService : NSObject
  84. /**
  85. 连接服务单例
  86. @return 连接服务单例
  87. */
  88. + (WFCCNetworkService *)sharedInstance;
  89. /**
  90. 连接状态监听
  91. */
  92. @property(nonatomic, weak) id<ConnectionStatusDelegate> connectionStatusDelegate;
  93. /**
  94. 消息接收监听
  95. */
  96. @property(nonatomic, weak) id<ReceiveMessageDelegate> receiveMessageDelegate;
  97. /**
  98. 当前是否处于登陆状态
  99. */
  100. @property(nonatomic, assign, getter=isLogined, readonly)BOOL logined;
  101. /**
  102. 当前的连接状态
  103. */
  104. @property(nonatomic, assign, readonly)ConnectionStatus currentConnectionStatus;
  105. /**
  106. 当前登陆的用户ID
  107. */
  108. @property (nonatomic, strong, readonly)NSString *userId;
  109. /**
  110. 服务器时间与本地时间的差值
  111. */
  112. @property(nonatomic, assign, readonly)long long serverDeltaTime;
  113. /**
  114. 开启Log
  115. */
  116. + (void)startLog;
  117. /**
  118. 停止Log
  119. */
  120. + (void)stopLog;
  121. /**
  122. 获取客户端id
  123. @return 客户端ID
  124. */
  125. - (NSString *)getClientId;
  126. /**
  127. 连接服务器
  128. @param userId 用户Id
  129. @param token 密码
  130. */
  131. - (void)connect:(NSString *)userId token:(NSString *)token;
  132. /**
  133. 断开连接
  134. @param clearSession 是否清除Session信息
  135. */
  136. - (void)disconnect:(BOOL)clearSession;
  137. /**
  138. 设置服务器信息
  139. @param host 服务器地址
  140. */
  141. - (void)setServerAddress:(NSString *)host port:(uint)port;
  142. /**
  143. 设置当前设备的device token
  144. @param token 苹果APNs Device Token
  145. */
  146. - (void)setDeviceToken:(NSString *)token;
  147. /**
  148. 设置当前设备的Voip device token
  149. @param token 苹果APNs Device Token
  150. */
  151. - (void)setVoipDeviceToken:(NSString *)token;
  152. /**
  153. 添加消息拦截Filter
  154. @param filter 消息拦截Filter
  155. */
  156. - (void)addReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  157. /**
  158. 移除消息拦截Filter
  159. @param filter 消息拦截Filter
  160. */
  161. - (void)removeReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  162. /**
  163. 应用已经login且在后台的情况下,强制进行连接,确保后台连接5秒钟,用于voip推送后台刷新等场景。
  164. 应用在前台情况下,此方法无效。
  165. */
  166. - (void)forceConnect:(NSUInteger)second;
  167. - (void)cancelForceConnect;
  168. @end
  169. #endif