|
2 | 2 |
|
3 | 3 | var MqttClient = require('../client')
|
4 | 4 | var Store = require('../store')
|
| 5 | +var url = require('url') |
| 6 | +var xtend = require('xtend') |
5 | 7 | var debug = require('debug')('mqttjs')
|
6 | 8 |
|
7 | 9 | var protocols = {}
|
@@ -58,38 +60,24 @@ function connect (brokerUrl, opts) {
|
58 | 60 | opts = opts || {}
|
59 | 61 |
|
60 | 62 | 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 | + |
61 | 70 | if (opts.protocol === null) {
|
62 | 71 | throw new Error('Missing protocol')
|
63 | 72 | }
|
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 | + |
81 | 74 | opts.protocol = opts.protocol.replace(/:$/, '')
|
82 | 75 | }
|
83 | 76 |
|
84 | 77 | // merge in the auth options if supplied
|
85 | 78 | // legacy support for url.parse objects (now deprecated in node.js)
|
86 | 79 | parseAuthOptions(opts)
|
87 | 80 |
|
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 |
| - |
93 | 81 | // legacy support for url.parse objects (now deprecated in node.js)
|
94 | 82 | if (opts.query && typeof opts.query.clientId === 'string') {
|
95 | 83 | opts.clientId = opts.query.clientId
|
|
0 commit comments