WFCCNetworkService.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. /**
  109. 会议事件的监听
  110. */
  111. @protocol ConferenceEventDelegate <NSObject>
  112. /**
  113. 会议事件的回调
  114. @param event 事件
  115. */
  116. - (void)onConferenceEvent:(NSString *)event;
  117. @end
  118. #pragma mark - 连接服务
  119. /**
  120. 连接服务
  121. */
  122. @interface WFCCNetworkService : NSObject
  123. /**
  124. 连接服务单例
  125. @return 连接服务单例
  126. */
  127. + (WFCCNetworkService *)sharedInstance;
  128. /**
  129. 连接状态监听
  130. */
  131. @property(nonatomic, weak) id<ConnectionStatusDelegate> connectionStatusDelegate;
  132. /**
  133. 消息接收监听
  134. */
  135. @property(nonatomic, weak) id<ReceiveMessageDelegate> receiveMessageDelegate;
  136. /**
  137. 会议事件监听
  138. */
  139. @property(nonatomic, weak) id<ConferenceEventDelegate> conferenceEventDelegate;
  140. /**
  141. 当前是否处于登陆状态
  142. */
  143. @property(nonatomic, assign, getter=isLogined, readonly)BOOL logined;
  144. /**
  145. 当前的连接状态
  146. */
  147. @property(nonatomic, assign, readonly)ConnectionStatus currentConnectionStatus;
  148. /**
  149. 当前登陆的用户ID
  150. */
  151. @property (nonatomic, strong, readonly)NSString *userId;
  152. /**
  153. 服务器时间与本地时间的差值
  154. */
  155. @property(nonatomic, assign, readonly)long long serverDeltaTime;
  156. /**
  157. 开启Log
  158. */
  159. + (void)startLog;
  160. /**
  161. 停止Log
  162. */
  163. + (void)stopLog;
  164. /**
  165. 获取日志文件路径
  166. */
  167. + (NSArray<NSString *> *)getLogFilesPath;
  168. /**
  169. 获取客户端id
  170. @return 客户端ID
  171. */
  172. - (NSString *)getClientId;
  173. /**
  174. 连接服务器,需要注意token跟clientId是强依赖的,一定要调用getClientId获取到clientId,然后用这个clientId获取token,这样connect才能成功,如果随便使用一个clientId获取到的token将无法链接成功。另外不能多次connect,如果需要切换用户请先disconnect,然后3秒钟之后再connect(如果是用户手动登录可以不用等,因为用户操作很难3秒完成,如果程序自动切换请等3秒)
  175. @param userId 用户Id
  176. @param token 密码
  177. @return 是否是第一次连接。第一次连接需要同步用户信息,耗时较长,可以加个第一次登录的等待提示界面。
  178. */
  179. - (BOOL)connect:(NSString *)userId token:(NSString *)token;
  180. /**
  181. 断开连接
  182. @param disablePush 是否停止推送,clearSession为YES时无意义。
  183. @param clearSession 是否清除Session信息,如果清楚本地历史消息将全部清除。
  184. */
  185. - (void)disconnect:(BOOL)disablePush clearSession:(BOOL)clearSession;
  186. /**
  187. 设置服务器信息。host可以是IP,可以是域名,如果是域名的话只支持主域名或www域名,二级域名不支持!
  188. 例如:example.com或www.example.com是支持的;xx.example.com或xx.yy.example.com是不支持的。
  189. @param host 服务器地址
  190. */
  191. - (void)setServerAddress:(NSString *)host;
  192. /**
  193. 设置当前设备的device token
  194. @param token 苹果APNs Device Token
  195. */
  196. - (void)setDeviceToken:(NSString *)token;
  197. /**
  198. 设置当前设备的Voip device token
  199. @param token 苹果APNs Device Token
  200. */
  201. - (void)setVoipDeviceToken:(NSString *)token;
  202. /**
  203. 添加消息拦截Filter
  204. @param filter 消息拦截Filter
  205. */
  206. - (void)addReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  207. /**
  208. 移除消息拦截Filter
  209. @param filter 消息拦截Filter
  210. */
  211. - (void)removeReceiveMessageFilter:(id<ReceiveMessageFilter>)filter;
  212. /**
  213. 应用已经login且在后台的情况下,强制进行连接,确保后台连接5秒钟,用于voip推送后台刷新等场景。
  214. 应用在前台情况下,此方法无效。
  215. */
  216. - (void)forceConnect:(NSUInteger)second;
  217. - (void)cancelForceConnect;
  218. @end
  219. #endif