Skip to content

Commit

Permalink
Fixed code and reason arguments ignored when closing a WebSocket on i…
Browse files Browse the repository at this point in the history
…OS (#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
  • Loading branch information
jeanregisser authored and facebook-github-bot committed May 20, 2019
1 parent 4ea6204 commit 0ac2171
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Libraries/WebSocket/RCTWebSocketModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ - (void)sendData:(NSData *)data forSocketID:(nonnull NSNumber *)socketID
[_sockets[socketID] sendPing:NULL];
}

RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID)
RCT_EXPORT_METHOD(close:(NSInteger)code reason:(NSString *)reason socketID:(nonnull NSNumber *)socketID)
{
[_sockets[socketID] close];
[_sockets[socketID] closeWithCode:code reason:reason];
[_sockets removeObjectForKey:socketID];
}

Expand Down
12 changes: 4 additions & 8 deletions Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,10 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
}

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

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

0 comments on commit 0ac2171

Please sign in to comment.