LiveController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\LiveValidator;
  5. use App\Services\LiveService;
  6. use App\Services\RedisService;
  7. /**
  8. * 在线直播
  9. * @package App\Http\Controllers\Api\v1
  10. */
  11. class LiveController extends webApp
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. */
  17. public function index()
  18. {
  19. try {
  20. $params = request()->post();
  21. $pageSize = request()->post('pageSize', 0);
  22. $datas = LiveService::make()->getDataList($params, $pageSize,'', $this->userId);
  23. return message(1010, true, $datas);
  24. } catch (\Exception $exception){
  25. RedisService::set("caches:request:error_live_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  26. return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  27. }
  28. }
  29. /**
  30. * 播放与浏览
  31. * @return array
  32. */
  33. public function updatePlay()
  34. {
  35. $id = request()->post('id',0);
  36. if(!$result = LiveService::make()->updatePlay($this->userId, $id)){
  37. return message(LiveService::make()->getError(), false);
  38. }else{
  39. return message(LiveService::make()->getError(), true, $result);
  40. }
  41. }
  42. /**
  43. * 获取流地址
  44. * @return array
  45. */
  46. public function getUrl()
  47. {
  48. $urls = LiveService::make()->getLiveUrl($this->userId);
  49. return message(1010, true, $urls);
  50. }
  51. /**
  52. * 直播详情
  53. * @param LiveValidator $validator
  54. * @return array
  55. */
  56. public function getInfo(LiveValidator $validator)
  57. {
  58. $params = request()->all();
  59. $params = $validator->check($params, 'info');
  60. if (!is_array($params)) {
  61. return message($params, false);
  62. }
  63. if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
  64. return message(LiveService::make()->getError(),false);
  65. }else{
  66. return message(1010,true, $info);
  67. }
  68. }
  69. /**
  70. * 创建直播间(开启直播)
  71. * @return array
  72. */
  73. public function create(LiveValidator $validator)
  74. {
  75. $params = request()->all();
  76. $params = $validator->check($params, 'create');
  77. if (!is_array($params)) {
  78. return message($params, false);
  79. }
  80. if(!$result = LiveService::make()->create($this->userId, $params)){
  81. return message(LiveService::make()->getError(),false);
  82. }else{
  83. return message(LiveService::make()->getError(),true, $result);
  84. }
  85. }
  86. }