2
0

WFCCNetworkService.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #import "WFCCReadReport.h"
  13. #import "WFCCDeliveryReport.h"
  14. extern const NSString *SDKVERSION;
  15. #pragma mark - 通知定义
  16. //群组信息更新通知
  17. extern NSString *kGroupInfoUpdated;
  18. //群组成员更新通知
  19. extern NSString *kGroupMemberUpdated;
  20. //用户信息更新通知
  21. extern NSString *kUserInfoUpdated;
  22. //好友列表更新通知
  23. extern NSString *kFriendListUpdated;
  24. //好友请求信息更新通知
  25. extern NSString *kFriendRequestUpdated;
  26. //设置更新通知
  27. extern NSString *kSettingUpdated;
  28. //频道信息更新通知
  29. extern NSString *kChannelInfoUpdated;
  30. #pragma mark - 枚举值定义
  31. /**
  32. 连接状态
  33. - kConnectionStatusSecretKeyMismatch 密钥错误
  34. - kConnectionStatusTokenIncorrect Token错误
  35. - kConnectionStatusServerDown 服务器关闭
  36. - kConnectionStatusRejected: 被拒绝
  37. - kConnectionStatusLogout: 退出登录
  38. - kConnectionStatusUnconnected: 未连接
  39. - kConnectionStatusConnecting: 连接中
  40. - kConnectionStatusConnected: 已连接
  41. - kConnectionStatusReceiving: 获取离线消息中,可忽略
  42. */
  43. typedef NS_ENUM(NSInteger, ConnectionStatus) {
  44. kConnectionStatusSecretKeyMismatch = -6,
  45. kConnectionStatusTokenIncorrect = -5,
  46. kConnectionStatusServerDown = -4,
  47. kConnectionStatusRejected = -3,
  48. kConnectionStatusLogout = -2,
  49. kConnectionStatusUnconnected = -1,
  50. kConnectionStatusConnecting = 0,
  51. kConnectionStatusConnected = 1,
  52. kConnectionStatusReceiving = 2
  53. };
  54. /**
  55. 平台枚举值
  56. //Platform_Android = 2,
  57. //Platform_Windows = 3,
  58. //Platform_OSX = 4,
  59. //Platform_WEB = 5,
  60. //Platform_WX = 6,
  61. */
  62. #define Platform_iOS 1
  63. #pragma mark - 连接状态&消息监听
  64. /**
  65. 连接状态的监听
  66. */
  67. @protocol ConnectionStatusDelegate <NSObject>
  68. /**
  69. 连接状态变化的回调
  70. @param status 连接状态
  71. */
  72. - (void)onConnectionStatusChanged:(ConnectionStatus)status;
  73. @end
  74. /**
  75. 消息接收的监听
  76. */
  77. @protocol ReceiveMessageDelegate <NSObject>
  78. /**
  79. 接收消息的回调
  80. @param messages 收到的消息
  81. @param hasMore 是否还有待接受的消息,UI可以根据此参数决定刷新的时机
  82. */
  83. - (void)onReceiveMessage:(NSArray<WFCCMessage *> *)messages hasMore:(BOOL)hasMore;
  84. @optional
  85. - (void)onRecallMessage:(long long)messageUid;
  86. - (void)onDeleteMessage:(long long)messageUid;
  87. /**
  88. 消息已送达到目标用户的回调
  89. @param delivereds 送达报告
  90. */
  91. - (void)onMessageDelivered:(NSArray<WFCCDeliveryReport *> *)delivereds;
  92. /**
  93. 消息已读的监听
  94. */
  95. - (void)onMessageReaded:(NSArray<WFCCReadReport *> *)readeds;
  96. @end
  97. /**
  98. 接收消息前的拦截Filter
  99. */
  100. @protocol ReceiveMessageFilter <NSObject>
  101. /**
  102. 是否拦截收到的消息
  103. @param message 消息
  104. @return 是否拦截,如果拦截该消息,则ReceiveMessageDelegate回调不会再收到此消息
  105. */
  106. - (BOOL)onReceiveMessage:(WFCCMessage *)message;
  107. @end
  108. #pragma mark - 连接服务
  109. /**
  110. 连接服务
  111. */
  112. @interface WFCCNetworkService : NSObject
  113. /**
  114. 连接服务单例
  115. @return 连接服务单例
  116. */
  117. + (WFCCNetworkService *)sharedInstance;
  118. /**
  119. 连接状态监听
  120. */
  121. @property(nonatomic, weak) id<ConnectionStatusDelegate> connectionStatusDelegate;
  122. /**
  123. 消息接收监听
  124. */
  125. @property(nonatomic, weak) id<ReceiveMessageDelegate> receiveMessageDelegate;
  126. /**
  127. 当前是否处于登陆状态
  128. */
  129. @property(nonatomic, assign, getter=isLogined, readonly)BOOL logined;
  130. /**
  131. 当前的连接状态
  132. */
  133. @property(nonatomic, assign, readonly)ConnectionStatus currentConnectionStatus;
  134. /**
  135. 当前登陆的用户ID
  136. */
  137. @property (nonatomic, strong, readonly)NSString *userId;
  138. /**
  139. 服务器时间与本地时间的差值
  140. */
  141. @property(nonatomic, assign, readonly)long long serverDeltaTime;
  142. /**
  143. 开启Log
  144. */
  145. + (void)startLog;
  146. /**
  147. 停止Log
  148. */
  149. + (void)stopLog;
  150. /**
  151. 获取日志文件路径
  152. */
  153. + (NSArray<NSString *> *)getLogFilesPath;
  154. /**
  155. 获取客户端id
  156. @return 客户端ID
  157. */
  158. - (NSString *)getClientId;
  159. /**
  160. 连接服务器,需要注意token跟clientId是强依赖的,一定要调用getClientId获取到clientId,然后用这个clientId获取token,这样connect才能成功,如果随便使用一个clientId获取到的token将无法链接成功。另外不能多次connect,如果需要切换用户请先disconnect,然后3秒钟之后再connect(如果是用户手动登录可以不用等,因为用户操作很难3秒完成,如果程序自动切换请等3秒)
  161. @param userId 用户Id
  162. @param token 密码
  163. @return 是否是第一次连接。第一次连接需要同步用户信息,耗时较长,可以加个第一次登录的等待提示界面。
  164. */
  165. - (BOOL)connect:(NSString *)userId token:(NSString *)token;
  166. /**
  167. 断开连接
  168. @param disablePush 是否停止推送,clearSession为YES时无意义。
  169. @param clearSession 是否清除Session信息,如果清楚本地历史消息将全部清除。
  170. */
  171. - (void)disconnect:(BOOL)disablePush clearSession:(BOOL)clearSession;
  172. /**
  173. 设置服务器信息。host可以是IP,可以是域名,如果是域名的话只支持主域名或www域名,二级域名不支持!
  174. 例如:example.com或www.example.com是支持的;xx.example.com或xx.yy.example.com是不支持的。
  175. @param host 服务器地址
  176. */
  177. - (void)setServerAddress:(NSString *)host;
  178. /**
  179. 设置当前设备的device token
  180. @param token 苹果APNs Device Token
  181. */
  182. - (void)setDeviceToken:(NSString *)token;
  183. /**
  184. 设置当前设备的Voip device token
  185. @param token 苹果APNs Device Token
  186. */
  187. - (void)setVoipDeviceToken:(NSString *)token;
  188. /**
  189. 添加消息拦截Filter
  190. @param filter 消息拦截Filter
  191. */
  192. - (void)addReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  193. /**
  194. 移除消息拦截Filter
  195. @param filter 消息拦截Filter
  196. */
  197. - (void)removeReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  198. /**
  199. 应用已经login且在后台的情况下,强制进行连接,确保后台连接5秒钟,用于voip推送后台刷新等场景。
  200. 应用在前台情况下,此方法无效。
  201. */
  202. - (void)forceConnect:(NSUInteger)second;
  203. - (void)cancelForceConnect;
  204. @end
  205. #endif