2015-07-28 18:07:45 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-07-28 18:07:45 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-20 15:20:03 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
2015-07-28 18:07:45 +00:00
|
|
|
|
2017-04-20 15:20:03 +00:00
|
|
|
#import <React/RCTDefines.h>
|
2015-07-28 18:07:45 +00:00
|
|
|
|
2017-04-20 15:20:03 +00:00
|
|
|
#if RCT_DEV
|
|
|
|
|
2017-10-05 02:06:22 +00:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-05-05 15:32:15 +00:00
|
|
|
@protocol RCTPackagerClientMethod;
|
2017-11-21 02:12:13 +00:00
|
|
|
@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;
|
2017-04-20 15:20:03 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-21 02:12:13 +00:00
|
|
|
* 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.
|
2017-04-20 15:20:03 +00:00
|
|
|
*/
|
2017-11-21 02:12:13 +00:00
|
|
|
- (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;
|
2017-04-20 15:20:03 +00:00
|
|
|
|
2017-11-21 02:12:13 +00:00
|
|
|
/** Removes a handler. Silently does nothing if the token is not valid. */
|
|
|
|
- (void)removeHandler:(RCTHandlerToken)token;
|
2017-10-05 02:06:22 +00:00
|
|
|
|
2017-11-21 02:12:13 +00:00
|
|
|
/** Disconnects and removes all handlers. */
|
2017-10-05 02:06:22 +00:00
|
|
|
- (void)stop;
|
2015-09-04 10:44:55 +00:00
|
|
|
|
2017-11-21 02:12:13 +00:00
|
|
|
/**
|
|
|
|
* 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");
|
|
|
|
|
2015-07-28 18:07:45 +00:00
|
|
|
@end
|
2017-04-20 15:20:03 +00:00
|
|
|
|
2017-10-05 02:06:22 +00:00
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
|
2017-04-20 15:20:03 +00:00
|
|
|
#endif
|