FConnection.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/Realtime/FWebSocketConnection.h"
  17. #import "FirebaseDatabase/Sources/Utilities/FTypedefs.h"
  18. #import <Foundation/Foundation.h>
  19. @protocol FConnectionDelegate;
  20. @interface FConnection : NSObject <FWebSocketDelegate>
  21. @property(nonatomic, weak) id<FConnectionDelegate> delegate;
  22. - (id)initWith:(FRepoInfo *)aRepoInfo
  23. andDispatchQueue:(dispatch_queue_t)queue
  24. googleAppID:(NSString *)googleAppID
  25. lastSessionID:(NSString *)lastSessionID;
  26. - (void)open;
  27. - (void)close;
  28. - (void)sendRequest:(NSDictionary *)dataMsg sensitive:(BOOL)sensitive;
  29. // FWebSocketDelegate delegate methods
  30. - (void)onMessage:(FWebSocketConnection *)fwebSocket
  31. withMessage:(NSDictionary *)message;
  32. - (void)onDisconnect:(FWebSocketConnection *)fwebSocket
  33. wasEverConnected:(BOOL)everConnected;
  34. @end
  35. typedef enum {
  36. DISCONNECT_REASON_SERVER_RESET = 0,
  37. DISCONNECT_REASON_OTHER = 1
  38. } FDisconnectReason;
  39. @protocol FConnectionDelegate <NSObject>
  40. - (void)onReady:(FConnection *)fconnection
  41. atTime:(NSNumber *)timestamp
  42. sessionID:(NSString *)sessionID;
  43. - (void)onDataMessage:(FConnection *)fconnection
  44. withMessage:(NSDictionary *)message;
  45. - (void)onDisconnect:(FConnection *)fconnection
  46. withReason:(FDisconnectReason)reason;
  47. - (void)onKill:(FConnection *)fconnection withReason:(NSString *)reason;
  48. @end