From 8b6722dfd4970f017d7ecaab159e81ed70cf702f Mon Sep 17 00:00:00 2001 From: Rhys Williams Date: Wed, 14 Nov 2018 13:55:53 +1100 Subject: [PATCH 1/4] If options is supplied and has a headers property, make sure to pass it through. --- stream.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stream.js b/stream.js index d138eea..24e9cde 100644 --- a/stream.js +++ b/stream.js @@ -60,7 +60,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) From bbc92dff9e537cca414f396a10eec7b1fb9d7b60 Mon Sep 17 00:00:00 2001 From: Rhys Williams Date: Thu, 27 Jun 2019 13:27:29 +1000 Subject: [PATCH 2/4] Update readme.md --- readme.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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. From 47362a2cd8052e266f333deaa49dd03251ef94ca Mon Sep 17 00:00:00 2001 From: Rhys Williams Date: Thu, 27 Jun 2019 13:28:29 +1000 Subject: [PATCH 3/4] Update stream.js if process.title is reactnative, use the browser socket write implementation. --- stream.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stream.js b/stream.js index 24e9cde..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 From 09ee0a7bea45762082edabae7173c4bd9bca81aa Mon Sep 17 00:00:00 2001 From: Rhys Williams Date: Thu, 27 Jun 2019 13:29:21 +1000 Subject: [PATCH 4/4] Update package.json --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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." }