RCTPackagerConnection.h
2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <Foundation/Foundation.h>
#import <React/RCTDefines.h>
#if RCT_DEV
NS_ASSUME_NONNULL_BEGIN
@protocol RCTPackagerClientMethod;
@class RCTPackagerClientResponder;
typedef uint32_t RCTHandlerToken;
typedef void (^RCTNotificationHandler)(NSDictionary<NSString *, id> *);
typedef void (^RCTRequestHandler)(NSDictionary<NSString *, id> *, RCTPackagerClientResponder *);
typedef void (^RCTConnectedHandler)(void);
/** Encapsulates singleton connection to React Native packager. */
@interface RCTPackagerConnection : NSObject
+ (instancetype)sharedPackagerConnection;
/**
* Registers a handler for a notification broadcast from the packager. An
* example is "reload" - an instruction to reload from the packager.
* If multiple notification handlers are registered for the same method, they
* will all be invoked sequentially.
*/
- (RCTHandlerToken)addNotificationHandler:(RCTNotificationHandler)handler
queue:(dispatch_queue_t)queue
forMethod:(NSString *)method;
/**
* Registers a handler for a request from the packager. An example is
* pokeSamplingProfiler; it asks for profile data from the client.
* Only one handler can be registered for a given method; calling this
* displaces any previous request handler registered for that method.
*/
- (RCTHandlerToken)addRequestHandler:(RCTRequestHandler)handler
queue:(dispatch_queue_t)queue
forMethod:(NSString *)method;
/**
* Registers a handler that runs at most once, when the connection to the
* packager has been established. The handler will be dispatched immediately
* if the connection is already established.
*/
- (RCTHandlerToken)addConnectedHandler:(RCTConnectedHandler)handler
queue:(dispatch_queue_t)queue;
/** Removes a handler. Silently does nothing if the token is not valid. */
- (void)removeHandler:(RCTHandlerToken)token;
/** Disconnects and removes all handlers. */
- (void)stop;
/**
* Historically no distinction was made between notification and request
* handlers. If you use this method, it will be registered as *both* a
* notification handler *and* a request handler. You should migrate to the
* new block-based API instead.
*/
- (void)addHandler:(id<RCTPackagerClientMethod>)handler
forMethod:(NSString *)method __deprecated_msg("Use addRequestHandler or addNotificationHandler instead");
@end
NS_ASSUME_NONNULL_END
#endif