dthy81285 2016-07-22 01:48
浏览 28

如何成为现场状态

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);
    }}) ;   
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制