LiveStream.php 852 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Storage;
  6. class LiveStream extends Model
  7. {
  8. use HasFactory;
  9. public function getHlsUrl()
  10. {
  11. $path = Storage::url("live-hls/{$this->stream_id}/index.m3u8");
  12. return url($path);
  13. }
  14. public function getStreamServer()
  15. {
  16. $proto = 'rtmp://';
  17. $host = config('livestreaming.server.host');
  18. $port = ':' . config('livestreaming.server.port');
  19. $path = '/' . config('livestreaming.server.path');
  20. return $proto . $host . $port . $path;
  21. }
  22. public function getStreamKeyUrl()
  23. {
  24. $path = $this->getStreamServer() . '?';
  25. $query = http_build_query([
  26. 'name' => $this->stream_key,
  27. ]);
  28. return $path . $query;
  29. }
  30. public function getStreamRtmpUrl()
  31. {
  32. return $this->getStreamServer() . '/' . $this->stream_id;
  33. }
  34. }