FConnection.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "FTypedefs.h"
  17. #import "FWebSocketConnection.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. lastSessionID:(NSString *)lastSessionID;
  25. - (void)open;
  26. - (void)close;
  27. - (void)sendRequest:(NSDictionary *)dataMsg sensitive:(BOOL)sensitive;
  28. // FWebSocketDelegate delegate methods
  29. - (void)onMessage:(FWebSocketConnection *)fwebSocket
  30. withMessage:(NSDictionary *)message;
  31. - (void)onDisconnect:(FWebSocketConnection *)fwebSocket
  32. wasEverConnected:(BOOL)everConnected;
  33. @end
  34. typedef enum {
  35. DISCONNECT_REASON_SERVER_RESET = 0,
  36. DISCONNECT_REASON_OTHER = 1
  37. } FDisconnectReason;
  38. @protocol FConnectionDelegate <NSObject>
  39. - (void)onReady:(FConnection *)fconnection
  40. atTime:(NSNumber *)timestamp
  41. sessionID:(NSString *)sessionID;
  42. - (void)onDataMessage:(FConnection *)fconnection
  43. withMessage:(NSDictionary *)message;
  44. - (void)onDisconnect:(FConnection *)fconnection
  45. withReason:(FDisconnectReason)reason;
  46. - (void)onKill:(FConnection *)fconnection withReason:(NSString *)reason;
  47. @end