FWebSocketConnection.h 2.2 KB

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