Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: nl property not working in react project #1956

Open
NexonTreeHouse opened this issue Nov 25, 2024 · 1 comment
Open

[Bug]: nl property not working in react project #1956

NexonTreeHouse opened this issue Nov 25, 2024 · 1 comment
Labels

Comments

@NexonTreeHouse
Copy link

NexonTreeHouse commented Nov 25, 2024

MQTTjs Version

5.0

Broker

mosquitto

Environment

Browser

Description

Setting the nl flag to true still allows the receipt of published messages from the same client. However, other MQTT connections (using Paho Rust) to the same broker do not encounter this issue. A minimal React component recreation below demonstrates this behavior, however, I am just using this client in react, however, I don't see any reason this would be a react specific issue.

Minimal Reproduction

create a react project and use the component below.

"use client"

export default function Home() {
  const [messages, setMessages] = React.useState<string[]>([]);
  const [client, setClient] = React.useState<mqtt.MqttClient | null>(null);
  useEffect(() => {
    const client = mqtt.connect({
      host: "localhost",
      defaultProtocol: "ws",
      port: 9001,
      protocolVersion: 5,
    });

    client.on("connect", () => {
      setClient(client);
    });

    client.subscribe("testtopic/#", {
      nl: true,
      properties: {},
    });

    client.on("message", (topic, message) => {
      console.log("message", topic, message.toString());
      setMessages((messages) => [...messages, message.toString()]);
    });
  }, []);

  return (
    <div>
      <button
        onClick={() => {
          if (client) {
            client.publish("testtopic/1", "Hello World", {
              qos: 2,
            });
          }
        }}
      >
        Send Message
      </button>
      <pre>{JSON.stringify(messages, null, 2)}</pre>
    </div>
  );
}

Debug logs

no logs in browser console

@robertsLando
Copy link
Member

robertsLando commented Dec 16, 2024

If the packet is received by client it means the broker is sending this to him so could be that for some reason the nl flag is not respected by broker or mqttjs is not econding it correctly in the packet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants