FWebSocketConnection.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. - (id)initWith:(FRepoInfo *)repoInfo
  29. andQueue:(dispatch_queue_t)queue
  30. googleAppID:(NSString *)googleAppID
  31. lastSessionID:(NSString *)lastSessionID;
  32. - (void)open;
  33. - (void)close;
  34. - (void)start;
  35. - (void)send:(NSDictionary *)dictionary;
  36. // Ignore FSRWebSocketDelegate calls on watchOS.
  37. #if !TARGET_OS_WATCH
  38. - (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message;
  39. // Exclude the `webSocket` argument since it isn't used in this codebase and it
  40. // allows for better code sharing with watchOS.
  41. - (void)webSocketDidOpen;
  42. - (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error;
  43. - (void)webSocket:(FSRWebSocket *)webSocket
  44. didCloseWithCode:(NSInteger)code
  45. reason:(NSString *)reason
  46. wasClean:(BOOL)wasClean;
  47. #endif // !TARGET_OS_WATCH
  48. @end
  49. @protocol FWebSocketDelegate <NSObject>
  50. - (void)onMessage:(FWebSocketConnection *)fwebSocket
  51. withMessage:(NSDictionary *)message;
  52. - (void)onDisconnect:(FWebSocketConnection *)fwebSocket
  53. wasEverConnected:(BOOL)everConnected;
  54. @end