Z
Z
zozyla2019-09-03 22:34:18
Laravel
zozyla, 2019-09-03 22:34:18

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

2 answer(s)
I
Ivan Shumov, 2019-09-03
@inoise

Websockets should still be used if near-realtime is needed) This can be done on the lara

R
Razgelday, 2019-09-04
@Razgelday

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);
    }

// ...

2. On the frontend, use the built-in Laravel Echo package to "listen" to this event:
Echo.channel('casinoRoom.1')
    .listen('NewBet', (event) => {
        // Новая ставка сделана, можно получить ее данные из переменной event
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question