Manage.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Live\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. # 获取所有的流
  7. public function getStream_api()
  8. {
  9. $handle = new Handle();
  10. $info = Dever::db('live/active')->state();
  11. foreach ($info as $k => $v) {
  12. $live = Dever::db('live/info')->one($v['live_id']);
  13. $data = $handle->method($live)->gets();
  14. if (isset($data['keys']) && $data['keys']) {
  15. foreach ($data['keys'] as $k1 => $v1) {
  16. $this->insertStream($v1, $live['id'], $v['id']);
  17. }
  18. }
  19. }
  20. return 'yes';
  21. }
  22. private function insertStream($name, $live_id, $active_id)
  23. {
  24. $data['key'] = $name;
  25. $info = Dever::db('live/stream')->one($data);
  26. if (!$info) {
  27. $data['name'] = $name;
  28. $data['active_id'] = $active_id;
  29. $data['live_id'] = $live_id;
  30. $id = Dever::db('live/stream')->insert($data);
  31. } else {
  32. $id = $info['id'];
  33. }
  34. $handle = new Handle();
  35. $data = $handle->init($id, $name);
  36. }
  37. # 创建新流
  38. public function createStream($id, $name, $data)
  39. {
  40. $name = Dever::param('key', $data);
  41. $handle = new Handle();
  42. $data = $handle->init($id, $name);
  43. }
  44. # 禁播流
  45. public function updateDisabled($id, $name, $data)
  46. {
  47. $disabled = Dever::param('disabled', $data);
  48. $handle = new Handle();
  49. if ($disabled == 1) {
  50. $handle->start($id);
  51. } else {
  52. $handle->stop($id);
  53. }
  54. }
  55. # 获取流信息
  56. public function liveData($id)
  57. {
  58. $info = Dever::db('live/stream')->one($id);
  59. $html = $info['name'] . '('.$info['key'].')';
  60. return $html;
  61. }
  62. # 获取直播地址
  63. public function live($id)
  64. {
  65. $info = Dever::db('live/stream')->one($id);
  66. $table['推流地址'] = $info['live'];
  67. $table['高清地址'] = $info['url_rtmp'];
  68. $table['标清地址'] = $info['url_hls'];
  69. $table['普清地址'] = $info['url_hdl'];
  70. $table['截图地址'] = $info['url_pic'];
  71. return Dever::table($table);
  72. }
  73. # 获取直播信息
  74. public function liveInfo($id)
  75. {
  76. $info = Dever::db('live/stream')->one($id);
  77. $table = array();
  78. if ($info['info']) {
  79. if ($info['status'] == 1) {
  80. $table['直播状态'] = '未开始';
  81. } elseif ($info['status'] == 2) {
  82. $table['直播状态'] = '直播中';
  83. } elseif ($info['status'] == 3) {
  84. $table['直播状态'] = '已结束';
  85. }
  86. $data = Dever::json_decode($info['info']);
  87. if (isset($data['live']) && $data['live']) {
  88. $table['开始时间'] = date('Y-m-d H:i:s', $data['live']['startAt']);
  89. $table['主播IP'] = $data['live']['clientIP'];
  90. $table['当前码率'] = $data['live']['bps'];
  91. $table['音频帧率'] = $data['live']['fps']['audio'];
  92. $table['视频帧率'] = $data['live']['fps']['video'];
  93. $table['数据帧率'] = $data['live']['fps']['data'];
  94. }
  95. if (isset($data['history']) && $data['history']) {
  96. $history = array();
  97. foreach ($data['history'] as $k => $v) {
  98. $history['第' . ($k+1) . '次直播'] = date('Y-m-d H:i:s', $v['start']) . '~' . date('Y-m-d H:i:s', $v['end']);
  99. }
  100. $table['直播历史'] = Dever::table($history);
  101. }
  102. }
  103. return Dever::table($table);
  104. }
  105. }