Application with websockets

Hi,
Well, this is not a problem, I am looking for a north to start.

I currently have an application written in Nuxt and Sockette, however, I have no idea how to move to Livewire.

I just need to use the Sockette to connect to the destination websocket server with the data that the backend will pass, I searched everywhere and found nothing related to this on Google, only with Laravel Echo.

I can’t use Laravel Echo for this

Sockette: https://github.com/lukeed/sockette

Hey, @vinhais

Check out laravel-websocket package from beyondcode team, It’s great start and works with livewire very well.

If you don’t know how to start with it and how to implement it with livewire please let me know.

1 Like

I’m not familiar with Sockette but it looks like it’s a js wrapper for websockets. If you’re looking to integrate that with livewire, I’d suggest you look into events: https://laravel-livewire.com/docs/2.x/events

I think the keystone here is when you receive the info from your websockets in the js portion of your application, you’re going to want to toss that to the backend using something live Livewire.emit('socket-received', {'message': message});

Good luck and have fun tinkering! I don’t think it’d be too difficult to interface the two frameworks.

1 Like

I’ll go testing with him, thanks for the help :slight_smile:

Thank you for your help :slight_smile:

Just a head’s up about laravel-websockets, you’ll still need the javascript front-end to communicate things. In the Laravel universe, Echo is the go-to and it works very well but you can roll with another framework, like Sockette.

You are very welcome @vinhais!

I agree with @shortbrownman in the part of using websockets.

If you want a real time stuff then go with laravel websockets, and it works very well with laravel echo and livewire events …

If you just want to update things behind the scene for example you can go with livewire events.

Hello every body, i try use laravel-websockets, but in livewire how use the listener?

i use this in the livewire component

protected $listeners = ['echo:prueba,PruebaEvent' => 'notifyNew'];


    public function notifyNew(){
        $this->notification = true;
    }

in the dashboard of laravel-websocket the event is push, but in the view i dont have changes
(sorry, i try spell english)

You can listen for events in the frontend.

Example
public function notifyNew()
{
$this->dispatchBrowserEvent(‘Eventname’, [‘data’ => $this->property]); // sent event to frontend with data if need it
}

then in the frontend add a event listener
window.addEventListener(‘Eventname’,(data)=>{
console.log(data.detail);
});

Above is one way to get the desire action, but updating properties via event listener reflect directly in frontend
Also always test that you are receiving the event, add dd where you are listening for event.

i use laravel-websocket in realtime app with livewire, works great