Answer the question
In order to leave comments, you need to log in
How to notify other users about an event?
I'm making a roll.
The user makes a bet, the data is sent to the server and the bet is added to the game. How can I notify other users about the new rate? Do I need to deploy a socket server for this, or can I get by with Laravel and Vue. Everything happens without reloading the page.
Answer the question
In order to leave comments, you need to log in
Websockets should still be used if near-realtime is needed) This can be done on the lara
Laravel has a built-in functionality for using WebSocket event subscriptions - called "Broadcasting" ( https://laravel.com/docs/master/broadcasting)
The general meaning is this:
1. On the backend, create an event that "broadcasts" via Pusher / Socket .io
// app/Events/NewBet.php
// ...
public function broadcastOn()
{
return new PrivateChannel('casinoRoom.'.$this->room->id);
}
// ...
Echo.channel('casinoRoom.1')
.listen('NewBet', (event) => {
// Новая ставка сделана, можно получить ее данные из переменной event
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question