<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span></span></div><div>Has anyone implemented the following php script in dancer: <a target="_blank" href="http://yuilibrary.com/gallery/show/eventsource">http://yuilibrary.com/gallery/show/eventsource</a><br><br>What I wrote so far is:<br><br>any ['get', 'post'] => '/chat/:session' => sub {<br> if ( param('view') ){<br> template 'view', { id => param('session') }, { layout => undef };<br><br> }else{<br><br> content_type "text/event-stream";<br> # check every so often to see if there's new data<br> while( 1 ) {<br> # sleep for a second - simulate waiting for data<br>
sleep(1);<br> # check for poll-only header<br> if ( my $header = header("X-YUIEventSource-PollOnly") ){<br> # if it's a poll-only request, break the loop, which ends the request - the client will reconnect<br> last; <br> }<br> return 'data: ' . request->uri_base . request->path . '?view=1'; # Of course it will also end here, the loop does not continue<br> } <br><br> return 'data: ' . request->uri_base . request->path . '?view=1';<br> }<br>};<br><br>I am still getting
some errors in the :<br>src.on("error", function(event){ console.log("Error!"); });</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div></div></body></html>