faithgen /
laravel-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace FaithGen\SDK\Events\Commenter; |
||
| 4 | |||
| 5 | use FaithGen\SDK\Models\User; |
||
| 6 | use Illuminate\Broadcasting\InteractsWithSockets; |
||
| 7 | use Illuminate\Broadcasting\PrivateChannel; |
||
| 8 | use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; |
||
| 9 | use Illuminate\Foundation\Events\Dispatchable; |
||
| 10 | use Illuminate\Queue\SerializesModels; |
||
| 11 | |||
| 12 | class UserPresent implements ShouldBroadcastNow |
||
| 13 | { |
||
| 14 | use Dispatchable, InteractsWithSockets, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | private array $data; |
||
| 19 | /** |
||
| 20 | * @var User |
||
| 21 | */ |
||
| 22 | private User $user; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Create a new event instance. |
||
| 26 | * |
||
| 27 | * @param User $user |
||
| 28 | * @param array $data |
||
| 29 | */ |
||
| 30 | public function __construct(User $user, array $data) |
||
| 31 | { |
||
| 32 | $this->data = $data; |
||
| 33 | $this->user = $user; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get the channels the event should broadcast on. |
||
| 38 | * |
||
| 39 | * @return \Illuminate\Broadcasting\Channel|array |
||
| 40 | */ |
||
| 41 | public function broadcastOn() |
||
| 42 | { |
||
| 43 | return new PrivateChannel('comments-'.$this->data['category'].'-'.$this->data['item_id']); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function broadcastWith() |
||
| 47 | { |
||
| 48 | return [ |
||
| 49 | 'user' => $this->user, |
||
| 50 | 'coming_in' => (bool) $this->data['presence'], |
||
| 51 | ]; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Broadcast event name. |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function broadcastAs() |
||
| 60 | { |
||
| 61 | return 'user.joined'; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |