window.Pusher = Pusher
window.Echo = new Echo({
broadcaster: 'pusher',
withCredentials: true,
auth: {
headers: {
...commonHeader
}
},
key: 'local',
cluster: 'mt1',
wsHost: 'freephone.test',
wsPort: 6001,
forceTLS: false,
disableStats: true,
encrypted: true,
// enabledTransports: ['ws', 'wss'],
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
$apiFetch('http://freephone.test/api/v1/broadcasting/auth', {
method: 'POST',
body: {
socket_id: socketId,
channel_name: channel.name
},
headers: {
...commonHeader,
}
})
.then((response) => {
console.log('Broadcast', response)
callback(null, response.data)
})
.catch((error) => {
callback(error)
})
}
}
}
})
window.Echo.private('messages.1').listen('MessageReceived', (response) => {
console.log('Actual Listen', response)
})
console.log('Private End')
Event Dispatched
event(new MessageReceived($message, $thread, $this->getToUser($to)->user_id, $to));
Event Class
public function broadcastOn(): array {
return [
new PrivateChannel('messages.1'),
];
}
Channel.php
Broadcast::channel('messages.1', function (User $user) { \Illuminate\Support\Facades\Log::info('Broadcasting authorized');
return true;
});