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