diff --git a/package.json b/package.json index 3129d73..53dc669 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "websocket-stream", - "version": "5.1.2", + "version": "5.1.3", "license": "BSD-2-Clause", "description": "Use websockets with the node streams API. Works in browser and node", "scripts": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+ssh://git@github.com/maxogden/websocket-stream.git" + "url": "git+ssh://git@github.com/rrrhys/websocket-stream.git" }, "keywords": [ "websocket", @@ -43,9 +43,9 @@ "ws": "./ws-fallback.js" }, "bugs": { - "url": "https://github.com/maxogden/websocket-stream/issues" + "url": "https://github.com/rrrhys/websocket-stream/issues" }, - "homepage": "https://github.com/maxogden/websocket-stream#readme", + "homepage": "https://github.com/rrrhys/websocket-stream#readme", "main": "index.js", - "author": "" + "author": "Original code is Max Ogden." } diff --git a/readme.md b/readme.md index e514d11..3501789 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,12 @@ # websocket-stream -[![NPM](https://nodei.co/npm/websocket-stream.png?global=true)](https://nodei.co/npm/websocket-stream/) +### Changes made to this repository + +I'm using this repo for mqtt in a react-native mobile app. + +It sends the aws custom authoriser headers that the original lib does not. + + Use HTML5 [websockets](https://developer.mozilla.org/en-US/docs/WebSockets) using the Node Streams API. diff --git a/stream.js b/stream.js index d138eea..318ba7f 100644 --- a/stream.js +++ b/stream.js @@ -22,8 +22,9 @@ function WebSocketStream(target, protocols, options) { var stream, socket var isBrowser = process.title === 'browser' + var isReactNative = process.title === 'reactnative' var isNative = !!global.WebSocket - var socketWrite = isBrowser ? socketWriteBrowser : socketWriteNode + var socketWrite = isBrowser || isReactNative ? socketWriteBrowser : socketWriteNode if (protocols && !Array.isArray(protocols) && 'object' === typeof protocols) { // accept the "options" Object as the 2nd argument @@ -60,7 +61,9 @@ function WebSocketStream(target, protocols, options) { } else { // special constructor treatment for native websockets in browsers, see // https://github.com/maxogden/websocket-stream/issues/82 - if (isNative && isBrowser) { + // additionally, if options is supplied and contains headers property, keep initialise with protocols & options + let hasAdditionalHeaders = !!(options && options.headers); + if (isNative && isBrowser && !hasAdditionalHeaders) { socket = new WS(target, protocols) } else { socket = new WS(target, protocols, options)