Currently, I doing a project by using a live stream API, I faced on an issue that to update my live status, live stream provider allows me retrieval the data of a number of views and live status, but it's is not a constant value, which is the value given would change anytime. Is that any method to update my live data interval, by using js PHP or jQuery, but not setInterval or setTimeout in js.
This is my PHP code (getBroadcastStatus.php)
<?php
use models\getLiveStatus;
spl_autoload_register(function($class_name){ include $class_name.".php";});
session_start();
error_reporting(E_ALL^E_NOTICE);
$getLiveStatus = new getLiveStatus();
$counter = rand(1, 10);
while (1) {
echo $getLiveStatus->getBroadcastStatus();
$counter--;
if (!$counter) {
$counter = rand(1, 10);
}
ob_end_flush();
flush();
sleep(1);
}
This is my js code follow the suggestion here: How make a Live status
Documentation here:https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
var evtSource = new EventSource('getBroadcastStatus.php');
evtSource.addEventListener('ping',function(e){
alert(e.data);
}}) ;