FWebSocketConnection.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseDatabase/Sources/Utilities/FUtilities.h"
  17. #if !TARGET_OS_WATCH
  18. #import "FirebaseDatabase/Sources/third_party/SocketRocket/FSRWebSocket.h"
  19. #endif // !TARGET_OS_WATCH
  20. #import <Foundation/Foundation.h>
  21. @protocol FWebSocketDelegate;
  22. #if !TARGET_OS_WATCH
  23. @interface FWebSocketConnection : NSObject <FSRWebSocketDelegate>
  24. #else
  25. @interface FWebSocketConnection : NSObject <NSURLSessionWebSocketDelegate>
  26. #endif // else !TARGET_OS_WATCH
  27. @property(nonatomic, weak) id<FWebSocketDelegate> delegate;
  28. - (instancetype)initWith:(FRepoInfo *)repoInfo
  29. andQueue:(dispatch_queue_t)queue
  30. googleAppID:(NSString *)googleAppID
  31. lastSessionID:(NSString *)lastSessionID
  32. appCheckToken:(NSString *)appCheckToken;
  33. - (void)open;
  34. - (void)close;
  35. - (void)start;
  36. - (void)send:(NSDictionary *)dictionary;
  37. // Ignore FSRWebSocketDelegate calls on watchOS.
  38. #if !TARGET_OS_WATCH
  39. - (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message;
  40. // Exclude the `webSocket` argument since it isn't used in this codebase and it
  41. // allows for better code sharing with watchOS.
  42. - (void)webSocketDidOpen;
  43. - (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error;
  44. - (void)webSocket:(FSRWebSocket *)webSocket
  45. didCloseWithCode:(NSInteger)code
  46. reason:(NSString *)reason
  47. wasClean:(BOOL)wasClean;
  48. #endif // !TARGET_OS_WATCH
  49. @end
  50. @protocol FWebSocketDelegate <NSObject>
  51. - (void)onMessage:(FWebSocketConnection *)fwebSocket
  52. withMessage:(NSDictionary *)message;
  53. - (void)onDisconnect:(FWebSocketConnection *)fwebSocket
  54. wasEverConnected:(BOOL)everConnected;
  55. @end