LiveController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /**
  7. * 在线直播
  8. * @package App\Http\Controllers\Api\v1
  9. */
  10. class LiveController extends webApp
  11. {
  12. /**
  13. * 获取流地址
  14. * @return array
  15. */
  16. public function getUrl()
  17. {
  18. $urls = LiveService::make()->getLiveUrl($this->userId);
  19. return message(1010, true, $urls);
  20. }
  21. /**
  22. * 直播详情
  23. * @param LiveValidator $validator
  24. * @return array
  25. */
  26. public function getInfo(LiveValidator $validator)
  27. {
  28. $params = request()->all();
  29. $params = $validator->check($params, 'info');
  30. if (!is_array($params)) {
  31. return message($params, false);
  32. }
  33. if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
  34. return message(LiveService::make()->getError(),false);
  35. }else{
  36. return message(1010,true, $info);
  37. }
  38. }
  39. /**
  40. * 创建直播间(开启直播)
  41. * @return array
  42. */
  43. public function create(LiveValidator $validator)
  44. {
  45. $params = request()->all();
  46. $params = $validator->check($params, 'create');
  47. if (!is_array($params)) {
  48. return message($params, false);
  49. }
  50. if(!$result = LiveService::make()->create($this->userId, $params)){
  51. return message(LiveService::make()->getError(),false);
  52. }else{
  53. return message(LiveService::make()->getError(),true, $result);
  54. }
  55. }
  56. }