react-native/Libraries/WebSocket
Philipp von Weitershausen ed903099b4 Add blob implementation with WebSocket integration
Summary:
This is the first PR from a series of PRs grabbou and me will make to add blob support to React Native. The next PR will include blob support for XMLHttpRequest.

I'd like to get this merged with minimal changes to preserve the attribution. My next PR can contain bigger changes.

Blobs are used to transfer binary data between server and client. Currently React Native lacks a way to deal with binary data. The only thing that comes close is uploading files through a URI.

Current workarounds to transfer binary data includes encoding and decoding them to base64 and and transferring them as string, which is not ideal, since it increases the payload size and the whole payload needs to be sent via the bridge every time changes are made.

The PR adds a way to deal with blobs via a new native module. The blob is constructed on the native side and the data never needs to pass through the bridge. Currently the only way to create a blob is to receive a blob from the server via websocket.

The PR is largely a direct port of https://github.com/silklabs/silk/tree/master/react-native-blobs by philikon into RN (with changes to integrate with RN), and attributed as such.

> **Note:** This is a breaking change for all people running iOS without CocoaPods. You will have to manually add `RCTBlob.xcodeproj` to your `Libraries` and then, add it to Build Phases. Just follow the process of manual linking. We'll also need to document this process in the release notes.

Related discussion - https://github.com/facebook/react-native/issues/11103

- `Image` can't show image when `URL.createObjectURL` is used with large images on Android

The websocket integration can be tested via a simple server,

```js
const fs = require('fs');
const http = require('http');

const WebSocketServer = require('ws').Server;

const wss = new WebSocketServer({
  server: http.createServer().listen(7232),
});

wss.on('connection', (ws) => {
  ws.on('message', (d) => {
    console.log(d);
  });

  ws.send(fs.readFileSync('./some-file'));
});
```

Then on the client,

```js
var ws = new WebSocket('ws://localhost:7232');

ws.binaryType = 'blob';

ws.onerror = (error) => {
  console.error(error);
};

ws.onmessage = (e) => {
  console.log(e.data);
  ws.send(e.data);
};
```

cc brentvatne ide
Closes https://github.com/facebook/react-native/pull/11417

Reviewed By: sahrens

Differential Revision: D5188484

Pulled By: javache

fbshipit-source-id: 6afcbc4d19aa7a27b0dc9d52701ba400e7d7e98f
2017-07-26 08:23:20 -07:00
..
RCTWebSocket.xcodeproj Enable -Wimplicit-retain-self en sync warning config for all projects 2017-03-23 15:01:34 -07:00
__mocks__ Fix WebSocket compatibility with event-target-shim ^1.0.5 2016-04-27 12:26:23 -07:00
__tests__ disable automock by default in as many places as possible @bypass-lint 2017-06-08 07:45:54 -07:00
RCTReconnectingWebSocket.h Align ios api with android 2017-04-17 07:30:18 -07:00
RCTReconnectingWebSocket.m Align ios api with android 2017-04-17 07:30:18 -07:00
RCTSRWebSocket.h Backed out changeset 183744d2415b 2016-03-15 11:49:28 -07:00
RCTSRWebSocket.m Merge RCTPackagerClient into RCTPackagerConnection 2017-05-05 08:49:28 -07:00
RCTWebSocketExecutor.h Move all header imports to "<React/..>" 2016-11-23 07:58:39 -08:00
RCTWebSocketExecutor.m Make startup errors in the websocket executor invalidate the bridge 2017-06-22 08:37:13 -07:00
RCTWebSocketModule.h Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
RCTWebSocketModule.m Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
RCTWebSocketObserver.h Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
RCTWebSocketObserver.m Refactor iOS packager webSocket handling to resemble Android's packagerconnection 2017-02-23 10:03:54 -08:00
RCTWebSocketObserverProtocol.h Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
WebSocket.js Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07: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