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
This commit is contained in:
Andy Prock
2016-01-20 11:00:21 -08:00
committed by facebook-github-bot-4
parent 15f806957f
commit 9b87e6c860
6 changed files with 49 additions and 20 deletions

View File

@@ -26,15 +26,16 @@ var CLOSE_NORMAL = 1000;
* Browser-compatible WebSockets implementation.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
* See https://github.com/websockets/ws
*/
class WebSocket extends WebSocketBase {
_socketId: number;
_subs: any;
connectToSocketImpl(url: string): void {
connectToSocketImpl(url: string, protocols: ?Array<string>, options: ?{origin?: string}): void {
this._socketId = WebSocketId++;
RCTWebSocketModule.connect(url, this._socketId);
RCTWebSocketModule.connect(url, protocols, options, this._socketId);
this._registerEvents(this._socketId);
}