I'm trying to understand exactly where/how I should implement node.js/socketstream server side code that runs independent of client rpc calls. As a simple example I'm trying to push a regular clock update to connected clients using something like this on the server side:
var pushTime = function() {
d = new Date();
ss.publish.all('newServerTime', d);
return;
};
setInterval(pushTime, 1000);
And setting up the client to subscribe to that publish event sorta like this:
ss.event.on('newServerTime', function(time) {
return $('#serverTime').val(time);
});
Problem: where do I put/execute the server side pushTime function? The docs suggest the /server/rpc tree so I put it in /server/rpc/demo.js but that yields this error:
ReferenceError: ss is not defined
Mind you, I'm not putting the code in the export.actions block; I believe that's only for client rpc calls.
I tried setting ss at the top of the file:
ss = require('socketstream');
but that's gotta be wrong - now the 'publish.all' method doesn't exist.
I tried putting the code at the bottom of app.js, right after the ss.start call. Again that says the publish.all method doesn't exist (maybe not until there's a client attached?). I'm lost. Any help appreciated; hope this was clear.