added iOS source code
[wl-app.git] / iOS / Pods / FirebaseMessaging / Firebase / Messaging / FIRMessagingConnection.h
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
17 #import <Foundation/Foundation.h>
18
19 @class FIRMessagingConnection;
20 @class FIRMessagingDataMessageManager;
21 @class FIRMessagingRmqManager;
22
23 @class GtalkDataMessageStanza;
24 @class GPBMessage;
25
26 typedef void (^FIRMessagingMessageHandler)(NSDictionary *);
27
28 typedef NS_ENUM(NSUInteger, FIRMessagingConnectionState) {
29   kFIRMessagingConnectionNotConnected = 0,
30   kFIRMessagingConnectionConnecting,
31   kFIRMessagingConnectionConnected,
32   kFIRMessagingConnectionSignedIn,
33 };
34
35 typedef NS_ENUM(NSUInteger, FIRMessagingConnectionCloseReason) {
36   kFIRMessagingConnectionCloseReasonSocketDisconnected = 0,
37   kFIRMessagingConnectionCloseReasonTimeout,
38   kFIRMessagingConnectionCloseReasonUserDisconnect,
39 };
40
41 @protocol FIRMessagingConnectionDelegate<NSObject>
42
43 - (void)connection:(FIRMessagingConnection *)fcmConnection
44     didCloseForReason:(FIRMessagingConnectionCloseReason)reason;
45 - (void)didLoginWithConnection:(FIRMessagingConnection *)fcmConnection;
46 - (void)connectionDidRecieveMessage:(GtalkDataMessageStanza *)message;
47 /**
48  * Called when a stream ACK or a selective ACK are received - this indicates the
49  * message has been received by MCS.
50  * @return The count of rmqIds deleted from the client RMQ store.
51  */
52 - (int)connectionDidReceiveAckForRmqIds:(NSArray *)rmqIds;
53
54 @end
55
56
57 /**
58  * This class maintains the actual FIRMessaging connection that we use to receive and send messages
59  * while the app is in foreground. Once we have a registrationID from the FIRMessaging backend we
60  * are able to set up this connection which is used for any further communication with FIRMessaging
61  * backend. In case the connection breaks off while the app is still being used we try to rebuild
62  * the connection with an exponential backoff.
63  *
64  * This class also notifies the delegate about the main events happening in the lifcycle of the
65  * FIRMessaging connection (read FIRMessagingConnectionDelegate). All of the `on-the-wire`
66  * interactions with FIRMessaging are channelled through here.
67  */
68 @interface FIRMessagingConnection : NSObject
69
70 @property(nonatomic, readonly, assign) FIRMessagingConnectionState state;
71 @property(nonatomic, readonly, copy) NSString *host;
72 @property(nonatomic, readonly, assign) NSUInteger port;
73 @property(nonatomic, readwrite, weak) id<FIRMessagingConnectionDelegate> delegate;
74
75 - (instancetype)initWithAuthID:(NSString *)authId
76                          token:(NSString *)token
77                           host:(NSString *)host
78                           port:(NSUInteger)port
79                        runLoop:(NSRunLoop *)runLoop
80                    rmq2Manager:(FIRMessagingRmqManager *)rmq2Manager
81                     fcmManager:(FIRMessagingDataMessageManager *)dataMessageManager;
82
83 - (void)signIn; // connect
84 - (void)signOut; // disconnect
85
86 /**
87  * Teardown the FIRMessaging connection and deallocate the resources being held up by the
88  * connection.
89  */
90 - (void)teardown;
91
92 /**
93  * Send proto to the wire. The message will be cached before we try to send so that in case of
94  * failure we can send it again later on when we have connection.
95  */
96 - (void)sendProto:(GPBMessage *)proto;
97
98 /**
99  * Send a message after the currently in progress connection succeeds, otherwise drop it.
100  *
101  * This should be used for TTL=0 messages that force a reconnect. They shouldn't be persisted
102  * in the RMQ, but they should be sent if the reconnect is successful.
103  */
104 - (void)sendOnConnectOrDrop:(GPBMessage *)message;
105
106 @end