My application is a VueJS frontend and a Laravel Backend API. I want to subscribe to Binance API WebSocket but I’m unsure how to do it.
Any ideas?
I’m talking about the high level design of it. I was not able to find a way to listen to a WebSocket from the backend in Laravel.
- FYI, I’ve already setup a websocket server and I’m sending events through it so my Vue JS Front end knows when the specific event happens, now I need to actually take the event from Binance WebSocket. It’s important for me to listen to the websocket from the backend since that’s where the action should happen.
For sure this has to run somewhere at the back in some kind of isolated env or ?
2
Answers
I don’t understand exactly what you want, but…
e.g:
Method 1: Using Laravel Echo Server
Laravel Echo Server is a Node.js server that allows you to listen to WebSocket connections outside of your Laravel application. You can install Laravel Echo Server using the following command:
(https://github.com/tlaverdure/laravel-echo-server)
npm install -g laravel-echo-server
After installing Laravel Echo Server, you can start it using the following command:
laravel-echo-server start
You can also configure Laravel Echo Server using the following command:
laravel-echo-server init
You can find more information about Laravel Echo Server here:
Method 2: Using Pusher
Pusher is a service that allows you to listen to WebSocket connections outside of your Laravel application. You can find more information about Pusher here:
https://pusher.com/
Method 3: Using Redis
Redis is a service that allows you to listen to WebSocket connections outside of your Laravel application. You can find more information about Redis here:
https://redis.io/
Method 4: Using Socket.io
Socket.io is a service that allows you to listen to WebSocket connections outside of your Laravel application. You can find more information about Socket.io here:
https://socket.io/
Did you want such an example?
I also faced the similar issue recently, I found a solution which is, you can use a package called vue-pusher, by using it you can easily listen to any event, the uses are like this:
first import the package and set the params
then in the template use it like this:
I used it for live chat so i just push the new message in the messages array, here you can do your stuff.