Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down Expand Up @@ -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."
}
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
7 changes: 5 additions & 2 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down