Skip to content

Commit a70bae6

Browse files
nealmanaktolaFlewp
authored andcommitted
expose flush on RCTWebSocketModule to close all open websockets synchronously (#14)
* expose `flush` on RCTWebSocketModule to close all open websockets synchronously add log statement back * simplify code * simplify even more * change comment
1 parent c8bca92 commit a70bae6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/react-native/React/CoreModules/RCTWebSocketModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
2525

2626
- (void)sendData:(NSData *)data forSocketID:(nonnull NSNumber *)socketID;
2727

28+
// Blocking call that waits until there are no more remaining actions on the queue
29+
- (void)flush;
30+
2831
@end
2932

3033
@interface RCTBridge (RCTWebSocketModule)

packages/react-native/React/CoreModules/RCTWebSocketModule.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ - (NSArray *)supportedEvents
5151
return @[ @"websocketMessage", @"websocketOpen", @"websocketFailed", @"websocketClosed" ];
5252
}
5353

54+
55+
- (void)flush
56+
{
57+
for (RCTSRWebSocket *socket in _sockets.allValues) {
58+
[socket flush];
59+
}
60+
}
61+
5462
- (void)invalidate
5563
{
5664
[super invalidate];

0 commit comments

Comments
 (0)