BroadcastToStation.php 898 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Events;
  3. use Illuminate\Broadcasting\Channel;
  4. use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
  5. class BroadcastToStation implements ShouldBroadcastNow
  6. {
  7. public $json;
  8. private $id;
  9. const ALL_STATION=0;
  10. /**
  11. * Create a new event instance.
  12. *
  13. * @param int $id
  14. * @param string $json
  15. * @return void
  16. */
  17. public function __construct(int $id, string $json)
  18. {
  19. app('LogService')->log('海柔','broadcast1',$id.$json);
  20. $this->id = $id;// 0意味着通用站,所有站都需要收发的意思
  21. $this->json = $json;
  22. }
  23. /**
  24. * Get the channels the event should broadcast on.
  25. *
  26. * @return Channel|array
  27. */
  28. public function broadcastOn()
  29. {
  30. app('LogService')->log('海柔','broadcast2',$this->id.$this->json);
  31. return new Channel('station-'.$this->id);
  32. }
  33. }