Skip to content

Commit b9be289

Browse files
rozelefacebook-github-bot
authored andcommitted
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 facebook#18056 Differential Revision: D7070380 Pulled By: TheSavior fbshipit-source-id: 9bfd47654d0bf6f0e07fc799853a206721467525
1 parent 446ce49 commit b9be289

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Libraries/WebSocket/WebSocket.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const EventTarget = require('event-target-shim');
1414
const NativeEventEmitter = require('NativeEventEmitter');
1515
const BlobManager = require('BlobManager');
1616
const NativeModules = require('NativeModules');
17-
const Platform = require('Platform');
1817
const WebSocketEvent = require('WebSocketEvent');
1918

2019
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
@@ -203,7 +202,7 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
203202
}
204203

205204
_close(code?: number, reason?: string): void {
206-
if (Platform.OS === 'android') {
205+
if (WebSocketModule.close.length === 3) {
207206
// See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
208207
const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
209208
const closeReason = typeof reason === 'string' ? reason : '';

0 commit comments

Comments
 (0)