Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/WebSocket/RCTSRWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ extern NSString *const RCTSRHTTPResponseErrorKey;
- (void)open;

- (void)close;
- (void)flush;

- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;

// Send a UTF8 String or Data.
Expand Down
7 changes: 7 additions & 0 deletions Libraries/WebSocket/RCTSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ - (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode
[_scheduledRunloops removeObject:@[aRunLoop, mode]];
}

- (void)flush
{
// By queueing an empty block, all blocks queued before
// need to finish executing as this is a serial queue
dispatch_sync(_workQueue, ^{});
}

- (void)close
{
[self closeWithCode:RCTSRStatusCodeNormal reason:nil];
Expand Down
3 changes: 3 additions & 0 deletions React/CoreModules/RCTWebSocketModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN

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

// Blocking call that waits until there are no more remaining actions on the queue
- (void)flush;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit / question on naming: does this method empty any buffers or perform any remaining actions in a queue? That's what the "flush" terminology makes me think. If the method does something like that, then the name makes sense. If it doesn't do that, then a name like closeAllSockets would be clearer to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i updated the implementation + comment to be more in line with the function name (flush)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The comments are helpful, and this makes more sense to me now


@end

@interface RCTBridge (RCTWebSocketModule)
Expand Down
8 changes: 8 additions & 0 deletions React/CoreModules/RCTWebSocketModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ - (NSArray *)supportedEvents
return @[ @"websocketMessage", @"websocketOpen", @"websocketFailed", @"websocketClosed" ];
}


- (void)flush
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function will be called from here: https://github.com/discord/discord/pull/72585

{
for (RCTSRWebSocket *socket in _sockets.allValues) {
[socket flush];
}
}

- (void)invalidate
{
[super invalidate];
Expand Down