Hi guys,
Awesome work with MQTT.js! I currently use it with mosquitto 1.4.10.
I have a use case where I am publishing around 10-20 times per second from the chrome client, mostly from metrics, which is not urgent. I noticed that the messages are being queued before sending it out, to the tone of around 10 publishes per second max. (I tested this using setInterval()) Thus, when I need to send something out that is urgent, the queue causes the publish to happen much later (delay is proportional as the queue gets longer).
To solve this issue, I offloaded the MQTT publishes to a web worker, which runs its own MQTT connection (using importScripts('/js/browserMqtt.min.js') and its own mqtt.connect(brokerUrl)).
However, I am getting the error Could not determine host. Specify host manually. I worked around this by specifying at the top (in the worker script): var document = { URL: null } and then setting document.URL = url on worker.postMessage().
Sorry for the long post. Few questions:
1) Is the 10 publishes per second cap a known thing? I know javascript in single-threaded, not sure if this something I configured wrong or a MQTT.js limitation.
2) Is the var document = { URL: null } the correct hack to get MQTT working on a Web Worker?
Thanks again!
Hey @hijklmno I started a little project a while ago mqttWorker to provide the same api MQTT.js API but do all MQTT work in a WebWorker. The project is not ready but you can have a look at it.
To fix the var document.URL I just create the document in the beginning of the Worker see mqttWorker.js#L25, so your fix is the same.
@sandro-k can we fix this issue here?
thanks @sandro-k. @mcollina let me know if you need some help. I can do a PR in the next few days, if needed.
@hijklmno prs are always welcome!
@mcollina Okay I'll try to make time this week. Haven't looked into MQTT.js source code in depth yet. Will link back when ready.
Is this still an issue on the latest version? If not could you please close the issue.
@OmgImAlexis feel free to close the old ones anyway :)
Most helpful comment
@OmgImAlexis feel free to close the old ones anyway :)