react-native/Libraries/WebSocket
Dan Abramov 7a3ab96d94 Fix race condition during initialization
Summary:
I discovered this while trying to pinpoint why Nuclide Inspector integration with RN is so flaky. It turns out that, for some reason, if I create a `WebSocket` instance early enough (which I need to when setting up DevTools integration), and the connection is fast enough (which it is on localhost), the `websocketOpen` message may arrive earlier than an `onopen` event handler is registered, causing the `onopen` handler to never fire.

```
mkdir ~/my-server
cd ~/my-server
npm i ws
nano index.js
```

Paste this code:

```js
const ws = require('ws');
const wss = new ws.Server({
  port: 8099
});
```

Run the server:

```js
node index.js
```

Now, inside React Native, paste right after [these lines](57010d63b6/Libraries/Core/InitializeCore.js (L193-L194)):

```js
  const ws = new window.WebSocket('ws://localhost:8099');
  ws.onopen = function() {
    alert('open!');
  };
```

Closes https://github.com/facebook/react-native/pull/12305

Differential Revision: D4536554

Pulled By: gaearon

fbshipit-source-id: 3021fa26b3bf275cba3704a7f3a30c77db69a1f8
2017-02-09 13:32:31 -08:00
..
RCTWebSocket.xcodeproj Rename RCTWebSocketManager file to reflect its new contents 2016-12-08 07:44:37 -08:00
__mocks__ Fix WebSocket compatibility with event-target-shim ^1.0.5 2016-04-27 12:26:23 -07:00
__tests__ Update Jest APIs on fbsource 2016-04-27 19:16:32 -07:00
RCTSRWebSocket.h Backed out changeset 183744d2415b 2016-03-15 11:49:28 -07:00
RCTSRWebSocket.m Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTWebSocketExecutor.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTWebSocketExecutor.m fix memory leak in Chrome debugging 2016-12-07 17:13:42 -08:00
RCTWebSocketModule.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTWebSocketModule.m Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTWebSocketObserver.h Rename and merge files for RCTWebSocketObserver protocol 2016-12-08 07:44:37 -08:00
RCTWebSocketObserver.m Rename RCTWebSocketManager file to reflect its new contents 2016-12-08 07:44:37 -08:00
WebSocket.js Fix race condition during initialization 2017-02-09 13:32:31 -08:00
WebSocketEvent.js Implement WebSocket module for Android. Fixes #2837 2015-10-07 08:36:22 -07:00
WebSocketInterceptor.js Reorganize core JS files 2016-10-11 10:14:28 -07:00