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')`.

<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

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

<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
[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
This commit is contained in:
Eric Rozell 2018-02-23 11:08:14 -08:00 committed by Facebook Github Bot
parent 446ce49e9b
commit b9be28915c
1 changed files with 1 additions and 2 deletions

View File

@ -14,7 +14,6 @@ const EventTarget = require('event-target-shim');
const NativeEventEmitter = require('NativeEventEmitter'); const NativeEventEmitter = require('NativeEventEmitter');
const BlobManager = require('BlobManager'); const BlobManager = require('BlobManager');
const NativeModules = require('NativeModules'); const NativeModules = require('NativeModules');
const Platform = require('Platform');
const WebSocketEvent = require('WebSocketEvent'); const WebSocketEvent = require('WebSocketEvent');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error /* $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 { _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 // 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 : '';