FIRMessagingClient.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h"
  17. @class GULReachabilityChecker;
  18. @class GPBMessage;
  19. @class FIRMessagingConnection;
  20. @class FIRMessagingDataMessageManager;
  21. @class FIRMessagingRmqManager;
  22. @class FIRMessagingTokenManager;
  23. /**
  24. * Callback to handle MCS connection requests.
  25. *
  26. * @param error The error object if any while trying to connect with MCS else nil.
  27. */
  28. typedef void (^FIRMessagingConnectCompletionHandler)(NSError *error);
  29. @protocol FIRMessagingClientDelegate <NSObject>
  30. @end
  31. /**
  32. * The client handles the subscribe/unsubscribe for an unregistered senderID
  33. * and device. It also manages the FIRMessaging data connection, the exponential backoff
  34. * algorithm in case of registration failures, sign in failures and unregister
  35. * failures. It also handles the reconnect logic if the FIRMessaging connection is
  36. * broken off by some error during an active session.
  37. */
  38. @interface FIRMessagingClient : NSObject
  39. @property(nonatomic, readonly, strong) FIRMessagingConnection *connection;
  40. @property(nonatomic, readwrite, weak) FIRMessagingDataMessageManager *dataMessageManager;
  41. @property(nonatomic, readonly, strong) FIRMessagingTokenManager *tokenManager;
  42. // Designated initializer
  43. - (instancetype)initWithDelegate:(id<FIRMessagingClientDelegate>)delegate
  44. reachability:(GULReachabilityChecker *)reachability
  45. rmq2Manager:(FIRMessagingRmqManager *)rmq2Manager
  46. tokenManager:(FIRMessagingTokenManager *)tokenManager;
  47. - (void)teardown;
  48. #pragma mark - MCS Connection
  49. /**
  50. * Create a MCS connection.
  51. *
  52. * @param handler The handler to be invokend once the connection is setup. If
  53. * setting up the connection fails we invoke the handler with
  54. * an appropriate error object.
  55. */
  56. - (void)connectWithHandler:(FIRMessagingConnectCompletionHandler)handler;
  57. /**
  58. * Disconnect the current MCS connection. If there is no valid connection this
  59. * should be a NO-OP.
  60. */
  61. - (void)disconnect;
  62. #pragma mark - MCS Connection State
  63. /**
  64. * If we are connected to MCS or not. This doesn't take into account the fact if
  65. * the client has been signed in(verified) by MCS.
  66. *
  67. * @return YES if we are signed in or connecting and trying to sign-in else NO.
  68. */
  69. @property(nonatomic, readonly) BOOL isConnected;
  70. /**
  71. * If we have an active MCS connection
  72. *
  73. * @return YES if we have an active MCS connection else NO.
  74. */
  75. @property(nonatomic, readonly) BOOL isConnectionActive;
  76. /**
  77. * If we should be connected to MCS
  78. *
  79. * @return YES if we have attempted a connection and not requested to disconect.
  80. */
  81. @property(nonatomic, readonly) BOOL shouldStayConnected;
  82. /**
  83. * Schedule a retry to connect to MCS. If `immediately` is `YES` try to
  84. * schedule a retry now else retry with some delay.
  85. *
  86. * @param immediately Should retry right now.
  87. */
  88. - (void)retryConnectionImmediately:(BOOL)immediately;
  89. #pragma mark - Messages
  90. /**
  91. * Send a message over the MCS connection.
  92. *
  93. * @param message Message to be sent.
  94. */
  95. - (void)sendMessage:(GPBMessage *)message;
  96. /**
  97. * Send message if we have an active MCS connection. If not cache the message
  98. * for this session and in case we are able to re-establish the connection try
  99. * again else drop it. This should only be used for TTL=0 messages for now.
  100. *
  101. * @param message Message to be sent.
  102. */
  103. - (void)sendOnConnectOrDrop:(GPBMessage *)message;
  104. @end