Fixed code and reason arguments ignored when closing a WebSocket on iOS (#24950)
Summary: While working on https://github.com/facebook/react-native/pull/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: https://github.com/facebook/react-native/pull/24950 Differential Revision: D15411922 Pulled By: cpojer fbshipit-source-id: f8a25598bd9c727313e24fea3801d5884d0723e4
This commit is contained in:
Родитель
4ea6204111
Коммит
0ac2171c54
|
@ -112,9 +112,9 @@ RCT_EXPORT_METHOD(ping:(nonnull NSNumber *)socketID)
|
||||||
[_sockets[socketID] sendPing:NULL];
|
[_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];
|
[_sockets removeObjectForKey:socketID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,14 +201,10 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_close(code?: number, reason?: string): void {
|
_close(code?: number, reason?: string): void {
|
||||||
if (Platform.OS === 'android') {
|
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
||||||
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
|
||||||
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
|
const closeReason = typeof reason === 'string' ? reason : '';
|
||||||
const closeReason = typeof reason === 'string' ? reason : '';
|
WebSocketModule.close(statusCode, closeReason, this._socketId);
|
||||||
WebSocketModule.close(statusCode, closeReason, this._socketId);
|
|
||||||
} else {
|
|
||||||
WebSocketModule.close(this._socketId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BlobManager.isAvailable && this._binaryType === 'blob') {
|
if (BlobManager.isAvailable && this._binaryType === 'blob') {
|
||||||
BlobManager.removeWebSocketHandler(this._socketId);
|
BlobManager.removeWebSocketHandler(this._socketId);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче