Commit Graph

8 Commits

Author SHA1 Message Date
Christopher Dro e674e45c2e Reverted commit D3040735
Summary:This is a follow up of 9b87e6c860.

- Allows custom headers on connection request
- Adds a default `origin` header to Android, just like iOS

**Introduces no breaking changes.**

I was working on something similar and would like to propose a few changes that make the API more consistent across both iOS and Android platforms and brings this closer to [spec](https://tools.ietf.org/html/rfc6455).

I believe aprock first implementation of adding custom `headers` was correct. It makes sense naming this argument `headers` since we have no other general options available, and the current `options` field is being used to pass in a header anyway.

My use case for custom headers was attaching a token to the `Authorization` header on the connection request. I have been testing this by passing a JWT inside the `Authorization` header and verifying it on the server before establishing a connection.
Closes https://github.com/facebook/react-native/pull/6016

Differential Revision: D3040735

fb-gh-sync-id: 183744d2415b895f9d9fd8ecf6023a546e18a546
shipit-source-id: 183744d2415b895f9d9fd8ecf6023a546e18a546
2016-03-15 07:20:26 -07:00
Christopher Dro 205b5d4732 Update options parameter to headers. Update to spec.
Summary:This is a follow up of 9b87e6c860.

- Allows custom headers on connection request
- Adds a default `origin` header to Android, just like iOS

**Introduces no breaking changes.**

I was working on something similar and would like to propose a few changes that make the API more consistent across both iOS and Android platforms and brings this closer to [spec](https://tools.ietf.org/html/rfc6455).

I believe aprock first implementation of adding custom `headers` was correct. It makes sense naming this argument `headers` since we have no other general options available, and the current `options` field is being used to pass in a header anyway.

My use case for custom headers was attaching a token to the `Authorization` header on the connection request. I have been testing this by passing a JWT inside the `Authorization` header and verifying it on the server before establishing a connection.
Closes https://github.com/facebook/react-native/pull/6016

Differential Revision: D3040735

Pulled By: nicklockwood

fb-gh-sync-id: f81bd14ccbdba36309b9d4b4850fb66fe4deae11
shipit-source-id: f81bd14ccbdba36309b9d4b4850fb66fe4deae11
2016-03-15 05:14:21 -07:00
Andy Prock 9b87e6c860 Added an optional options parameter for WebSockets
Summary:
This enables overriding origin, and other request headers. Similar to the https://github.com/websockets/ws api.
Closes https://github.com/facebook/react-native/pull/4629

Reviewed By: svcscm

Differential Revision: D2839951

Pulled By: mkonicek

fb-gh-sync-id: 3578af4343f90572b8851ff28342a05945498ef6
2016-01-20 11:01:39 -08:00
Philipp von Weitershausen 66158ab2bf Make the RCTSRWebSocketDelegate protocol part of RCTWebSocketModule public
Summary:
This allows consumers to subclass and extend `RCTWebSocketModule` and make use of the `RCTSRWebSocketDelegate` methods.

The use case here is to do some pre-processing of WebSocket data before handing it off to JS. Consumers could that in the following way:

```

interface MyWebSocketModule : RCTWebSocketModule
end

implementation MyWebSocketModule

// Don't use RCT_EXPORT_MODULE macro for this so we replace the existing RCTWebSocketModule.
+ (NSString *)moduleName { return @"RCTWebSocketModule"; }

RCT_EXTERN_METHOD(connect:(NSURL *)URL socketID:(nonnull NSNumber *)socketID)
RCT_EXTERN_METHOD(send:(NSString *)message socketID:(nonnull NSNumber *)socketID)
RCT_EXTERN_METHOD(close:(nonnull NSNumber *)socketID)

- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
{
  [super webSocket:webSocket didReceiveMessage:[DoSomethingWith message]];
}

end
```

... and then returning a `MyWebSocketModule` ins
Closes https://github.com/facebook/react-native/pull/5321

Reviewed By: svcscm

Differential Revision: D2832374

Pulled By: nicklockwood

fb-gh-sync-id: f208516b2b2f76276223ffc972871d96afe87e27
2016-01-14 16:13:33 -08:00
Johan Lindskogen afbff9bf88 Add support for binary type data (ArrayBuffer)
Summary:
Entirely based on https://github.com/facebook/react-native/pull/1829
I just updated the diff to be compatible with the current master branch.
Closes https://github.com/facebook/react-native/pull/4483

Reviewed By: svcscm

Differential Revision: D2783425

Pulled By: nicklockwood

fb-gh-sync-id: 1cc67c0741cff3b071530877d688f6b8c1061e3f
2015-12-23 10:07:37 -08:00
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
Summary: public

The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.

This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.

The rules are now as follows:

* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but  `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.

These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.

I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:

Out of the 65 modules included in UIExplorer:

* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand

Reviewed By: jspahrsummers

Differential Revision: D2677695

fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 04:49:45 -08:00
Nick Lockwood fa0b45c58b Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
2015-11-14 10:28:28 -08:00
Satyajit Sahoo f4857a6d42 Implement WebSocket module for Android. Fixes #2837
Summary: The JavaScript code for Android is same as the iOS counterpart, I just added few new lines and used arrow functions instead of binding `this`.
Closes https://github.com/facebook/react-native/pull/2839

Reviewed By: @​svcscm, @vjeux

Differential Revision: D2498703

Pulled By: @mkonicek

fb-gh-sync-id: 3fe958dd5af0efba00df07515f8e33b5d87eb05b
2015-10-07 08:36:22 -07:00