Closed dator-zz closed 12 years ago
This is not something the library should handle. It simply implements the EventSource protocol. What kind of messages you send are application-specific. It's really trivial to do:
<?php
$data = array('userIds' => array(21, 43, 127));
$stream
->event()
->setData(json_encode($data));
->end()
->flush();
var stream = new EventSource('stream.php');
stream.addEventListener('message', function (event) {
var data = JSON.parse(event.data);
console.log('User IDs: '+data.userIds.join(', '));
});
I will add some docs for this to the README though.
hum, ok it's too late for me !
Thanks a lot ;)
I've added this to the docs.
What about adding the support to send json data ?
AFAIK, we can only send text data, it can be very useful to be able to send json data to the client ?
http://www.html5rocks.com/en/tutorials/eventsource/basics/#toc-json-data
What do you think ?