I am using Pusher API for sending notifications in Laravel 5.4 with JQuery. I found out that whenever I send notification from Firefox or Safari...it reaches chrome browser successfully but not vice versa. Another problem is that when I send message, it is being received by me!!! Although I used toOthers()
method
My Code is below. Please let me know if you need more info.
Controller Code
broadcast(new SendMessageEvent("hi", \Auth::user()))->toOthers();
Blade
$(function() {
Pusher.logToConsole = true;
var pusher = new Pusher('Pusher API key', {
authEndpoint: 'broadcasting/auth',
auth: {headers: {'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')}}
});
var channel = pusher.subscribe('private-user-channel.{!! \Auth::user()->UserID !!}');
channel.bind('App\\Events\\SendMessageEvent', function(data) {
console.log(data);
});
});
Event
class SendMessageEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $msg;
public $user;
public $userid;
public function __construct($msg, $user) {
$this->msg = $msg;
$this->user = $user;
$this->userid = $this->user->UserID;
}
public function broadcastOn()
{
return new PrivateChannel('user-channel.1');
}
}
Channel
Broadcast::channel('user-channel.{userid}', function ($user, $userid) {
return (int) $user->UserID === (int) $userid;
});