react-native/Libraries
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
..
ART Avoid creating a new Path instance for performance 2017-07-11 11:18:56 -07:00
ActionSheetIOS Enable -Wimplicit-retain-self en sync warning config for all projects 2017-03-23 15:01:34 -07:00
AdSupport Update AdSupportIOS.js 2017-04-28 06:34:21 -07:00
Alert Export Alert's type ButtonsArray for external use 2017-03-06 12:44:47 -08:00
Animated Native Animated - Override __makeNative in AnimatedInterpolation 2017-07-18 18:02:22 -07:00
AppState Added stubs for some native modules 2017-06-01 08:31:19 -07:00
BatchedBridge Revert D5470356: [react-native] Increase information logged to MessageQueue.spy 2017-07-25 11:53:20 -07:00
Blob Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
BugReporting Patch up for future React Sync 2017-02-08 14:50:43 -08:00
CameraRoll Mark non-extern strings static 2017-07-25 04:49:46 -07:00
Components Add 'contentInsetAdjustmentBehavior' (new in iOS 11) to ScrollView 2017-07-25 10:28:42 -07:00
Core Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
EventEmitter Breaking - make RCTDeviceEventEmitter warnings fatal 2017-07-24 03:47:59 -07:00
Experimental Support for preventing swipe left or swipe right 2017-07-07 20:03:20 -07:00
Geolocation Use Apple's significant-change API (for iOS 11 UX) 2017-07-24 11:23:10 -07:00
Image Fix photo orientation from ImagePickerIOS 2017-07-24 21:51:51 -07:00
Inspector Use fixed point in inspector 2017-07-06 14:52:28 -07:00
Interaction Revert D5470356: [react-native] Increase information logged to MessageQueue.spy 2017-07-25 11:53:20 -07:00
JSInspector Add Network agent 2016-11-02 12:29:15 -07:00
LayoutAnimation Fix prop-types warning in LayoutAnimation 2017-05-12 15:06:17 -07:00
Linking Docs: fix typo in deeplinking docs 2017-07-26 07:18:44 -07:00
LinkingIOS Mark non-extern strings static 2017-07-25 04:49:46 -07:00
Lists Improve the documentation for ListView and ListViewDataSource 2017-07-21 14:31:17 -07:00
Modal Update Modal.js 2017-07-26 07:18:44 -07:00
NativeAnimation Stop native driver animations when value is set. 2017-07-20 14:20:30 -07:00
Network DEPRECATION: Make NetInfo API cross platform and expose whether connection is 2g/3g/4g 2017-07-24 15:50:53 -07:00
Performance Cleanup ifdef's in JSCExecutor 2017-07-25 05:02:03 -07:00
PermissionsAndroid Include Create React Native App in Getting Started 2017-04-26 07:16:18 -07:00
PushNotificationIOS Mark non-extern strings static 2017-07-25 04:49:46 -07:00
RCTTest Replace exported method registration with statically allocated struct 2017-07-24 07:01:53 -07:00
ReactNative Support native ViewManager inheritance on iOS 2017-07-10 16:01:12 -07:00
Renderer React sync for revisions cb32253...5495e49 2017-07-13 17:38:57 -07:00
Sample Fix missing RCTBridgeModule.h 2017-01-31 11:13:50 -08:00
Settings Enable -Wimplicit-retain-self en sync warning config for all projects 2017-03-23 15:01:34 -07:00
Share Flowify Process Color 2017-04-26 11:31:56 -07:00
Storage correctly order ASyncStorage 2017-02-21 15:18:40 -08:00
StyleSheet Fix typo 2017-07-26 07:08:51 -07:00
Text Mark non-extern strings static 2017-07-25 04:49:46 -07:00
Utilities gets Relay/Classic/Compat building 2017-07-24 21:39:00 -07:00
Vibration Enable -Wimplicit-retain-self en sync warning config for all projects 2017-03-23 15:01:34 -07:00
WebSocket Add blob implementation with WebSocket integration 2017-07-26 08:23:20 -07:00
polyfills Remove default polyfills from metro-bundler 2017-07-17 03:20:02 -07:00
react-native MaskedViewIOS -- A way to apply alpha masks to views on iOS 2017-07-11 15:05:57 -07:00
vendor gets Relay/Classic/Compat building 2017-07-24 21:39:00 -07:00
Promise.js Don't require prettyFormat in every single bundle. 2017-06-16 04:31:56 -07:00
promiseRejectionIsError.js RN: Cleanup OSS JS & Flow Declarations 2016-11-20 17:58:29 -08:00