Manage.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $data['times'] = 1;
  31. $id = Dever::db('live/stream')->insert($data);
  32. } else {
  33. $id = $info['id'];
  34. }
  35. $handle = new Handle();
  36. $data = $handle->init($id, $name);
  37. }
  38. # 创建新流
  39. public function createStream($id, $name, $data)
  40. {
  41. $name = Dever::param('key', $data);
  42. $handle = new Handle();
  43. $data = $handle->init($id, $name);
  44. }
  45. # 禁播流
  46. public function updateDisabled($id, $name, $data)
  47. {
  48. $disabled = Dever::param('disabled', $data);
  49. $handle = new Handle();
  50. if ($disabled == 1) {
  51. $handle->start($id);
  52. } else {
  53. $handle->stop($id);
  54. }
  55. }
  56. # 获取流信息
  57. public function liveData($id)
  58. {
  59. $info = Dever::db('live/stream')->one($id);
  60. $html = $info['name'] . '('.$info['key'].')';
  61. return $html;
  62. }
  63. # 获取直播地址
  64. public function live($id)
  65. {
  66. $info = Dever::db('live/stream')->one($id);
  67. $table['推流地址'] = $info['live'];
  68. $table['高清地址'] = $info['url_rtmp'];
  69. $table['标清地址'] = $info['url_hls'];
  70. $table['普清地址'] = $info['url_hdl'];
  71. $table['截图地址'] = $info['url_pic'];
  72. $table['直播时长'] = $info['times'] . '小时';
  73. return Dever::table($table);
  74. }
  75. # 获取直播信息
  76. public function liveInfo($id)
  77. {
  78. $info = Dever::db('live/stream')->one($id);
  79. $table = array();
  80. if ($info['info']) {
  81. if ($info['status'] == 1) {
  82. $table['直播状态'] = '未开始';
  83. } elseif ($info['status'] == 2) {
  84. $table['直播状态'] = '直播中';
  85. } elseif ($info['status'] == 3) {
  86. $table['直播状态'] = '已结束';
  87. }
  88. $data = Dever::json_decode($info['info']);
  89. if (isset($data['live']) && $data['live']) {
  90. $table['开始时间'] = date('Y-m-d H:i:s', $data['live']['startAt']);
  91. $table['主播IP'] = $data['live']['clientIP'];
  92. $table['当前码率'] = $data['live']['bps'];
  93. $table['音频帧率'] = $data['live']['fps']['audio'];
  94. $table['视频帧率'] = $data['live']['fps']['video'];
  95. $table['数据帧率'] = $data['live']['fps']['data'];
  96. }
  97. /*
  98. if (isset($data['history']) && $data['history'] && isset($data['history']['items']) && $data['history']['items']) {
  99. $history = array();
  100. foreach ($data['history']['items'] as $k => $v) {
  101. $history['第' . ($k+1) . '次直播'] = date('Y-m-d H:i:s', $v['start']) . '~' . date('Y-m-d H:i:s', $v['end']);
  102. }
  103. $table['直播历史'] = Dever::table($history);
  104. }
  105. */
  106. }
  107. return Dever::table($table);
  108. }
  109. }