Skip to content

Commit 0eb3d1b

Browse files
author
Yoseph Maguire
committed
fix(websockets): rollback WHATWG changes
1 parent ba90144 commit 0eb3d1b

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

examples/wss/client_with_proxy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
var mqtt = require('mqtt')
4+
var url = require('url')
45
var HttpsProxyAgent = require('https-proxy-agent')
56
/*
67
host: host of the endpoint you want to connect e.g. my.mqqt.host.com
@@ -12,8 +13,8 @@ proxy: your proxy e.g. proxy.foo.bar.com
1213
port: http proxy port e.g. 8080
1314
*/
1415
var proxy = process.env.http_proxy || 'http://<proxy>:<port>'
15-
var parsed = new URL(endpoint)
16-
var proxyOpts = new URL(proxy)
16+
var parsed = url.parse(endpoint)
17+
var proxyOpts = url.parse(proxy)
1718
// true for wss
1819
proxyOpts.secureEndpoint = parsed.protocol ? parsed.protocol === 'wss:' : true
1920
var agent = new HttpsProxyAgent(proxyOpts)

lib/connect/index.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var MqttClient = require('../client')
44
var Store = require('../store')
5+
var url = require('url')
6+
var xtend = require('xtend')
57
var debug = require('debug')('mqttjs')
68

79
var protocols = {}
@@ -58,38 +60,24 @@ function connect (brokerUrl, opts) {
5860
opts = opts || {}
5961

6062
if (brokerUrl) {
63+
var parsed = url.parse(brokerUrl, true)
64+
if (parsed.port != null) {
65+
parsed.port = Number(parsed.port)
66+
}
67+
68+
opts = xtend(parsed, opts)
69+
6170
if (opts.protocol === null) {
6271
throw new Error('Missing protocol')
6372
}
64-
var parsed = new URL(brokerUrl)
65-
66-
// the URL object is a bit special, so copy individual
67-
// items to the opts object
68-
opts.hash = parsed.hash
69-
opts.host = parsed.host
70-
opts.hostname = parsed.hostname
71-
opts.href = parsed.href
72-
opts.origin = parsed.origin
73-
opts.pathname = parsed.pathname
74-
opts.port = Number(parsed.port) || null
75-
opts.protocol = parsed.protocol
76-
opts.username = opts.username || parsed.username || null
77-
opts.password = opts.password || parsed.password || null
78-
opts.search = parsed.search
79-
opts.searchParams = parsed.searchParams
80-
opts.path = parsed.pathname + parsed.search
73+
8174
opts.protocol = opts.protocol.replace(/:$/, '')
8275
}
8376

8477
// merge in the auth options if supplied
8578
// legacy support for url.parse objects (now deprecated in node.js)
8679
parseAuthOptions(opts)
8780

88-
// support clientId passed in the query string of the url
89-
if (opts.searchParams && typeof opts.searchParams.get('clientId') === 'string') {
90-
opts.clientId = opts.searchParams.get('clientId')
91-
}
92-
9381
// legacy support for url.parse objects (now deprecated in node.js)
9482
if (opts.query && typeof opts.query.clientId === 'string') {
9583
opts.clientId = opts.query.clientId

test/browser/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var mqtt = require('../../lib/connect')
44
var xtend = require('xtend')
5-
var parsed = new URL(document.URL)
5+
var _URL = require('url')
6+
var parsed = _URL.parse(document.URL)
67
var isHttps = parsed.protocol === 'https:'
78
var port = parsed.port || (isHttps ? 443 : 80)
89
var host = parsed.hostname

0 commit comments

Comments
 (0)