Skip to content
Permalink
Browse files

Fixed code and reason arguments ignored when closing a WebSocket on i…

…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 0ac2171c549b389228c4a37ae645eb0d9813b82d
Showing with 6 additions and 10 deletions.
  1. +2 −2 Libraries/WebSocket/RCTWebSocketModule.m
  2. +4 −8 Libraries/WebSocket/WebSocket.js
@@ -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];
}

@@ -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);

0 comments on commit 0ac2171

Please sign in to comment.
You can’t perform that action at this time.