Getting real-time
The last stage in our code is to start publishing our real-time stock updates. We're going to implement the letsGetRealtime()
function. All this function really needs to do is send a presence stanza to the pubsub
server to say that we're online. We'll also need to register a listener for pubsub
push events and then add them to the charts.
Let's first write the code that sends the presence stanza:
var letsGetRealtime = function() { socket.send('xmpp.presence', { to: 'pubsub.localhost' }) }
That's it! Since presence isn't an IQ type stanza, we don't need to wait for a response, and we can now get on with handling our pushed data:
socket.on('xmpp.pubsub.push.item', function(item) { stockChart.append( new Date(item.entry.json.timestamp).getTime(), item.entry.json.value ) })
In the payload, we are also given details about where (that is, which domain) the payload came from and from, which node...