bare-ws 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/socket.js +17 -1
  2. package/package.json +3 -3
package/lib/socket.js CHANGED
@@ -12,7 +12,7 @@ module.exports = exports = class WebSocket extends Duplex {
12
12
  constructor (url, opts = {}) {
13
13
  if (typeof url === 'string') url = new URL(url)
14
14
 
15
- if (URL.isURL(url)) {
15
+ if (isURL(url)) {
16
16
  opts = opts ? { ...opts } : {}
17
17
 
18
18
  opts.host = url.hostname
@@ -21,6 +21,10 @@ module.exports = exports = class WebSocket extends Duplex {
21
21
  opts.secure = url.protocol === 'https:' || url.protocol === 'wss:'
22
22
  } else {
23
23
  opts = url ? { ...url } : {}
24
+
25
+ // For Node.js compatibility
26
+ opts.host = opts.hostname || opts.host
27
+ opts.port = typeof opts.port === 'string' ? parseInt(opts.port, 10) : opts.port
24
28
  }
25
29
 
26
30
  const {
@@ -270,3 +274,15 @@ function defaultPort (url) {
270
274
 
271
275
  return null
272
276
  }
277
+
278
+ // https://url.spec.whatwg.org/#api
279
+ function isURL (url) {
280
+ return (
281
+ url !== null &&
282
+ typeof url === 'object' &&
283
+ typeof url.protocol === 'string' &&
284
+ typeof url.hostname === 'string' &&
285
+ typeof url.pathname === 'string' &&
286
+ typeof url.search === 'string'
287
+ )
288
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ws",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "WebSocket library for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -28,8 +28,8 @@
28
28
  "dependencies": {
29
29
  "bare-crypto": "^1.2.0",
30
30
  "bare-events": "^2.3.1",
31
- "bare-http1": "^3.5.2",
32
- "bare-https": "^1.1.0",
31
+ "bare-http1": "^3.8.0",
32
+ "bare-https": "^1.3.0",
33
33
  "bare-stream": "^2.1.2"
34
34
  },
35
35
  "devDependencies": {