From b9be28915cf323eb36f1d7c77821cdf994954074 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Fri, 23 Feb 2018 11:08:14 -0800 Subject: [PATCH] Remove Platform check from WebSocket module Summary: WebSocket uses the Platform module to check how many arguments for the `close` method should be used. In react-native-windows, we have the same number of arguments for `close` as Android, so we're prevented from using this module as-is because of the platform check (see https://github.com/Microsoft/react-native-windows/blob/master/Libraries/WebSocket/WebSocket.windows.js#L136). By switching to an argument count check, this module becomes more useful cross-platform. If you'd like to keep the platform check, I'm also open to inverting the conditional, e.g., `if (Platform.OS !== 'ios')`. I'd like to minimize the amount of code I need to copy over to react-native-windows for platform-specific overrides. Run jest tests. N/A [GENERAL][MINOR][ENHANCEMENT][Libraries/WebSocket/WebSocket.js] - Better enable cross-platform support of WebSocket.js Closes https://github.com/facebook/react-native/pull/18056 Differential Revision: D7070380 Pulled By: TheSavior fbshipit-source-id: 9bfd47654d0bf6f0e07fc799853a206721467525 --- Libraries/WebSocket/WebSocket.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Libraries/WebSocket/WebSocket.js b/Libraries/WebSocket/WebSocket.js index 13e614557d78b4..daa1ed77ca050d 100644 --- a/Libraries/WebSocket/WebSocket.js +++ b/Libraries/WebSocket/WebSocket.js @@ -14,7 +14,6 @@ const EventTarget = require('event-target-shim'); const NativeEventEmitter = require('NativeEventEmitter'); const BlobManager = require('BlobManager'); const NativeModules = require('NativeModules'); -const Platform = require('Platform'); const WebSocketEvent = require('WebSocketEvent'); /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error @@ -203,7 +202,7 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) { } _close(code?: number, reason?: string): void { - if (Platform.OS === 'android') { + if (WebSocketModule.close.length === 3) { // 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 : '';