Streaming.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Events;
  3. use App\Models\Message;
  4. use Illuminate\Broadcasting\InteractsWithSockets;
  5. use Illuminate\Broadcasting\PrivateChannel;
  6. use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
  7. use Illuminate\Foundation\Events\Dispatchable;
  8. use Illuminate\Queue\SerializesModels;
  9. class Streaming implements ShouldBroadcastNow
  10. {
  11. use Dispatchable, InteractsWithSockets, SerializesModels;
  12. public readonly string $chunk;
  13. public readonly int $index;
  14. /**
  15. * Create a new event instance.
  16. */
  17. public function __construct(private readonly Message $message, string $chunk, int $index)
  18. {
  19. $this->chunk = $chunk;
  20. $this->index = $index;
  21. }
  22. /**
  23. * Get the channels the event should broadcast on.
  24. *
  25. * @return array<int, \Illuminate\Broadcasting\Channel>
  26. */
  27. public function broadcastOn(): array
  28. {
  29. return [new PrivateChannel('App.Models.Message.' . $this->message->id)];
  30. }
  31. public function broadcastAs(): string
  32. {
  33. return 'Streaming';
  34. }
  35. }