Open MajorMayer opened 1 year ago
Hi @MajorMayer,
It seems that there is no way to connect directly to the broker via TCP on the browser. It would be best if you used WebSocket (ws://, wss://) as your protocol. See here: https://www.hivemq.com/blog/mqtt-essentials-special-mqtt-over-websockets/
Hi @tommy44458 I also got the same error
Is it not available in nuxt3?
Hi @jskim82, (sorry that I tagged the wrong name the first time
Maybe you can try another way to connect with your broker:
React or Typescript instance
// src/app.tsx
// protocol = 'wss', 'ws', 'mqtt', ...
// host = ip or domain
// port = 8083, 1883, ...
import { useMQTT } from 'mqtt-vue-hook'
const mqttHook = useMQTT()
mqttHook.connect(`${protocol}://${host}:${port}`, {
clean: false,
keepalive: 60,
clientId: `mqtt_client_${Math.random().toString(16).substring(2, 10)}`,
connectTimeout: 4000,
})
Also, I think your broker need to open a port for web socket connections. Then, your protocol should be ‘ws’ and port should be ‘your broker’s listening port for web socket’.
当协议是 mqtt:// 的时候 会出现这个错误 Uncaught (in promise) TypeError: net.createConnection is not a function