mqtt 5.15.1 → 5.15.2

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.
package/dist/mqtt.js CHANGED
@@ -11968,7 +11968,7 @@ var mqtt = (() => {
11968
11968
  // package-json:../../package.json
11969
11969
  var require_package = __commonJS({
11970
11970
  "package-json:../../package.json"(exports8, module) {
11971
- module.exports = { version: "5.15.1" };
11971
+ module.exports = { version: "5.15.2" };
11972
11972
  }
11973
11973
  });
11974
11974
 
@@ -23332,7 +23332,7 @@ var mqtt = (() => {
23332
23332
  var buildStream = (client, opts) => {
23333
23333
  opts.port = opts.port || 8883;
23334
23334
  opts.host = opts.hostname || opts.host || "localhost";
23335
- if (net_1.default.isIP(opts.host) === 0) {
23335
+ if (net_1.default.isIP(opts.host) === 0 && !opts.servername) {
23336
23336
  opts.servername = opts.host;
23337
23337
  }
23338
23338
  opts.rejectUnauthorized = opts.rejectUnauthorized !== false;
@@ -23613,6 +23613,15 @@ var mqtt = (() => {
23613
23613
  }
23614
23614
  var debug = (0, debug_1.default)("mqttjs");
23615
23615
  var protocols = null;
23616
+ function getDefaultWebSocketProtocol() {
23617
+ if (typeof location !== "undefined") {
23618
+ return location.protocol === "https:" ? "wss" : "ws";
23619
+ }
23620
+ if (typeof document !== "undefined") {
23621
+ return new URL(document.URL).protocol === "https:" ? "wss" : "ws";
23622
+ }
23623
+ return "ws";
23624
+ }
23616
23625
  function parseAuthOptions(opts) {
23617
23626
  let matches;
23618
23627
  if (opts.auth) {
@@ -23636,6 +23645,7 @@ var mqtt = (() => {
23636
23645
  if (brokerUrl && typeof brokerUrl === "string") {
23637
23646
  const parsedUrl = url_1.default.parse(brokerUrl, true);
23638
23647
  const parsedOptions = {};
23648
+ const isRelativeWebSocketUrl = !parsedUrl.protocol && !parsedUrl.hostname && parsedUrl.path?.startsWith("/") && (is_browser_1.default || opts.forceNativeWebSocket);
23639
23649
  if (parsedUrl.port != null) {
23640
23650
  parsedOptions.port = Number(parsedUrl.port);
23641
23651
  }
@@ -23645,10 +23655,10 @@ var mqtt = (() => {
23645
23655
  parsedOptions.protocol = parsedUrl.protocol;
23646
23656
  parsedOptions.path = parsedUrl.path;
23647
23657
  opts = { ...parsedOptions, ...opts };
23648
- if (!opts.protocol) {
23658
+ if (!opts.protocol && !isRelativeWebSocketUrl) {
23649
23659
  throw new Error("Missing protocol");
23650
23660
  }
23651
- opts.protocol = opts.protocol.replace(/:$/, "");
23661
+ opts.protocol = (opts.protocol || getDefaultWebSocketProtocol()).replace(/:$/, "");
23652
23662
  }
23653
23663
  opts.unixSocket = opts.unixSocket || opts.protocol?.includes("+unix");
23654
23664
  if (opts.unixSocket) {