Make the RCTSRWebSocketDelegate protocol part of RCTWebSocketModule public
Summary: This allows consumers to subclass and extend `RCTWebSocketModule` and make use of the `RCTSRWebSocketDelegate` methods. The use case here is to do some pre-processing of WebSocket data before handing it off to JS. Consumers could that in the following way: ``` interface MyWebSocketModule : RCTWebSocketModule end implementation MyWebSocketModule // Don't use RCT_EXPORT_MODULE macro for this so we replace the existing RCTWebSocketModule. + (NSString *)moduleName { return @"RCTWebSocketModule"; } RCT_EXTERN_METHOD(connect:(NSURL *)URL socketID:(nonnull NSNumber *)socketID) RCT_EXTERN_METHOD(send:(NSString *)message socketID:(nonnull NSNumber *)socketID) RCT_EXTERN_METHOD(close:(nonnull NSNumber *)socketID) - (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message { [super webSocket:webSocket didReceiveMessage:[DoSomethingWith message]]; } end ``` ... and then returning a `MyWebSocketModule` ins Closes https://github.com/facebook/react-native/pull/5321 Reviewed By: svcscm Differential Revision: D2832374 Pulled By: nicklockwood fb-gh-sync-id: f208516b2b2f76276223ffc972871d96afe87e27
This commit is contained in:
parent
e4c53c28ae
commit
66158ab2bf
|
@ -8,7 +8,8 @@
|
|||
*/
|
||||
|
||||
#import "RCTBridgeModule.h"
|
||||
#import "RCTSRWebSocket.h"
|
||||
|
||||
@interface RCTWebSocketModule : NSObject <RCTBridgeModule>
|
||||
@interface RCTWebSocketModule : NSObject <RCTBridgeModule, RCTSRWebSocketDelegate>
|
||||
|
||||
@end
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTSRWebSocket.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
@implementation RCTSRWebSocket (React)
|
||||
|
@ -28,10 +27,6 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface RCTWebSocketModule () <RCTSRWebSocketDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTWebSocketModule
|
||||
{
|
||||
NSMutableDictionary<NSNumber *, RCTSRWebSocket *> *_sockets;
|
||||
|
|
Loading…
Reference in New Issue