diff --git a/app/lib/App/Core/AccessControl.php b/app/lib/App/Core/AccessControl.php index e3a0268..77ce340 100644 --- a/app/lib/App/Core/AccessControl.php +++ b/app/lib/App/Core/AccessControl.php @@ -23,7 +23,8 @@ class AccessControl // routes that need power level 1 and up [ "routes" => [ - "race/*" + "race/simulator.php", + "race/configure/*" ], "catcher" => [ "name" => "page", diff --git a/app/lib/App/SSE/Sender.php b/app/lib/App/SSE/Sender.php index 706337d..6eb59d0 100644 --- a/app/lib/App/SSE/Sender.php +++ b/app/lib/App/SSE/Sender.php @@ -9,7 +9,7 @@ namespace App\SSE; */ class Sender { - public function __construct() + public function start(): void { header("Cache-Control: no-store"); header("Content-Type: text/event-stream"); @@ -17,9 +17,13 @@ class Sender // as session data is locked to prevent concurrent writes we // make it read only to prevent the server from locking up session_write_close(); + + // we have to flush before because idk + ob_end_flush(); + flush(); } - public function send($data, $event = NULL): void + public function flush($data, $event = NULL): void { if ($event) { diff --git a/app/view/pages/race/live-results.php b/app/view/pages/race/live-results.php index d979abc..e9a3e0b 100644 --- a/app/view/pages/race/live-results.php +++ b/app/view/pages/race/live-results.php @@ -1,10 +1,26 @@

Live resultater

-

Venter på data...

+
+ + + + + +
Some shitSome shit
\ No newline at end of file diff --git a/public/race/stream.php b/public/race/stream.php index b117c73..ad78da4 100644 --- a/public/race/stream.php +++ b/public/race/stream.php @@ -1,28 +1,32 @@ database->conn); $timeMapper = new TimeMapper($app->database->conn); /** * Server-Sent Events (SSE) */ - $sse = new Sender(); +$sse->start(); -$last_change_in_timetable; +$prev_last_insert = NULL; while (!connection_aborted()) { $time = $timeMapper->getLatest(); if ($time) { - $last_change_in_timetable = $time->date->getTimestamp(); + $last_insert = $time->date->getTimestamp(); - if ($last_time == NULL || $last_change_in_timetable > $last_ajax_call) + if ($prev_last_insert == NULL || $last_insert > $prev_last_insert) { - $sse->send($timeMapper->getAll()); + $sse->flush($timeMapper->getAll()); + + $prev_last_insert = $last_insert; } }