How to update each X seconds a widget?
-
Is there some example?
I'd like to update the content of my widget each X seconds.
-
You mean client-side? You can use default javascript setInterval http://www.w3schools.com/jsref/met_win_setinterval.asp
If you need server-side update, you can use cron or smth like this -
I display data from a remote request, and I'd like to update it client-side each X seconds. But I can't perform the update using client-side JS, I need Node.js.
So I was wondering if there is a way to tell to a widget to reload the data from its node.js source.
-
I recommend sockets.
This is the way I do it. There's probably better ways, I'm a noob.
I put a listener on my client js,
socket.on('whatever', function(data) { // Update any widgets using data. });
and set a timer in my server code and do:
SocketIO.in("online_users").emit('whatever', {somevalue: getWhateverValue()});
-
Is
SocketIO
alredy inited by NodeBB or do I have to include it and initialize it?Also, what is the best way to include client-side JS in a widget?
-
@Fez-Vrasta You have to include it. e.g.
var SocketIO = require('./socket.io');
I'm not sure if there is an option for per widget client js. I put it in my main client.js in my plugin.json.