Reputation: 292
I want the status to be live when the user logs in and logs out. I get the connection to the pusher and everything is registered but the javascript side doesn't work (STEP 3) and it doesn't show anything in console.log. I get status 101
These are the steps I took:
"pusher/pusher-php-server": "^7.2",
"laravel-echo": "^1.16.0",
"pusher-js": "^8.4.0-rc2",
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=098576747
PUSHER_APP_KEY=34kkh4jhj56mn7nl7h5
PUSHER_APP_SECRET=h4857jfhf83746565
PUSHER_APP_CLUSTER=eu
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
window._ = require('lodash');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.$ = require('jquery');
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true,
forceTLS: true
});
Echo.channel('notifications')
.listen('LogInLogOutEvent', (e) => {
console.log(e)
})
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
'encrypted' => true,
],
],
class LogInLogOutEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public $type;
/**
* Create a new event instance.
*/
public function __construct($message, $type)
{
//
$this->message = $message;
$this->type = $type;
}
public function broadcastOn()
{
Log::debug($this->message);
Log::debug($this->type);
return new Channel('notifications');
}
}
public function handle(Login $event): void
{
broadcast(new LogInLogOutEvent("{$event->user->name} is online", 'success'));
}
public function handle(Logout $event): void
{
broadcast(new LogInLogOutEvent("{$event->user->name} is offline", 'danger'));
}
Login::class => [
LogInListener::class,
],
Logout::class => [
LogOutListener::class,
],
Upvotes: 0
Views: 259