-
composer.json
Open in GitHub{ // "require": { "php": "^7.3|^8.0", // "beyondcode/laravel-websockets": "^1.12", // "pusher/pusher-php-server": "~3.0" }, // }
-
resources/js/bootstrap.js
Open in GitHubimport 'alpinejs'; import Echo from 'laravel-echo' window.Pusher = require('pusher-js'); window.Echo = new Echo({ broadcaster: 'pusher', key: process.env.MIX_PUSHER_APP_KEY, wsHost: window.location.hostname, wsPort: 6001, wssPort: 6001, disableStats: true, });
-
routes/channels.php
Open in GitHubuse Illuminate\Support\Facades\Broadcast; // Broadcast::channel('live.count.{channel}', function ($user, $channel) { return (int) $user->id === (int) \App\Models\Channel\Channel::where('slug', $channel)->first()->owner_id; }); //
-
app/Events/UserNotifications.php
Open in GitHubuse Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class UserNotifications implements ShouldBroadcastNow { use Dispatchable, InteractsWithSockets, SerializesModels; public $user; public function __construct($user) { $this->user = $user; } public function broadcastOn() { return new PrivateChannel('user.notifications.'. $this->user->id); } }
-
app/Http/Livewire/Frontend/Channel/Partial/ChannelAnalytics.php
Open in GitHubuse App\Models\Channel\Channel; use Livewire\Component; class ChannelAnalytics extends Component { public $channel_id; public $count; public $channel; public function mount() { $this->getData(); } public function getData() { $this->channel = Channel::find($this->channel_id); $this->count = $this->channel->subscribers()->count(); } public function getListeners() { return [ "echo-private:live.count.{$this->channel->slug},LiveCount" => 'getData' ]; } public function render() { return view('livewire.frontend.channel.partial.channel-analytics'); } }
-
resources/views/livewire/frontend/channel/partial/channel-analytics.blade.php
Open in GitHub<div class="mt-6"> <div> <p><i class="fas fa-spinner fa-pulse"></i> {{ __('Updating Live') }}</p> </div> <div class="h-96 w-auto flex flex-col justify-center items-center"> <h1 class="font-bold text-7xl">{{ ReadableNumber($count) }}</h1> <p class="font-medium text-2xl">{{ \Illuminate\Support\Str::plural('subscriber', $count) }}</p> </div> </div>