Node with Laravel Echo and Socket.io but no response

845 Views Asked by At

I am setting up Laravel API for a mobile app to call the APIs and I am currently configuring Laravel Broadcast which I am new to it. I have installed laravel-echo-server and redis for the server side while laravel-echo and socket.io-client for the client side.

As you can see, in the screenshot below, the client is subscribed to the channel.

enter image description here

Here is my code

OrderController.php

broadcast(new Ordered(Order::find($order->id)));

OrderEvent.php

public function broadcastOn()
{
     return new Channel('order');
}

channels.php

Broadcast::channel('order.{orderId}', function (User $user, int $orderId) {
    return true;
});

I tried to run node index.js in the terminal with the following codes in my index.js and there's no response from the console.log:

index.js

const express = require('express');
const Echo = require('laravel-echo');
const io = require('socket.io-client');

const echo = new Echo({
  broadcaster: 'socket.io',
  host: 'http://192.168.1.14:6001',
  client: io,
});

echo.channel('public').listen('order', (e) => {
  console.log("DATA RECEIVED");
  console.log(e);
})
0

There are 0 best solutions below