Search code examples
node.jslaravelwebsocketlaravel-echoecho-server

Connect node JS server to remote laravel-echo-server channel


I have two servers, server 1 hosting laravel echo and server 2 hosting NodeJS. I want server 2 to be able to listen and transmit on a laravel-echo channel which is in server 1. Anyone have an idea on how to proceed?

I tested with socket IO but I don't receive the events emitted from laravel echo server.

Here is the code I am using

const io = require('socket.io-client');
const socket = io('http://localhost:6001');

socket.on('*', (data) => {
    console.log(data);
});


socket.emit('subscribe', {
    channel: 'licence-update-7e32cd49-8714-42bf-804b-d823c5698ecc'
});

socket.on('connect', () => {
    socket.emit('subscribe', {
        // channel: 'private-channel',
    channel: 'licence-update-7e32cd49-8714-42bf-804b-d823c5698ecc'
        // auth: Cache.get('private-channel:socket-id')
    });
});

socket.on('event-name', (data) => {
    console.log(data);
});

the code executes but I do not receive a notification.

I want server 2 to be notified whenever there are actions on server 1 and vice versa.


Solution

  • Works using version socket.io.client version 2.4.0 of laravel-echo-client