[dancer-users] Server-Sent Events

Daniel M. danny_mk at yahoo.com
Wed Jan 16 22:21:25 GMT 2013



Has anyone implemented the following php script in dancer:  http://yuilibrary.com/gallery/show/eventsource

What I wrote so far is:

any ['get', 'post'] => '/chat/:session' => sub {
   if ( param('view') ){
       template 'view', { id => param('session') }, { layout => undef };

   }else{

       content_type "text/event-stream";
       # check every so often to see if there's new data
       while( 1 ) {
           # sleep for a second - simulate waiting for data
           sleep(1);
           # check for poll-only header
           if (  my $header = header("X-YUIEventSource-PollOnly") ){
               # if it's a poll-only request, break the loop, which ends the request - the client will reconnect
               last; 
           }
           return 'data: ' . request->uri_base . request->path . '?view=1'; # Of course it will also end here, the loop does not continue
       } 

       return 'data: ' . request->uri_base . request->path . '?view=1';
   }
};

I am still getting some errors in the :
src.on("error", function(event){ console.log("Error!"); });
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130116/30a1e901/attachment.htm>


More information about the dancer-users mailing list