I am new to electron and node.js working on mqtt to update the DOM. I receive message on mqtt to my main.js onmessage function and my main.js is
const { app, BrowserWindow } = require('electron')
var mqtt = require('mqtt')
var client = mqtt.connect("mqtt://localhost")
client.on("connect", function(){
client.subscribe("testtopic")
})
client.on("message", function(topic, message, packet){
document.getElementById("someId").innerHTML = message
})
function createWindow () {
const win = new BrowserWindow({webPreferences:{nodeIntegration: true}})
win.loadFile('index.html')
win.maximize()
}
app.whenReady().then(() => {
createWindow()
})
And I would like to update the element which is available in index.html from my onmessage callback. I cannot access it shows error document is not defined. How to achieve this or can I import mqtt directly in my index.html script ? in that case why use node mqtt instead I can use paho mqtt. Please advice on this.