Skip to content

Commit 0ac2171

Browse files
jeanregisserfacebook-github-bot
authored andcommitted
Fixed code and reason arguments ignored when closing a WebSocket on iOS (#24950)
Summary: While working on #24893 I noticed the `WebSocket` module implementation on iOS was ignoring the code and reason arguments for the `close` method. The Android implementation already handled those arguments properly. So this PR brings iOS implementation on par with Android for the `WebSocket` module. ## Changelog [iOS] [Fixed] - Fixed `code` and `reason` arguments ignored on iOS when calling `WebSocket.close` Pull Request resolved: #24950 Differential Revision: D15411922 Pulled By: cpojer fbshipit-source-id: f8a25598bd9c727313e24fea3801d5884d0723e4
1 parent 4ea6204 commit 0ac2171

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

Libraries/WebSocket/RCTWebSocketModule.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ - (void)sendData:(NSData *)data forSocketID:(nonnull NSNumber *)socketID
112112
[_sockets[socketID] sendPing:NULL];
113113
}
114114

115-
RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID)
115+
RCT_EXPORT_METHOD(close:(NSInteger)code reason:(NSString *)reason socketID:(nonnull NSNumber *)socketID)
116116
{
117-
[_sockets[socketID] close];
117+
[_sockets[socketID] closeWithCode:code reason:reason];
118118
[_sockets removeObjectForKey:socketID];
119119
}
120120

Libraries/WebSocket/WebSocket.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,10 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
201201
}
202202

203203
_close(code?: number, reason?: string): void {
204-
if (Platform.OS === 'android') {
205-
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
206-
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
207-
const closeReason = typeof reason === 'string' ? reason : '';
208-
WebSocketModule.close(statusCode, closeReason, this._socketId);
209-
} else {
210-
WebSocketModule.close(this._socketId);
211-
}
204+
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
205+
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
206+
const closeReason = typeof reason === 'string' ? reason : '';
207+
WebSocketModule.close(statusCode, closeReason, this._socketId);
212208

213209
if (BlobManager.isAvailable && this._binaryType === 'blob') {
214210
BlobManager.removeWebSocketHandler(this._socketId);

0 commit comments

Comments
 (0)