Handle.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Live\Lib;
  3. use Dever;
  4. class Handle
  5. {
  6. public function method($config)
  7. {
  8. if ($config['type'] == 1) {
  9. $method = new Qiniu($config);
  10. }
  11. return $method;
  12. }
  13. # 启动
  14. public function start($id)
  15. {
  16. $info = Dever::db('live/stream')->one($id);
  17. $config = Dever::db('live/info')->one($info['live_id']);
  18. $method = $this->method($config);
  19. $stream = $method->start($info['key']);
  20. }
  21. # 禁播
  22. public function stop($id)
  23. {
  24. $info = Dever::db('live/stream')->one($id);
  25. $config = Dever::db('live/info')->one($info['live_id']);
  26. $method = $this->method($config);
  27. $stream = $method->stop($info['key']);
  28. }
  29. # 初始化流
  30. public function init($id, $name = '')
  31. {
  32. $info = Dever::db('live/stream')->one($id);
  33. if ($info['url_rtmp']) {
  34. return;
  35. }
  36. if ($name) {
  37. $info['key'] = $name;
  38. }
  39. $config = Dever::db('live/info')->one($info['live_id']);
  40. $method = $this->method($config);
  41. $stream = $method->create($info['key']);
  42. $rtmp = $method->getRtmp($info['key'], $info['times'] * 3600);
  43. $url = $method->getPlay($info['key']);
  44. $data['where_id'] = $id;
  45. $data['live'] = $rtmp;
  46. $data['url_rtmp'] = $url['rtmp'];
  47. $data['url_hls'] = $url['hls'];
  48. $data['url_hdl'] = $url['hdl'];
  49. $data['url_pic'] = $url['pic'];
  50. $live['info'] = $stream;
  51. $data['info'] = Dever::json_encode($live);
  52. Dever::db('live/stream')->update($data);
  53. return $data;
  54. }
  55. # 获取流信息 定时跑
  56. public function get($id)
  57. {
  58. $info = Dever::db('live/stream')->one($id);
  59. $config = Dever::db('live/info')->one($info['live_id']);
  60. $method = $this->method($config);
  61. $rtmp = $method->getRtmp($info['key'], $info['times'] * 3600);
  62. $url = $method->getPlay($info['key']);
  63. $stream = $method->getInfo($info['key']);
  64. $live = $method->getLiveStatus($info['key']);
  65. $hitory = $method->history($info['key']);
  66. $data['where_id'] = $id;
  67. $data['live'] = $rtmp;
  68. $data['url_rtmp'] = $url['rtmp'];
  69. $data['url_hls'] = $url['hls'];
  70. $data['url_hdl'] = $url['hdl'];
  71. $data['url_pic'] = $url['pic'];
  72. $live = Dever::json_decode($info['info']);
  73. $live['info'] = $stream;
  74. $live['live'] = $live;
  75. $live['hitory'] = $history;
  76. $data['info'] = Dever::json_encode($live);
  77. Dever::db('live/stream')->update($data);
  78. return $data;
  79. }
  80. }