Ryan Albrecht
05/16/2024, 5:06 PM//object to store throttled function for each topic
var topic_funcs = {}
//function to create new throttled dispatch function
var createDispatchFunc = ()=>{
return _.throttle( (payload)=>{
store.dispatch('broker/handleMessage', payload)
}, 3000);
}
//function to retrieve dispatch function
var getFunc = (topic) => {
if( topic_funcs[topic] == undefined ){
topic_funcs[topic] = createDispatchFunc();
}
return topic_funcs[topic];
}
// on message recieved from mqtt broker
client.on('message', (topic,payload) => {
//get func and execute
getFunc(topic)(payload);
} )
Patrick
05/16/2024, 5:39 PMclient.on
function uses to delay the output...I can send an exampleRyan Albrecht
05/16/2024, 5:40 PMPatrick
05/16/2024, 6:00 PM