@rodrigo.pedra can you look at my code it's working but i don't know if it is okay in the production too
app.blade.php (main layout file)
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<!-- 2. Include Laravel Echo -->
<script src="https://cdn.jsdelivr.net/npm/laravel-echo/dist/echo.iife.js"></script>
<script>
// Initialize Echo with Reverb
window.Echo = new Echo({
broadcaster: 'reverb',
key: "{{ env('REVERB_APP_KEY') }}",
wsHost: window.location.hostname,
wsPort: {{ env('REVERB_PORT', 8080) }},
forceTLS: {{ env('REVERB_SCHEME', 'http') === 'https' ? 'true' : 'false' }},
authEndpoint: '/broadcasting/auth',
auth: {
headers: {
'X-CSRF-TOKEN': "{{ csrf_token() }}"
}
}
});
// Connection status logging
window.Echo.connector.pusher.connection.bind('connected', () => {
console.log('Connected to Reverb!');
});
window.Echo.connector.pusher.connection.bind('error', (error) => {
console.error('Reverb connection error:', error);
});
</script>
it will be okay right if i use this pusher and echo CDN in the production as well ??
events/MessageSent.php
<?php
namespace App\Events;
class MessageSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public Message $message;
public function __construct(Message $message)
{
$this->message = $message->load('sender', 'conversation');
}
public function broadcastOn()
{
// Use PresenceChannel for user presence features if needed
return new PrivateChannel('chat.'.$this->message->conversation_id);
}
public function broadcastAs()
{
return 'message.sent'; // Custom event name
}
}
channels.php
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
$conversation = Conversation::find($conversationId);
if (!$conversation) {
return false;
}
return $conversation->participant_one_id == $user->id && $conversation->participant_one_type == get_class($user) ||
$conversation->participant_two_id == $user->id && $conversation->participant_two_type == get_class($user);
});