Skip to content

Commit c6580a6

Browse files
committed
fix(ws): ignored host option and default hostname in browser
Fixes #1730
1 parent 0c72b5a commit c6580a6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/connect/tcp.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { StreamBuilder } from '../shared'
22

33
import net from 'net'
44
import _debug from 'debug'
5-
import { Duplex } from 'readable-stream'
65

76
const debug = _debug('mqttjs:tcp')
87
/*

src/lib/connect/ws.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ function buildUrl(opts: IClientOptions, client: MqttClient) {
2828

2929
function setDefaultOpts(opts: IClientOptions) {
3030
const options = opts
31-
if (!opts.hostname) {
32-
options.hostname = 'localhost'
33-
}
31+
3432
if (!opts.port) {
3533
if (opts.protocol === 'wss') {
3634
options.port = 443
3735
} else {
3836
options.port = 80
3937
}
4038
}
39+
4140
if (!opts.path) {
4241
options.path = '/'
4342
}
@@ -141,6 +140,9 @@ function createBrowserWebSocket(client: MqttClient, opts: IClientOptions) {
141140
const streamBuilder: StreamBuilder = (client, opts) => {
142141
debug('streamBuilder')
143142
const options = setDefaultOpts(opts)
143+
144+
options.hostname = options.hostname || options.host || 'localhost'
145+
144146
const url = buildUrl(options, client)
145147
const socket = createWebSocket(client, url, options)
146148
const webSocketStream = Ws.createWebSocketStream(

0 commit comments

Comments
 (0)