From 2a01f4517a1f0ceaebaaf0efb04bf2a4d6330fab Mon Sep 17 00:00:00 2001 From: Mike Blouin Date: Mon, 5 Mar 2018 15:46:24 -0800 Subject: [PATCH 1/2] Fix browser support Previously we errored out when running in a browser with a 400 code - because no auth info was supplied. Fix is to take the auth info we would add to headers, and add to query string instead when working with the built-in `WebSocket` implementation. Tested in NodeJS and Browser (Firefox) --- src/wire/Socket.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wire/Socket.ts b/src/wire/Socket.ts index ed5fca0..054a906 100644 --- a/src/wire/Socket.ts +++ b/src/wire/Socket.ts @@ -202,9 +202,14 @@ export class InteractiveSocket extends EventEmitter { if (this.options.authToken) { extras.headers['Authorization'] = `Bearer ${this.options.authToken}`; } - url.query = Object.assign({}, url.query, this.options.queryParams); - this.socket = new InteractiveSocket.WebSocket(Url.format(url), [], extras); + if (WebSocket === InteractiveSocket.WebSocket) { + url.query = Object.assign({}, url.query, this.options.queryParams, extras.headers); + this.socket = new InteractiveSocket.WebSocket(Url.format(url)); + } else { + url.query = Object.assign({}, url.query, this.options.queryParams); + this.socket = new InteractiveSocket.WebSocket(Url.format(url), [], extras); + } this.state = SocketState.Connecting; From 21a6918bfda42569df2381a3a9d82a183f9aae63 Mon Sep 17 00:00:00 2001 From: Mike Blouin Date: Mon, 5 Mar 2018 16:22:59 -0800 Subject: [PATCH 2/2] fix(websocket): Fix `WebSocket` undefined error --- src/wire/Socket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wire/Socket.ts b/src/wire/Socket.ts index 054a906..23c905b 100644 --- a/src/wire/Socket.ts +++ b/src/wire/Socket.ts @@ -203,7 +203,7 @@ export class InteractiveSocket extends EventEmitter { extras.headers['Authorization'] = `Bearer ${this.options.authToken}`; } - if (WebSocket === InteractiveSocket.WebSocket) { + if (typeof WebSocket === 'function' && WebSocket === InteractiveSocket.WebSocket) { url.query = Object.assign({}, url.query, this.options.queryParams, extras.headers); this.socket = new InteractiveSocket.WebSocket(Url.format(url)); } else {